diff options
Diffstat (limited to 'src/resolver')
-rw-r--r-- | src/resolver/data_url.zig | 8 | ||||
-rw-r--r-- | src/resolver/package_json.zig | 11 | ||||
-rw-r--r-- | src/resolver/resolve_path.zig | 22 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 41 |
4 files changed, 37 insertions, 45 deletions
diff --git a/src/resolver/data_url.zig b/src/resolver/data_url.zig index 5404b0591..1ce6381fb 100644 --- a/src/resolver/data_url.zig +++ b/src/resolver/data_url.zig @@ -10,9 +10,7 @@ const default_allocator = bun.default_allocator; const C = bun.C; const std = @import("std"); -const assert = std.debug.assert; -const mem = std.mem; -const Allocator = mem.Allocator; +const Allocator = std.mem.Allocator; const ComptimeStringMap = @import("../comptime_string_map.zig").ComptimeStringMap; // https://github.com/Vexu/zuri/blob/master/src/zuri.zig#L61-L127 @@ -33,7 +31,7 @@ pub const PercentEncoding = struct { /// returns true if str starts with a valid path character or a percent encoded octet pub fn isPchar(str: []const u8) bool { - if (Environment.allow_assert) assert(str.len > 0); + if (comptime Environment.allow_assert) std.debug.assert(str.len > 0); return switch (str[0]) { 'a'...'z', 'A'...'Z', '0'...'9', '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=', ':', '@' => true, '%' => str.len > 3 and isHex(str[1]) and isHex(str[2]), @@ -55,7 +53,7 @@ pub const PercentEncoding = struct { } if (ret == null) { ret = try allocator.alloc(u8, path.len); - mem.copy(u8, ret.?, path[0..i]); + bun.copy(u8, ret, path[0..i]); ret_index = i; } diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 25b2ca673..0785e0493 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -60,12 +60,12 @@ pub const PackageJSON = struct { var hashy: [1024]u8 = undefined; std.mem.set(u8, &hashy, 0); var used: usize = 0; - std.mem.copy(u8, &hashy, package_json.name); + bun.copy(u8, &hashy, package_json.name); used = package_json.name.len; hashy[used] = '@'; used += 1; - std.mem.copy(u8, hashy[used..], package_json.version); + bun.copy(u8, hashy[used..], package_json.version); used += package_json.version.len; package_json.hash = std.hash.Murmur3_32.hash(hashy[0..used]); @@ -80,9 +80,8 @@ pub const PackageJSON = struct { if (strings.indexOf(parent, fs.FileSystem.instance.top_level_dir)) |i| { const relative_dir = parent[i + fs.FileSystem.instance.top_level_dir.len ..]; var out_dir = try allocator.alloc(u8, relative_dir.len + 2); - std.mem.copy(u8, out_dir[2..], relative_dir); - out_dir[0] = '.'; - out_dir[1] = '/'; + bun.copy(u8, out_dir[2..], relative_dir); + out_dir[0..2].* = ("." ++ std.fs.path.sep_str).*; return out_dir; } @@ -1346,8 +1345,8 @@ pub const ESModule = struct { } pub fn parseSubpath(subpath: *[]const u8, specifier: string, subpath_buf: []u8) void { - std.mem.copy(u8, subpath_buf[1..], specifier); subpath_buf[0] = '.'; + bun.copy(u8, subpath_buf[1..], specifier); subpath.* = subpath_buf[0 .. specifier.len + 1]; } }; diff --git a/src/resolver/resolve_path.zig b/src/resolver/resolve_path.zig index 20f889c2c..c44c2597d 100644 --- a/src/resolver/resolve_path.zig +++ b/src/resolver/resolve_path.zig @@ -202,7 +202,7 @@ pub fn relativeToCommonPath( // We get here if `from` is the root // For example: from='/'; to='/foo' if (always_copy) { - std.mem.copy(u8, buf, normalized_to); + bun.copy(u8, buf, normalized_to); return buf[0..normalized_to.len]; } else { return normalized_to; @@ -213,10 +213,9 @@ pub fn relativeToCommonPath( const slice = normalized_to[common_path.len..]; if (always_copy) { - // We get here if `from` is the exact base path for `to`. // For example: from='/foo/bar'; to='/foo/bar/baz' - std.mem.copy(u8, buf, slice); + bun.copy(u8, buf, slice); return buf[0..slice.len]; } else { return slice; @@ -268,7 +267,7 @@ pub fn relativeToCommonPath( const start = out_slice.len; out_slice = buf[0 .. out_slice.len + tail.len]; - std.mem.copy(u8, out_slice[start..], tail); + bun.copy(u8, out_slice[start..], tail); } return buf[0..out_slice.len]; @@ -690,11 +689,7 @@ pub fn joinStringBuf(buf: []u8, _parts: anytype, comptime _platform: Platform) [ written += 1; } - std.mem.copy( - u8, - temp_buf[written..], - part, - ); + bun.copy(u8, temp_buf[written..], part); written += part.len; } @@ -752,7 +747,7 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ } } - std.mem.copy(u8, &temp_buf, cwd); + bun.copy(u8, &temp_buf, cwd); out = cwd.len; for (parts) |_part| { @@ -767,12 +762,11 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ out += 1; } - std.mem.copy(u8, temp_buf[out..], part); + bun.copy(u8, temp_buf[out..], part); out += part.len; } - const leading_separator: []const u8 = - if (_platform.leadingSeparatorIndex(temp_buf[0..out])) |i| + const leading_separator: []const u8 = if (_platform.leadingSeparatorIndex(temp_buf[0..out])) |i| temp_buf[0 .. i + 1] else "/"; @@ -785,7 +779,7 @@ inline fn _joinAbsStringBuf(comptime is_sentinel: bool, comptime ReturnType: typ true, ); - std.mem.copy(u8, buf[0..leading_separator.len], leading_separator); + bun.copy(u8, buf, leading_separator); if (comptime is_sentinel) { buf.ptr[result.len + leading_separator.len] = 0; diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 45c0262fd..c2e00c22c 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -295,8 +295,9 @@ pub const DebugLogs = struct { const len = d.indent.len(); if (len > 0) { var __text = d.notes.allocator.alloc(u8, text.len + len) catch unreachable; - std.mem.copy(u8, __text, d.indent.list.items); - std.mem.copy(u8, __text[len..__text.len], _text); + bun.copy(u8, __text, d.indent.list.items); + bun.copy(u8, __text[len..], _text); + text = __text; d.notes.allocator.free(_text); } @@ -593,7 +594,7 @@ pub const Resolver = struct { } prefixed_package_buf[0..bunFrameworkPackagePrefix.len].* = bunFrameworkPackagePrefix.*; - std.mem.copy(u8, prefixed_package_buf[bunFrameworkPackagePrefix.len..], package); + bun.copy(u8, prefixed_package_buf[bunFrameworkPackagePrefix.len..], package); const prefixed_name = prefixed_package_buf[0 .. bunFrameworkPackagePrefix.len + package.len]; return r._resolveFramework(prefixed_name, pair, preference, load_defines) catch |err| { switch (err) { @@ -692,7 +693,7 @@ pub const Resolver = struct { }; var out = try r.allocator.alloc(u8, chosen_dir.len + 1); - std.mem.copy(u8, out, chosen_dir); + bun.copy(u8, out, chosen_dir); out[out.len - 1] = '/'; pair.router.dir = out; pair.router.routes_enabled = true; @@ -2036,10 +2037,10 @@ pub const Resolver = struct { // Try to have a friendly error message if people forget the extension if (ends_with_star) { - std.mem.copy(u8, &load_as_file_buf, base); + bun.copy(u8, &load_as_file_buf, base); for (extension_order) |ext| { var file_name = load_as_file_buf[0 .. base.len + ext.len]; - std.mem.copy(u8, file_name[base.len..], ext); + bun.copy(u8, file_name[base.len..], ext); if (entries.get(file_name) != null) { if (r.debug_logs) |*debug| { const parts = [_]string{ package_json.name, package_subpath }; @@ -2063,10 +2064,10 @@ pub const Resolver = struct { if (r.dirInfoCached(abs_esm_path) catch null) |dir_info| { if (dir_info.getEntries()) |dir_entries| { const index = "index"; - std.mem.copy(u8, &load_as_file_buf, index); + bun.copy(u8, &load_as_file_buf, index); for (extension_order) |ext| { var file_name = load_as_file_buf[0 .. index.len + ext.len]; - std.mem.copy(u8, file_name[index.len..], ext); + bun.copy(u8, file_name[index.len..], ext); const index_query = dir_entries.get(file_name); if (index_query != null and index_query.?.entry.kind(&r.fs.fs) == .file) { missing_suffix = std.fmt.allocPrint(r.allocator, "/{s}", .{file_name}) catch unreachable; @@ -2268,7 +2269,7 @@ pub const Resolver = struct { } var i: i32 = 1; - std.mem.copy(u8, &dir_info_uncached_path_buf, _path); + bun.copy(u8, &dir_info_uncached_path_buf, _path); var path = dir_info_uncached_path_buf[0.._path.len]; _dir_entry_paths_to_resolve[0] = (DirEntryResolveQueueItem{ .result = top_result, .unsafe_path = path, .safe_path = "" }); @@ -2701,11 +2702,11 @@ pub const Resolver = struct { return true; } - std.mem.copy(u8, &TemporaryBuffer.ExtensionPathBuf, cleaned); + bun.copy(u8, &TemporaryBuffer.ExtensionPathBuf, cleaned); // If that failed, try adding implicit extensions for (this.extension_order) |ext| { - std.mem.copy(u8, TemporaryBuffer.ExtensionPathBuf[cleaned.len .. cleaned.len + ext.len], ext); + bun.copy(u8, TemporaryBuffer.ExtensionPathBuf[cleaned.len..], ext); const new_path = TemporaryBuffer.ExtensionPathBuf[0 .. cleaned.len + ext.len]; // if (r.debug_logs) |*debug| { // debug.addNoteFmt("Checking for \"{s}\" ", .{new_path}); @@ -2732,10 +2733,10 @@ pub const Resolver = struct { return true; } - std.mem.copy(u8, &TemporaryBuffer.ExtensionPathBuf, index_path); + bun.copy(u8, &TemporaryBuffer.ExtensionPathBuf, index_path); for (this.extension_order) |ext| { - std.mem.copy(u8, TemporaryBuffer.ExtensionPathBuf[index_path.len .. index_path.len + ext.len], ext); + bun.copy(u8, TemporaryBuffer.ExtensionPathBuf[index_path.len..], ext); const new_path = TemporaryBuffer.ExtensionPathBuf[0 .. index_path.len + ext.len]; // if (r.debug_logs) |*debug| { // debug.addNoteFmt("Checking for \"{s}\" ", .{new_path}); @@ -2805,7 +2806,7 @@ pub const Resolver = struct { switch (comptime kind) { .AbsolutePath => { BrowserMapPath.abs_to_rel_buf[0..2].* = "./".*; - std.mem.copy(u8, BrowserMapPath.abs_to_rel_buf[2..], checker.input_path); + bun.copy(u8, BrowserMapPath.abs_to_rel_buf[2..], checker.input_path); if (checker.checkPath(BrowserMapPath.abs_to_rel_buf[0 .. checker.input_path.len + 2])) { return checker.remapped; } @@ -2825,7 +2826,7 @@ pub const Resolver = struct { if (isInSamePackage) { BrowserMapPath.abs_to_rel_buf[0..2].* = "./".*; - std.mem.copy(u8, BrowserMapPath.abs_to_rel_buf[2..], checker.input_path); + bun.copy(u8, BrowserMapPath.abs_to_rel_buf[2..], checker.input_path); if (checker.checkPath(BrowserMapPath.abs_to_rel_buf[0 .. checker.input_path.len + 2])) { return checker.remapped; @@ -2916,7 +2917,7 @@ pub const Resolver = struct { for (extension_order) |ext| { var base = TemporaryBuffer.ExtensionPathBuf[0 .. "index".len + ext.len]; base[0.."index".len].* = "index".*; - std.mem.copy(u8, base["index".len..base.len], ext); + bun.copy(u8, base["index".len..], ext); if (dir_info.getEntries()) |entries| { if (entries.get(base)) |lookup| { @@ -2966,7 +2967,7 @@ pub const Resolver = struct { // In order for our path handling logic to be correct, it must end with a trailing slash. var path = path_; if (!strings.endsWithChar(path_, std.fs.path.sep)) { - std.mem.copy(u8, &remap_path_trailing_slash, path); + bun.copy(u8, &remap_path_trailing_slash, path); remap_path_trailing_slash[path.len] = std.fs.path.sep; remap_path_trailing_slash[path.len + 1] = 0; path = remap_path_trailing_slash[0 .. path.len + 1]; @@ -3241,10 +3242,10 @@ pub const Resolver = struct { } // Try the path with extensions - std.mem.copy(u8, &load_as_file_buf, path); + bun.copy(u8, &load_as_file_buf, path); for (extension_order) |ext| { var buffer = load_as_file_buf[0 .. path.len + ext.len]; - std.mem.copy(u8, buffer[path.len..buffer.len], ext); + bun.copy(u8, buffer[path.len..], ext); const file_name = buffer[path.len - base.len .. buffer.len]; if (r.debug_logs) |*debug| { @@ -3295,7 +3296,7 @@ pub const Resolver = struct { if (strings.eqlComptime(ext, ".js") or strings.eqlComptime(ext, ".jsx")) { const segment = base[0..last_dot]; var tail = load_as_file_buf[path.len - base.len ..]; - std.mem.copy(u8, tail, segment); + bun.copy(u8, tail, segment); const exts = .{ ".ts", ".tsx" }; |