Skip to content

Commit

Permalink
Slightly improve JSX decoding perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner committed Sep 18, 2021
1 parent b1ca1eb commit 9ae35ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
21
13 changes: 11 additions & 2 deletions src/js_lexer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2071,8 +2071,17 @@ pub const Lexer = struct {
}
}

threadlocal var jsx_decode_buf: std.ArrayList(u16) = undefined;
threadlocal var jsx_decode_init = false;
pub fn fixWhitespaceAndDecodeJSXEntities(lexer: *LexerType, text: string) !JavascriptString {
var decoded = std.ArrayList(u16).init(lexer.allocator);
if (!jsx_decode_init) {
jsx_decode_init = true;
jsx_decode_buf = std.ArrayList(u16).init(default_allocator);
}
jsx_decode_buf.clearRetainingCapacity();

var decoded = jsx_decode_buf;
defer jsx_decode_buf = decoded;
var decoded_ptr = &decoded;
var i: u32 = 0;
var after_last_non_whitespace: ?u32 = null;
Expand Down Expand Up @@ -2129,7 +2138,7 @@ pub const Lexer = struct {
try decodeJSXEntities(lexer, text[start..text.len], decoded_ptr);
}

return decoded.toOwnedSlice();
return decoded.items;
}

pub fn decodeJSXEntities(lexer: *LexerType, text: string, out: *std.ArrayList(u16)) !void {
Expand Down

0 comments on commit 9ae35ec

Please sign in to comment.