Reduce cost of various Element render-related properties.

Added a get-only `getStyle` which doesn't lazily create a new style if none
exists. This can be used in the (frequently used) `checkVisibility` to avoid
an allocation. Added a specialized getBoundingClientRectForVisible which
skips the checkVisibility check, since a few callers have already done their
own visibility check.

DOMRect is now off the heap. This avoids _a lot_ of allocation when a DOMRect
is only needed for internal calculation, e.g. in Document.elementFromPoint.
This commit is contained in:
Karl Seguin
2026-02-19 09:45:56 +08:00
parent bd29f168e0
commit 645da2e307
5 changed files with 83 additions and 67 deletions

View File

@@ -356,7 +356,7 @@ const BoxModel = struct {
// shapeOutside: ?ShapeOutsideInfo,
};
fn rectToQuad(rect: *const DOMNode.Element.DOMRect) Quad {
fn rectToQuad(rect: DOMNode.Element.DOMRect) Quad {
return Quad{
rect._x,
rect._y,
@@ -434,9 +434,7 @@ fn getContentQuads(cmd: anytype) !void {
// Text may be tricky, multiple quads in case of multiple lines? empty quads of text = ""?
// Elements like SVGElement may have multiple quads.
const rect = try element.getBoundingClientRect(page);
const quad = rectToQuad(rect);
const quad = rectToQuad(element.getBoundingClientRect(page));
return cmd.sendResult(.{ .quads = &.{quad} }, .{});
}
@@ -455,7 +453,7 @@ fn getBoxModel(cmd: anytype) !void {
// TODO implement for document or text
const element = node.dom.is(DOMNode.Element) orelse return error.NodeIsNotAnElement;
const rect = try element.getBoundingClientRect(page);
const rect = element.getBoundingClientRect(page);
const quad = rectToQuad(rect);
const zero = [_]f64{0.0} ** 8;