aboutsummaryrefslogtreecommitdiff
path: root/src/bun.zig
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/bun.zig33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/bun.zig b/src/bun.zig
index c6fce74de..e6349fee9 100644
--- a/src/bun.zig
+++ b/src/bun.zig
@@ -20,6 +20,10 @@ else
pub const huge_allocator_threshold: comptime_int = @import("./memory_allocator.zig").huge_threshold;
+/// We cannot use a threadlocal memory allocator for FileSystem-related things
+/// FileSystem is a singleton.
+pub const fs_allocator = default_allocator;
+
pub const C = @import("c.zig");
pub const FeatureFlags = @import("feature_flags.zig");
@@ -1280,12 +1284,14 @@ pub const Schema = @import("./api/schema.zig");
pub const StringMap = struct {
map: Map,
+ dupe_keys: bool = false,
pub const Map = StringArrayHashMap(string);
- pub fn init(allocator: std.mem.Allocator) StringMap {
+ pub fn init(allocator: std.mem.Allocator, dupe_keys: bool) StringMap {
return StringMap{
.map = Map.init(allocator),
+ .dupe_keys = dupe_keys,
};
}
@@ -1311,7 +1317,8 @@ pub const StringMap = struct {
pub fn insert(self: *StringMap, key: []const u8, value: []const u8) !void {
var entry = try self.map.getOrPut(key);
if (!entry.found_existing) {
- entry.key_ptr.* = try self.map.allocator.dupe(u8, key);
+ if (self.dupe_keys)
+ entry.key_ptr.* = try self.map.allocator.dupe(u8, key);
} else {
self.map.allocator.free(entry.value_ptr.*);
}
@@ -1319,13 +1326,20 @@ pub const StringMap = struct {
entry.value_ptr.* = try self.map.allocator.dupe(u8, value);
}
+ pub const put = insert;
+ pub fn get(self: *const StringMap, key: []const u8) ?[]const u8 {
+ return self.map.get(key);
+ }
+
pub fn deinit(self: *StringMap) void {
for (self.map.values()) |value| {
self.map.allocator.free(value);
}
- for (self.map.keys()) |key| {
- self.map.allocator.free(key);
+ if (self.dupe_keys) {
+ for (self.map.keys()) |key| {
+ self.map.allocator.free(key);
+ }
}
self.map.deinit();
@@ -1334,3 +1348,14 @@ pub const StringMap = struct {
pub const DotEnv = @import("./env_loader.zig");
pub const BundleV2 = @import("./bundler/bundle_v2.zig").BundleV2;
+
+pub const Lock = @import("./lock.zig").Lock;
+pub const UnboundedQueue = @import("./bun.js/unbounded_queue.zig").UnboundedQueue;
+
+pub fn threadlocalAllocator() std.mem.Allocator {
+ if (comptime use_mimalloc) {
+ return MimallocArena.getThreadlocalDefault();
+ }
+
+ return default_allocator;
+}