From e7fa254387e450154f03b2d1bdef361a0adb80d1 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 24 Apr 2026 17:40:33 +0200 Subject: perf(lexer): do not alloc --- src/title.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/title.zig') diff --git a/src/title.zig b/src/title.zig index 352460f..c7845c6 100644 --- a/src/title.zig +++ b/src/title.zig @@ -1,6 +1,6 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const Lexed = @import("lexer/Lexed.zig"); +const Token = @import("lexer/Token.zig"); const Lexer = @import("lexer/Lexer.zig"); const Element = @import("dom/Element.zig"); const paragraph = @import("paragraph.zig"); @@ -11,9 +11,8 @@ const doTestError = testing.doError; pub const Error = error{InvalidTitleContent} || paragraph.Error || Lexer.Error; pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { - var v = (try l.next(alloc)).?; - defer v.deinit(); - var el = try Element.init(alloc, .content, switch (v.content.items.len) { + const v = l.next().?; + var el = try Element.init(alloc, .content, switch (v.content.len) { 1 => "h1", 2 => "h2", 3 => "h3", @@ -27,8 +26,7 @@ pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { paragraph.Error.IllegalPlacement => return Error.InvalidTitleContent, else => return err, }); - var next = (try l.next(alloc)) orelse return el; - defer next.deinit(); + var next = l.next() orelse return el; if (!next.kind.isDelimiter()) return Error.InvalidTitleContent; return el; } -- cgit v1.2.3