mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
SemanticTree: use StaticStringMap for structural role check
Improves performance and readability of isStructuralRole. Also includes minor syntax cleanup in AXNode.
This commit is contained in:
@@ -367,21 +367,22 @@ const JsonVisitor = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn isStructuralRole(role: []const u8) bool {
|
fn isStructuralRole(role: []const u8) bool {
|
||||||
// zig fmt: off
|
const structural_roles = std.StaticStringMap(void).initComptime(.{
|
||||||
return std.mem.eql(u8, role, "none") or
|
.{ "none", {} },
|
||||||
std.mem.eql(u8, role, "generic") or
|
.{ "generic", {} },
|
||||||
std.mem.eql(u8, role, "InlineTextBox") or
|
.{ "InlineTextBox", {} },
|
||||||
std.mem.eql(u8, role, "banner") or
|
.{ "banner", {} },
|
||||||
std.mem.eql(u8, role, "navigation") or
|
.{ "navigation", {} },
|
||||||
std.mem.eql(u8, role, "main") or
|
.{ "main", {} },
|
||||||
std.mem.eql(u8, role, "list") or
|
.{ "list", {} },
|
||||||
std.mem.eql(u8, role, "listitem") or
|
.{ "listitem", {} },
|
||||||
std.mem.eql(u8, role, "table") or
|
.{ "table", {} },
|
||||||
std.mem.eql(u8, role, "rowgroup") or
|
.{ "rowgroup", {} },
|
||||||
std.mem.eql(u8, role, "row") or
|
.{ "row", {} },
|
||||||
std.mem.eql(u8, role, "cell") or
|
.{ "cell", {} },
|
||||||
std.mem.eql(u8, role, "region");
|
.{ "region", {} },
|
||||||
// zig fmt: on
|
});
|
||||||
|
return structural_roles.has(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
const TextVisitor = struct {
|
const TextVisitor = struct {
|
||||||
|
|||||||
@@ -767,7 +767,7 @@ pub fn getName(self: AXNode, page: *Page, allocator: std.mem.Allocator) !?[]cons
|
|||||||
pub fn endWriteRaw(_: @This()) void {}
|
pub fn endWriteRaw(_: @This()) void {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const w = TextCaptureWriter{ .aw = &aw, .writer = &aw.writer };
|
const w: TextCaptureWriter = .{ .aw = &aw, .writer = &aw.writer };
|
||||||
|
|
||||||
const source = try self.writeName(w, page);
|
const source = try self.writeName(w, page);
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user