@@ -192,11 +192,9 @@ pub const Element = struct {
192192 // a new fragment
193193 const clean = try parser .documentCreateDocumentFragment (doc );
194194 const children = try parser .nodeGetChildNodes (body );
195- const ln = parser .nodeListLength (children );
196- for (0.. ln ) | _ | {
197- // always index 0, because nodeAppendChild moves the node out of
198- // the nodeList and into the new tree
199- const child = parser .nodeListItem (children , 0 ) orelse continue ;
195+ // always index 0, because nodeAppendChild moves the node out of
196+ // the nodeList and into the new tree
197+ while (parser .nodeListItem (children , 0 )) | child | {
200198 _ = try parser .nodeAppendChild (@ptrCast (@alignCast (clean )), child );
201199 }
202200
@@ -210,22 +208,18 @@ pub const Element = struct {
210208 {
211209 // First, copy some of the head element
212210 const children = try parser .nodeGetChildNodes (head );
213- const ln = parser .nodeListLength (children );
214- for (0.. ln ) | _ | {
215- // always index 0, because nodeAppendChild moves the node out of
216- // the nodeList and into the new tree
217- const child = parser .nodeListItem (children , 0 ) orelse continue ;
211+ // always index 0, because nodeAppendChild moves the node out of
212+ // the nodeList and into the new tree
213+ while (parser .nodeListItem (children , 0 )) | child | {
218214 _ = try parser .nodeAppendChild (node , child );
219215 }
220216 }
221217
222218 {
223219 const children = try parser .nodeGetChildNodes (body );
224- const ln = parser .nodeListLength (children );
225- for (0.. ln ) | _ | {
226- // always index 0, because nodeAppendChild moves the node out of
227- // the nodeList and into the new tree
228- const child = parser .nodeListItem (children , 0 ) orelse continue ;
220+ // always index 0, because nodeAppendChild moves the node out of
221+ // the nodeList and into the new tree
222+ while (parser .nodeListItem (children , 0 )) | child | {
229223 _ = try parser .nodeAppendChild (node , child );
230224 }
231225 }
0 commit comments