diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-05-07 16:29:42 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-06-10 20:42:29 -0700 |
| commit | 2f9b7dc1023e9ff21574b559e22265db65e00d2d (patch) | |
| tree | df09a315169c8e9485057349ee4a007a9a2af2b8 /src/InternPool.zig | |
| parent | 4fe0c583be8890b1cb8059c2daff3bd82c53d2e9 (diff) | |
| download | zig-2f9b7dc1023e9ff21574b559e22265db65e00d2d.tar.gz zig-2f9b7dc1023e9ff21574b559e22265db65e00d2d.zip | |
InternPool: add an int_u8 value encoding
On a simple input file, this had a total savings of 21% in the
InternPool:
Before:
int_positive: 427 occurrences, 8975 total bytes
After:
int_positive: 258 occurrences, 5426 total bytes
int_u8: 169 occurrences, 845 total bytes
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index c60f58e207..4f2e792a49 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -721,6 +721,9 @@ pub const Tag = enum(u8) { /// only an enum tag, but will be presented via the API with a different Key. /// data is SimpleInternal enum value. simple_internal, + /// Type: u8 + /// data is integer value + int_u8, /// Type: u16 /// data is integer value int_u16, @@ -1056,6 +1059,10 @@ pub fn indexToKey(ip: InternPool, index: Index) Key { .type_error_union => @panic("TODO"), .type_enum_simple => @panic("TODO"), .simple_internal => @panic("TODO"), + .int_u8 => .{ .int = .{ + .ty = .u8_type, + .storage = .{ .u64 = data }, + } }, .int_u16 => .{ .int = .{ .ty = .u16_type, .storage = .{ .u64 = data }, @@ -1226,6 +1233,22 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index { .int => |int| b: { switch (int.ty) { .none => unreachable, + .u8_type => switch (int.storage) { + .big_int => |big_int| { + ip.items.appendAssumeCapacity(.{ + .tag = .int_u8, + .data = big_int.to(u8) catch unreachable, + }); + break :b; + }, + inline .u64, .i64 => |x| { + ip.items.appendAssumeCapacity(.{ + .tag = .int_u8, + .data = @intCast(u8, x), + }); + break :b; + }, + }, .u16_type => switch (int.storage) { .big_int => |big_int| { if (big_int.to(u32)) |casted| { @@ -1678,6 +1701,7 @@ fn dumpFallible(ip: InternPool, arena: Allocator) anyerror!void { .simple_type => 0, .simple_value => 0, .simple_internal => 0, + .int_u8 => 0, .int_u16 => 0, .int_u32 => 0, .int_i32 => 0, |
