stage2 大量优化代码使其自举编译时间大幅缩短

This commit is contained in:
zzy committed 2026-09-20 09:33:20 +08:00
1 parent e02b0c633a
commit 846f441e3a
38 files changed
+2418 -835

No files matched your search

+8 -8
View File
@@ -3,7 +3,8 @@
// 开放寻址集合。键按字节复制到集合自己的存储中;集合只释放自身存储,
// 不释放键值内部引用的资源。哈希与相等回调的约定和 Map 一致。
type .{ .Status } = @import("error.spl");
type .{ .Map, .LookupResult } = @import("map.spl");
type .{ .Map, .LookupResult, .hash_kind_usize, .hash_kind_view, .hash_kind_constant } =
@import("map.spl");
type .{ .ByteView } = @import("byte_view.spl");
type .{ .hash_usize, .eq_usize, .hash_view, .eq_view } = @import("hash.spl");
@@ -11,15 +12,14 @@ type Set = @self;
map: Map,
fn new(key_size: usize, key_align: usize,
hash_fn: fn(*u8): usize, eq_fn: fn(*u8, *u8): bool): Set {
fn new(key_size: usize, key_align: usize, hash_kind: usize): Set {
ret Set {
.map = Map.new(key_size, key_align, 1, 1, hash_fn, eq_fn),
.map = Map.new(key_size, key_align, 1, 1, hash_kind),
};
}
fn valid(self: Set): bool {
ret Map.valid(self.map) && self.map.val_size == 1;
ret Map.valid(&self.map) && self.map.val_size == 1;
}
fn size(self: Set): usize {
@@ -104,7 +104,7 @@ fn constant_hash(key: *u8): usize {
}
fn test_insert_find_remove() {
var set = new(@sizeof(usize), @alignof(usize), hash_usize, eq_usize);
var set = new(@sizeof(usize), @alignof(usize), hash_kind_usize());
defer { drop(&set); }
@assert(valid(set));
@assert(size(set) == 0 && capacity(set) == 0);
@@ -169,7 +169,7 @@ fn test_insert_find_remove() {
}
fn test_collisions_and_take() {
var set = new(@sizeof(usize), @alignof(usize), constant_hash, eq_usize);
var set = new(@sizeof(usize), @alignof(usize), hash_kind_constant());
defer { drop(&set); }
var i: usize = 0;
@@ -213,7 +213,7 @@ fn test_collisions_and_take() {
}
fn test_byte_view_keys() {
var set = new(@sizeof(ByteView), @alignof(ByteView), hash_view, eq_view);
var set = new(@sizeof(ByteView), @alignof(ByteView), hash_kind_view());
defer { drop(&set); }
var alpha = ByteView.from_slice("alpha");