Skip to content

Commit 6863f32

Browse files
committed
Improve performance & compliance of MIME parsing
Common cases, text/html, text/xml and text/plain parse about 2x faster. Other cases are about 30% faster. Support quoted attributes, i.e. charset="utf-8" & valid escape sequences. This potentially requires allocation, thus Mime.parse now takes an allocator. Stricter validation around type/subtype based on RFC. More tests. Replace Mime.eql with isHTML(). Equality is complicated and was previously incorrect (it was case sensitive, it should not be). Since we currently only use isHTML-like behavior, built a (faster) method specifically for that.
1 parent 0c1a486 commit 6863f32

File tree

4 files changed

+360
-119
lines changed

4 files changed

+360
-119
lines changed

src/browser/browser.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const Types = @import("root").Types;
2424
const parser = @import("netsurf");
2525
const Loader = @import("loader.zig").Loader;
2626
const Dump = @import("dump.zig");
27-
const Mime = @import("mime.zig");
27+
const Mime = @import("mime.zig").Mime;
2828

2929
const jsruntime = @import("jsruntime");
3030
const Loop = jsruntime.Loop;
@@ -376,7 +376,9 @@ pub const Page = struct {
376376

377377
log.debug("header content-type: {s}", .{ct.?});
378378
const mime = try Mime.parse(ct.?);
379-
if (mime.eql(Mime.HTML)) {
379+
defer mime.deinit();
380+
381+
if (mime.isHTML()) {
380382
try self.loadHTMLDoc(req.reader(), mime.charset orelse "utf-8", auxData);
381383
} else {
382384
log.info("non-HTML document: {s}", .{ct.?});

0 commit comments

Comments
 (0)