perf: 字符串拼接消除冗余拷贝

This commit is contained in:
爱特每羊队
2026-06-30 21:49:41 +08:00
parent 7291fb237e
commit 66144929eb
+6 -4
View File
@@ -20,8 +20,9 @@ impl Vm {
buf.clear();
coercion::push_to_string(lhs, &mut buf);
coercion::push_to_string(rhs, &mut buf);
self.regs[rd] = self.new_string(&buf);
self.string_buf = buf;
let result = self.new_string_owned(buf);
self.string_buf = String::new();
self.regs[rd] = result;
} else {
let ln = coercion::to_number(lhs);
let rn = coercion::to_number(rhs);
@@ -61,8 +62,9 @@ impl Vm {
buf.clear();
coercion::push_to_string(lhs, &mut buf);
coercion::push_to_string(rhs, &mut buf);
self.regs[rd] = self.new_string(&buf);
self.string_buf = buf;
let result = self.new_string_owned(buf);
self.string_buf = String::new();
self.regs[rd] = result;
} else {
let ln = coercion::to_number(lhs);
let rn = coercion::to_number(rhs);