zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2f9b7dc1023e9ff21574b559e22265db65e00d2d (tree)
parent 4fe0c583be8890b1cb8059c2daff3bd82c53d2e9
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Sun,  7 May 2023 16:29:42 -0700

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:
Msrc/InternPool.zig | 24++++++++++++++++++++++++
1 file changed, 24 insertions(+), 0 deletions(-)

diff --git 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,