mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
Make js.Bridge aware of string.String for input parameters
Avoids having to allocate small strings when going from v8 -> Zig. Also added a discriminatory type, string.Global which uses the arena, rather than the call_arena, if an allocation _is_ necessary. (This is similar to a feature we had before, but was lost in zigdom). Strings from v8 that need to be persisted, can be allocated directly v8 -> arena, rather than v8 -> call_arena -> arena. I think there are a lot of places where we should use string.String - where strings are expected to be short (e.g. attribute names). But started with just document.querySelector and querySelectorAll.
This commit is contained in:
@@ -188,6 +188,13 @@ pub const String = packed struct {
|
||||
}
|
||||
};
|
||||
|
||||
// Discriminatory type that signals the bridge to use arena instead of call_arena
|
||||
// Use this for strings that need to persist beyond the current call
|
||||
// The caller can unwrap and store just the underlying .str field
|
||||
pub const Global = struct {
|
||||
str: String,
|
||||
};
|
||||
|
||||
fn asUint(comptime string: anytype) std.meta.Int(
|
||||
.unsigned,
|
||||
@bitSizeOf(@TypeOf(string.*)) - 8, // (- 8) to exclude sentinel 0
|
||||
|
||||
Reference in New Issue
Block a user