aboutsummaryrefslogtreecommitdiff
path: root/src/sourcemap/sourcemap.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-07 21:02:29 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-07 21:02:29 -0800
commit04568452567995e3aa42535ca356d83e60ed030f (patch)
tree87d5f74258b29d152c7c6195447dbc383f8d0099 /src/sourcemap/sourcemap.zig
parentce081f15e97055ae6641acc5fb7627acaf215602 (diff)
downloadbun-04568452567995e3aa42535ca356d83e60ed030f.tar.gz
bun-04568452567995e3aa42535ca356d83e60ed030f.tar.zst
bun-04568452567995e3aa42535ca356d83e60ed030f.zip
Add VLQ bench, improve decodeVLQ perf
Diffstat (limited to 'src/sourcemap/sourcemap.zig')
-rw-r--r--src/sourcemap/sourcemap.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig
index 3b6048985..e043a493b 100644
--- a/src/sourcemap/sourcemap.zig
+++ b/src/sourcemap/sourcemap.zig
@@ -298,7 +298,7 @@ const base64_lut: [std.math.maxInt(u7)]u7 = brk: {
break :brk bytes;
};
-fn decodeVLQ(encoded: []const u8, start: usize) VLQResult {
+pub fn decodeVLQ(encoded: []const u8, start: usize) VLQResult {
var shift: u8 = 0;
var vlq: u32 = 0;
@@ -306,8 +306,10 @@ fn decodeVLQ(encoded: []const u8, start: usize) VLQResult {
// by doing it this way, we can hint to the compiler that it will not exceed 9
const encoded_ = encoded[start..][0..@minimum(encoded.len - start, comptime (vlq_max_in_bytes + 1))];
- for (encoded_) |c, i| {
- const index = @as(u32, base64_lut[@truncate(u7, c)]);
+ comptime var i: usize = 0;
+
+ inline while (i < vlq_max_in_bytes + 1) : (i += 1) {
+ const index = @as(u32, base64_lut[@truncate(u7, encoded_[i])]);
// decode a byte
vlq |= (index & 31) << @truncate(u5, shift);
@@ -563,6 +565,7 @@ pub fn appendMappingToBuffer(buffer_: MutableString, last_byte: u8, prev_state:
if (needs_comma) {
buffer.appendCharAssumeCapacity(',');
}
+
comptime var i: usize = 0;
inline while (i < vlq.len) : (i += 1) {
buffer.appendAssumeCapacity(vlq[i].bytes[0..vlq[i].len]);