Made add in codegen faster

This commit is contained in:
2026-06-15 14:21:53 +02:00
parent 5f0b1fa67a
commit bed7b17134
3 changed files with 18 additions and 8 deletions
+1
View File
@@ -9,4 +9,5 @@ keywords = ["compiler", "language", "mist"]
categories = ["compilers"]
[dependencies]
bytecount = "0.6.9"
mist-parser = { workspace = true }
+10 -8
View File
@@ -50,15 +50,17 @@ impl RustCodegen {
}
fn add(&mut self, s: &str) {
for b in s.bytes() {
if b == b'\n' {
self.position.0 += 1;
self.position.1 = 0;
} else {
self.position.1 += 1;
}
let newline_count = bytecount::count(s.as_bytes(), b'\n');
if newline_count == 0 {
self.position.1 += s.len();
} else {
self.position.0 += newline_count;
let last_newline = s.rfind('\n').unwrap();
self.position.1 = s.len() - last_newline - 1;
}
self.output.push_str(s);
}