Less memory allocations at runtime

This commit is contained in:
2026-02-02 21:55:10 +01:00
parent 194030d953
commit 8024c18bb0
9 changed files with 146 additions and 457 deletions

View File

@@ -1,5 +1,5 @@
use std::collections::HashMap;
use std::sync::LazyLock;
use std::sync::{Arc, LazyLock};
use super::ops::Op;
use super::theory;
@@ -3031,7 +3031,7 @@ pub(super) fn compile_word(
// @varname - fetch variable
if let Some(var_name) = name.strip_prefix('@') {
if !var_name.is_empty() {
ops.push(Op::PushStr(var_name.to_string(), span));
ops.push(Op::PushStr(Arc::from(var_name), span));
ops.push(Op::Get);
return true;
}
@@ -3040,7 +3040,7 @@ pub(super) fn compile_word(
// !varname - store into variable
if let Some(var_name) = name.strip_prefix('!') {
if !var_name.is_empty() {
ops.push(Op::PushStr(var_name.to_string(), span));
ops.push(Op::PushStr(Arc::from(var_name), span));
ops.push(Op::Set);
return true;
}
@@ -3073,6 +3073,6 @@ pub(super) fn compile_word(
}
// Unrecognized token becomes a string
ops.push(Op::PushStr(name.to_string(), span));
ops.push(Op::PushStr(Arc::from(name), span));
true
}