Skip to content

Commit 54f9bfb

Browse files
authored
Merge pull request #1099 from lightpanda-io/nikneym/qol-changes
Small changes
2 parents 489ba13 + b9024ab commit 54f9bfb

File tree

2 files changed

+24
-39
lines changed

2 files changed

+24
-39
lines changed

src/browser/dom/element.zig

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/browser/netsurf.zig

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,31 +2500,22 @@ fn parseParams(enc: ?[:0]const u8) c.dom_hubbub_parser_params {
25002500
}
25012501

25022502
fn parseData(parser: *c.dom_hubbub_parser, reader: anytype) !void {
2503-
var err: c.hubbub_error = undefined;
2504-
const TI = @typeInfo(@TypeOf(reader));
2505-
if (TI == .pointer and @hasDecl(TI.pointer.child, "next")) {
2506-
while (try reader.next()) |data| {
2507-
err = c.dom_hubbub_parser_parse_chunk(parser, data.ptr, data.len);
2508-
try parserErr(err);
2509-
}
2510-
} else {
2511-
var buffer: [1024]u8 = undefined;
2512-
var ln = buffer.len;
2513-
while (ln > 0) {
2514-
ln = try reader.read(&buffer);
2515-
err = c.dom_hubbub_parser_parse_chunk(parser, &buffer, ln);
2516-
// TODO handle encoding change error return.
2517-
// When the HTML contains a META tag with a different encoding than the
2518-
// original one, a c.DOM_HUBBUB_HUBBUB_ERR_ENCODINGCHANGE error is
2519-
// returned.
2520-
// In this case, we must restart the parsing with the new detected
2521-
// encoding. The detected encoding is stored in the document and we can
2522-
// get it with documentGetInputEncoding().
2523-
try parserErr(err);
2524-
}
2503+
var buffer: [1024]u8 = undefined;
2504+
var ln = buffer.len;
2505+
while (ln > 0) {
2506+
ln = try reader.read(&buffer);
2507+
const err = c.dom_hubbub_parser_parse_chunk(parser, &buffer, ln);
2508+
// TODO handle encoding change error return.
2509+
// When the HTML contains a META tag with a different encoding than the
2510+
// original one, a c.DOM_HUBBUB_HUBBUB_ERR_ENCODINGCHANGE error is
2511+
// returned.
2512+
// In this case, we must restart the parsing with the new detected
2513+
// encoding. The detected encoding is stored in the document and we can
2514+
// get it with documentGetInputEncoding().
2515+
try parserErr(err);
25252516
}
2526-
err = c.dom_hubbub_parser_completed(parser);
2527-
try parserErr(err);
2517+
const err = c.dom_hubbub_parser_completed(parser);
2518+
return parserErr(err);
25282519
}
25292520

25302521
// documentHTMLClose closes the document.

0 commit comments

Comments
 (0)