diff options
author | 2021-12-30 21:12:32 -0800 | |
---|---|---|
committer | 2021-12-30 21:12:32 -0800 | |
commit | e75c711c68896f5952793601f156c921c814caab (patch) | |
tree | f3b30e2281c7231d480bb84503d17b2370866ff9 /src/string_immutable.zig | |
parent | 8d031f13c0e04629d431176e211a31224b7618c0 (diff) | |
download | bun-e75c711c68896f5952793601f156c921c814caab.tar.gz bun-e75c711c68896f5952793601f156c921c814caab.tar.zst bun-e75c711c68896f5952793601f156c921c814caab.zip |
Upgrade to latest Zig, remove dependency on patched version of Zig (#96)
* Prepare to upgrade zig
* zig fmt
* AllocGate
* Update data_url.zig
* wip
* few files
* just headers now?
* I think everything works?
* Update mimalloc
* Update hash_map.zig
* Perf improvements to compensate for Allocgate
* Bump
* :camera:
* Update bun.lockb
* Less branching
* [js parser] Slightly reduce memory usage
* Update js_parser.zig
* WIP remove unused
* [JS parser] WIP support for `with` keyword
* Remove more dead code
* Fix all the build errors!
* cleanup
* Move `network_thread` up
* Bump peechy
* Update README.md
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 2f14d7e28..8b6215606 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -3,7 +3,9 @@ const expect = std.testing.expect; const JavascriptString = @import("ast/base.zig").JavascriptString; -usingnamespace @import("string_types.zig"); +const string = @import("string_types.zig").string; +const stringZ = @import("string_types.zig").stringZ; +const CodePoint = @import("string_types.zig").CodePoint; pub inline fn containsChar(self: string, char: u8) bool { return indexOfChar(self, char) != null; @@ -61,7 +63,7 @@ pub inline fn indexOf(self: string, str: string) ?usize { return std.mem.indexOf(u8, self, str); } -pub fn cat(allocator: *std.mem.Allocator, first: string, second: string) !string { +pub fn cat(allocator: std.mem.Allocator, first: string, second: string) !string { var out = try allocator.alloc(u8, first.len + second.len); std.mem.copy(u8, out, first); std.mem.copy(u8, out[first.len..], second); @@ -84,7 +86,7 @@ pub const StringOrTinyString = struct { }; } - pub fn deinit(this: *StringOrTinyString, allocator: *std.mem.Allocator) void { + pub fn deinit(this: *StringOrTinyString, _: std.mem.Allocator) void { if (this.is_tiny_string == 1) return; // var slice_ = this.slice(); @@ -289,9 +291,7 @@ pub fn endsWithAny(self: string, str: string) bool { return false; } -pub fn lastNonwhitespace(self: string, str: string) bool {} - -pub fn quotedAlloc(allocator: *std.mem.Allocator, self: string) !string { +pub fn quotedAlloc(allocator: std.mem.Allocator, self: string) !string { var count: usize = 0; for (self) |char| { count += @boolToInt(char == '"'); @@ -450,7 +450,6 @@ pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool { } if ((len & 2) != 0) { - const slice = b.ptr; if (@bitCast(u16, a[b_ptr..len][0..@sizeOf(u16)].*) != @bitCast(u16, b.ptr[b_ptr..len][0..@sizeOf(u16)].*)) return false; @@ -464,7 +463,7 @@ pub fn eqlLong(a_: string, b: string, comptime check_len: bool) bool { return true; } -pub inline fn append(allocator: *std.mem.Allocator, self: string, other: string) !string { +pub inline fn append(allocator: std.mem.Allocator, self: string, other: string) !string { return std.fmt.allocPrint(allocator, "{s}{s}", .{ self, other }); } @@ -494,7 +493,7 @@ pub fn eqlUtf16(comptime self: string, other: []const u16) bool { return std.mem.eql(u16, std.unicode.utf8ToUtf16LeStringLiteral(self), other); } -pub fn toUTF8Alloc(allocator: *std.mem.Allocator, js: []const u16) !string { +pub fn toUTF8Alloc(allocator: std.mem.Allocator, js: []const u16) !string { var temp: [4]u8 = undefined; var list = std.ArrayList(u8).initCapacity(allocator, js.len) catch unreachable; var i: usize = 0; @@ -759,15 +758,15 @@ pub fn containsNonBmpCodePointUTF16(_text: []const u16) bool { return false; } -pub fn join(slices: []const string, delimiter: string, allocator: *std.mem.Allocator) !string { +pub fn join(slices: []const string, delimiter: string, allocator: std.mem.Allocator) !string { return try std.mem.join(allocator, delimiter, slices); } -pub fn cmpStringsAsc(ctx: void, a: string, b: string) bool { +pub fn cmpStringsAsc(_: void, a: string, b: string) bool { return std.mem.order(u8, a, b) == .lt; } -pub fn cmpStringsDesc(ctx: void, a: string, b: string) bool { +pub fn cmpStringsDesc(_: void, a: string, b: string) bool { return std.mem.order(u8, a, b) == .gt; } @@ -944,7 +943,7 @@ pub const UnsignedCodepointIterator = NewCodePointIterator(u32, 0); pub fn NewLengthSorter(comptime Type: type, comptime field: string) type { return struct { const LengthSorter = @This(); - pub fn lessThan(context: LengthSorter, lhs: Type, rhs: Type) bool { + pub fn lessThan(_: LengthSorter, lhs: Type, rhs: Type) bool { return @field(lhs, field).len < @field(rhs, field).len; } }; |