perf: inline calls to StaticBitSet.isSet in sgr parser

pull/9645/head
Qwerasd 2025-11-18 16:13:15 -07:00
parent d14b4cf068
commit 5ffa7f8f45
1 changed files with 16 additions and 6 deletions

View File

@ -197,7 +197,12 @@ pub const Parser = struct {
}
const slice = self.params[self.idx..self.params.len];
const colon = self.params_sep.isSet(self.idx);
// Call inlined for performance reasons.
const colon = @call(
.always_inline,
SepList.isSet,
.{ self.params_sep, self.idx },
);
self.idx += 1;
// Our last one will have an idx be the last value.
@ -485,10 +490,13 @@ pub const Parser = struct {
/// Returns true if the present position has a colon separator.
/// This always returns false for the last value since it has no
/// separator.
fn isColon(self: *Parser) bool {
// The `- 1` here is because the last value has no separator.
if (self.idx >= self.params.len - 1) return false;
return self.params_sep.isSet(self.idx);
inline fn isColon(self: *Parser) bool {
// Call inlined for performance reasons.
return @call(
.always_inline,
SepList.isSet,
.{ self.params_sep, self.idx },
);
}
fn countColon(self: *Parser) usize {
@ -514,7 +522,9 @@ fn testParse(params: []const u16) Attribute {
}
fn testParseColon(params: []const u16) Attribute {
var p: Parser = .{ .params = params, .params_sep = .initFull() };
var p: Parser = .{ .params = params };
// Mark all parameters except the last as having a colon after.
for (0..params.len - 1) |i| p.params_sep.set(i);
return p.next().?;
}