From 22c7aa339407042682eef78f7d1ae1398e1d9b79 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Fri, 24 Apr 2026 20:37:53 +0200 Subject: perf(lexer): replace nextKind by peek --- src/paragraph.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/paragraph.zig') diff --git a/src/paragraph.zig b/src/paragraph.zig index c8c6798..0e0f188 100644 --- a/src/paragraph.zig +++ b/src/paragraph.zig @@ -15,14 +15,14 @@ pub const Error = content.Error || link.Error || Lexer.Error || Allocator.Error; pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { var el = try Element.init(alloc, .content, "p"); errdefer el.deinit(); - while (l.nextKind()) |kind| { - switch (kind) { + while (l.peek()) |next| { + switch (next.kind) { // because nextKind returns only an hint for the next rune + .strong_delimiter => return el, .weak_delimiter => { - const v = l.next().?; - if (v.kind == .strong_delimiter) return el; - const next = l.nextKind() orelse return el; - switch (next) { + l.consume(); + const future = l.peek() orelse return el; + switch (future.kind) { .literal, .italic, .code, .bold, .link => try el.appendContent(try Element.initLit(alloc, " ")), else => return el, } @@ -36,8 +36,8 @@ pub fn parse(alloc: Allocator, l: *Lexer) Error!Element { pub fn parseLine(alloc: Allocator, l: *Lexer) Error!Element { var line = Element.initEmpty(alloc); errdefer line.deinit(); - while (l.nextKind()) |kind| { - switch (kind) { + while (l.peek()) |next| { + switch (next.kind) { .weak_delimiter, .strong_delimiter => return line, .link => { var el = try link.parse(alloc, l); -- cgit v1.2.3