From b9024ab0325608be1d60656a87755d8361dc4cf8 Mon Sep 17 00:00:00 2001 From: nikneym Date: Fri, 26 Sep 2025 15:37:49 +0300 Subject: [PATCH] set_innerHTML: simpler iteration --- src/browser/dom/element.zig | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/browser/dom/element.zig b/src/browser/dom/element.zig index 90317d9e..1d8f786b 100644 --- a/src/browser/dom/element.zig +++ b/src/browser/dom/element.zig @@ -192,11 +192,9 @@ pub const Element = struct { // a new fragment const clean = try parser.documentCreateDocumentFragment(doc); const children = try parser.nodeGetChildNodes(body); - const ln = parser.nodeListLength(children); - for (0..ln) |_| { - // always index 0, because nodeAppendChild moves the node out of - // the nodeList and into the new tree - const child = parser.nodeListItem(children, 0) orelse continue; + // always index 0, because nodeAppendChild moves the node out of + // the nodeList and into the new tree + while (parser.nodeListItem(children, 0)) |child| { _ = try parser.nodeAppendChild(@ptrCast(@alignCast(clean)), child); } @@ -210,22 +208,18 @@ pub const Element = struct { { // First, copy some of the head element const children = try parser.nodeGetChildNodes(head); - const ln = parser.nodeListLength(children); - for (0..ln) |_| { - // always index 0, because nodeAppendChild moves the node out of - // the nodeList and into the new tree - const child = parser.nodeListItem(children, 0) orelse continue; + // always index 0, because nodeAppendChild moves the node out of + // the nodeList and into the new tree + while (parser.nodeListItem(children, 0)) |child| { _ = try parser.nodeAppendChild(node, child); } } { const children = try parser.nodeGetChildNodes(body); - const ln = parser.nodeListLength(children); - for (0..ln) |_| { - // always index 0, because nodeAppendChild moves the node out of - // the nodeList and into the new tree - const child = parser.nodeListItem(children, 0) orelse continue; + // always index 0, because nodeAppendChild moves the node out of + // the nodeList and into the new tree + while (parser.nodeListItem(children, 0)) |child| { _ = try parser.nodeAppendChild(node, child); } }