mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
* 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
* 📷
* 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
77 lines
2.0 KiB
Zig
77 lines
2.0 KiB
Zig
const std = @import("std");
|
|
const Lock = @import("./lock.zig").Lock;
|
|
const _global = @import("./global.zig");
|
|
const string = _global.string;
|
|
const Output = _global.Output;
|
|
const Global = _global.Global;
|
|
const Environment = _global.Environment;
|
|
const strings = _global.strings;
|
|
const MutableString = _global.MutableString;
|
|
const stringZ = _global.stringZ;
|
|
const default_allocator = _global.default_allocator;
|
|
const C = _global.C;
|
|
|
|
const Blob = @This();
|
|
|
|
ptr: [*]const u8,
|
|
len: usize,
|
|
|
|
pub const Map = struct {
|
|
const MapContext = struct {
|
|
pub fn hash(_: @This(), s: u64) u32 {
|
|
return @truncate(u32, s);
|
|
}
|
|
pub fn eql(_: @This(), a: u64, b: u64) bool {
|
|
return a == b;
|
|
}
|
|
};
|
|
|
|
const HashMap = std.ArrayHashMap(u64, Blob, MapContext, false);
|
|
lock: Lock,
|
|
map: HashMap,
|
|
allocator: std.mem.Allocator,
|
|
|
|
pub fn init(allocator: std.mem.Allocator) Map {
|
|
return Map{
|
|
.lock = Lock.init(),
|
|
.map = HashMap.init(allocator),
|
|
.allocator = allocator,
|
|
};
|
|
}
|
|
|
|
pub fn get(this: *Map, key: string) ?Blob {
|
|
this.lock.lock();
|
|
defer this.lock.unlock();
|
|
return this.map.get(std.hash.Wyhash.hash(0, key));
|
|
}
|
|
|
|
pub fn put(this: *Map, key: string, blob: Blob) !void {
|
|
this.lock.lock();
|
|
defer this.lock.unlock();
|
|
|
|
return try this.map.put(std.hash.Wyhash.hash(0, key), blob);
|
|
}
|
|
|
|
pub fn reset(this: *Map) !void {
|
|
this.lock.lock();
|
|
defer this.lock.unlock();
|
|
this.map.clearRetainingCapacity();
|
|
}
|
|
};
|
|
|
|
pub const Group = struct {
|
|
persistent: Map,
|
|
temporary: Map,
|
|
allocator: std.mem.Allocator,
|
|
|
|
pub fn init(allocator: std.mem.Allocator) !*Group {
|
|
var group = try allocator.create(Group);
|
|
group.* = Group{ .persistent = Map.init(allocator), .temporary = Map.init(allocator), .allocator = allocator };
|
|
return group;
|
|
}
|
|
|
|
pub fn get(this: *Group, key: string) ?Blob {
|
|
return this.temporary.get(key) orelse this.persistent.get(key);
|
|
}
|
|
};
|