diff options
author | 2021-12-31 15:30:57 -0800 | |
---|---|---|
committer | 2021-12-31 15:30:57 -0800 | |
commit | eb142a6be556abd209a37efb5c9e9864de6e963b (patch) | |
tree | 35c216c9f261ad3438d151e9a900464d3789f39b /src | |
parent | 9fde2b28e14ed018aa781a64ca97ccf4aa7e314b (diff) | |
download | bun-eb142a6be556abd209a37efb5c9e9864de6e963b.tar.gz bun-eb142a6be556abd209a37efb5c9e9864de6e963b.tar.zst bun-eb142a6be556abd209a37efb5c9e9864de6e963b.zip |
little testbun-v0.0.64
Diffstat (limited to 'src')
-rw-r--r-- | src/bun_queue.zig | 15 | ||||
-rw-r--r-- | src/http.zig | 2 | ||||
-rw-r--r-- | src/string_immutable.zig | 8 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/bun_queue.zig b/src/bun_queue.zig index fc3edef52..3f20ca430 100644 --- a/src/bun_queue.zig +++ b/src/bun_queue.zig @@ -33,7 +33,7 @@ pub fn NewBlockQueue(comptime Value: type, comptime block_size: comptime_int, co allocator: std.mem.Allocator, empty_queue: std.atomic.Atomic(u32) = std.atomic.Atomic(u32).init(1), rand: std.rand.DefaultPrng = std.rand.DefaultPrng.init(100), - + random: std.rand.Random = undefined, pub fn new(this: *BlockQueue, allocator: std.mem.Allocator) void { this.* = BlockQueue{ .allocator = allocator, @@ -42,15 +42,14 @@ pub fn NewBlockQueue(comptime Value: type, comptime block_size: comptime_int, co }; this.blocks[0] = &this.first; this.allocator = allocator; + this.random = this.rand.random(); } pub fn get(this: *BlockQueue) ?Value { if (this.len.fetchMax(-1, .SeqCst) <= 0) return null; - const rand = this.rand.random(); - while (@atomicRmw(bool, &this.write_lock, .Xchg, true, .SeqCst)) { - const end = rand.uintAtMost(u8, 64); + const end = this.random.uintAtMost(u8, 64); var i: u8 = 0; while (i < end) : (i += 1) {} std.atomic.spinLoopHint(); @@ -468,7 +467,7 @@ test "BunQueue: Dedupes" { "uniq30", } ++ [_]string{ "dup20", "dup21", "dup27", "dup2", "dup12", "dup15", "dup4", "dup12", "dup10", "dup7", "dup26", "dup22", "dup1", "dup23", "dup11", "dup8", "dup11", "dup29", "dup28", "dup25", "dup20", "dup2", "dup6", "dup16", "dup22", "dup13", "dup30", "dup9", "dup3", "dup17", "dup14", "dup18", "dup8", "dup3", "dup28", "dup30", "dup24", "dup18", "dup24", "dup5", "dup23", "dup10", "dup13", "dup26", "dup27", "dup29", "dup25", "dup4", "dup19", "dup15", "dup6", "dup17", "dup1", "dup16", "dup19", "dup7", "dup9", "dup21", "dup14", "dup5" }; var prng = std.rand.DefaultPrng.init(100); - prng.random.shuffle(string, &greet); + prng.random().shuffle(string, &greet); var deduped = std.BufSet.init(default_allocator); var consumed = std.BufSet.init(default_allocator); @@ -616,8 +615,8 @@ test "BunQueue: SCMP Threaded" { "uniq119", "uniq120", } ++ [_]string{ "dup1", "dup1", "dup10", "dup10", "dup11", "dup11", "dup12", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup25", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup23", "dup23", "dup12", "dup13", "dup13", "dup14", "dup14", "dup15", "dup15", "dup16", "dup16", "dup17", "dup17", "dup18", "dup18", "dup19", "dup19", "dup2", "dup2", "dup20", "dup20", "dup21", "dup21", "dup22", "dup22", "dup23", "dup23", "dup24", "dup24", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup25", "dup26", "dup26", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9", "dup27", "dup27", "dup28", "dup28", "dup29", "dup29", "dup3", "dup3", "dup30", "dup30", "dup4", "dup4", "dup5", "dup5", "dup6", "dup6", "dup7", "dup7", "dup8", "dup8", "dup9", "dup9" }; - var prng = std.rand.DefaultPrng.init(100); - prng.random.shuffle(string, &greet); + var prng = std.rand.DefaultPrng.init(100).random(); + prng.shuffle(string, &greet); var in = try default_allocator.create(std.BufSet); in.* = std.BufSet.init(default_allocator); for (greet) |i| { @@ -690,7 +689,7 @@ test "BunQueue: MPMC Threaded" { var copy = val; @setEvalBranchQuota(99999); var rand = std.rand.DefaultPrng.init(100); - rand.random.shuffle(string, ©); + rand.random().shuffle(string, ©); return copy; } const three_all = shuffle(@TypeOf(@import("./test/project.zig").three), @import("./test/project.zig").three); diff --git a/src/http.zig b/src/http.zig index ed1dd9cae..a2870a345 100644 --- a/src/http.zig +++ b/src/http.zig @@ -1723,7 +1723,7 @@ pub const RequestContext = struct { var it = std.mem.split(u8, connection_header.value, ","); while (it.next()) |part| { const conn = std.mem.trim(u8, part, " "); - if (strings.eqlCaseInsensitiveASCII(conn, "upgrade")) { + if (strings.eqlCaseInsensitiveASCII(conn, "upgrade", true)) { return; } } diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 2796f59b8..368e245f2 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1004,3 +1004,11 @@ pub const unicode_replacement_str = brk: { _ = std.unicode.utf8Encode(unicode_replacement, &out) catch unreachable; break :brk out; }; + +test "eqlCaseInsensitiveASCII" { + try std.testing.expect(eqlCaseInsensitiveASCII("abc", "ABC", true)); + try std.testing.expect(eqlCaseInsensitiveASCII("abc", "abc", true)); + try std.testing.expect(eqlCaseInsensitiveASCII("aBcD", "aBcD", true)); + try std.testing.expect(!eqlCaseInsensitiveASCII("aBcD", "NOOO", true)); + try std.testing.expect(!eqlCaseInsensitiveASCII("aBcD", "LENGTH CHECK", true)); +} |