Skip to content

Commit c6455cf

Browse files
committed
Select is relatively large (64 bytes), pass it by ref
1 parent 2ac1d39 commit c6455cf

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/browser/css/css.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn parse(alloc: std.mem.Allocator, s: []const u8, opts: parser.ParseOptions)
4545

4646
// matchFirst call m.match with the first node that matches the selector s, from the
4747
// descendants of n and returns true. If none matches, it returns false.
48-
pub fn matchFirst(s: Selector, node: anytype, m: anytype) !bool {
48+
pub fn matchFirst(s: *const Selector, node: anytype, m: anytype) !bool {
4949
var c = try node.firstChild();
5050
while (true) {
5151
if (c == null) break;
@@ -63,7 +63,7 @@ pub fn matchFirst(s: Selector, node: anytype, m: anytype) !bool {
6363

6464
// matchAll call m.match with the all the nodes that matches the selector s, from the
6565
// descendants of n.
66-
pub fn matchAll(s: Selector, node: anytype, m: anytype) !void {
66+
pub fn matchAll(s: *const Selector, node: anytype, m: anytype) !void {
6767
var c = try node.firstChild();
6868
while (true) {
6969
if (c == null) break;

src/browser/css/selector.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ pub const Selector = union(enum) {
306306
}
307307

308308
// match returns true if the node matches the selector query.
309-
pub fn match(s: Selector, n: anytype) !bool {
310-
return switch (s) {
309+
pub fn match(s: *const Selector, n: anytype) !bool {
310+
return switch (s.*) {
311311
.tag => |v| n.isElement() and std.ascii.eqlIgnoreCase(v, try n.tag()),
312312
.id => |v| return n.isElement() and std.mem.eql(u8, v, try n.attr("id") orelse return false),
313313
.class => |v| return n.isElement() and word(try n.attr("class") orelse return false, v, false),
@@ -794,8 +794,8 @@ pub const Selector = union(enum) {
794794
return false;
795795
}
796796

797-
pub fn deinit(sel: Selector, alloc: std.mem.Allocator) void {
798-
switch (sel) {
797+
pub fn deinit(sel: *const Selector, alloc: std.mem.Allocator) void {
798+
switch (sel.*) {
799799
.group => |v| {
800800
for (v) |vv| vv.deinit(alloc);
801801
alloc.free(v);

src/browser/dom/css.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn querySelector(alloc: std.mem.Allocator, n: *parser.Node, selector: []cons
3838

3939
var m = MatchFirst{};
4040

41-
_ = try css.matchFirst(ps, Node{ .node = n }, &m);
41+
_ = try css.matchFirst(&ps, Node{ .node = n }, &m);
4242
return m.n;
4343
}
4444

@@ -75,6 +75,6 @@ pub fn querySelectorAll(alloc: std.mem.Allocator, n: *parser.Node, selector: []c
7575
var m = MatchAll.init(alloc);
7676
defer m.deinit();
7777

78-
try css.matchAll(ps, Node{ .node = n }, &m);
78+
try css.matchAll(&ps, Node{ .node = n }, &m);
7979
return m.toOwnedList();
8080
}

0 commit comments

Comments
 (0)