mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-10-09 12:51:45 -04:00
perf: improve common element attribute getters
In main, there's a `getId`, and `getClassName` (etc...) getter on Element. But
these all `orelse ""`, because that's what the WebAPI wants. Internally though,
most code want the optional. The result is that _many_ places do:
```zig
el.getAttributeSafe(comptime .wrap("id"))
```
instead of:
```zig
el.getId()
```
This is a bit tedious AND, it means that when we improve `Element.getId` (1) no
internal caller benefits from it. This commit makes the element getters return
the optional (`?[]const u8`) and updates every callsite to use the new getter.
The `orelse ""` needed by the WebAPI is moved to the JsApi bridge.
(1) https://github.com/lightpanda-io/browser/pull/3457
This commit is contained in:
53 files changed
+275
-210
No files matched your search
@@ -201,7 +201,7 @@ fn walk(
|
||||
var name = try axn.getName(self.frame, self.arena, ctx.label_index);
|
||||
|
||||
const has_explicit_label = if (node.is(Element)) |el|
|
||||
el.getAttributeSafe(comptime .wrap("aria-label")) != null or el.getAttributeSafe(comptime .wrap("title")) != null
|
||||
el.getAttributeInterned("aria-label") != null or el.getAttributeInterned("title") != null
|
||||
else
|
||||
false;
|
||||
|
||||
@@ -681,12 +681,12 @@ pub fn getNodeDetails(
|
||||
if (node.is(Element)) |el| {
|
||||
tag_name = el.getTagNameLower();
|
||||
is_disabled = el.isDisabled();
|
||||
id_attr = el.getAttributeSafe(comptime .wrap("id"));
|
||||
class_attr = el.getAttributeSafe(comptime .wrap("class"));
|
||||
id_attr = el.getId();
|
||||
class_attr = el.getClassName();
|
||||
selector = try SelectorPath.init(arena, frame).build(el);
|
||||
placeholder = el.getAttributeSafe(comptime .wrap("placeholder"));
|
||||
placeholder = el.getAttributeInterned("placeholder");
|
||||
|
||||
if (el.getAttributeSafe(comptime .wrap("href"))) |h| {
|
||||
if (el.getAttributeInterned("href")) |h| {
|
||||
const URL = lp.URL;
|
||||
href = URL.resolve(arena, frame.base(), h, .{ .encoding = frame.charset }) catch h;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user