optimize: dedup consts
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use derive_more::{IsVariant, Unwrap};
|
||||
use ecow::EcoString;
|
||||
|
||||
@@ -7,6 +9,20 @@ pub enum Const {
|
||||
Int(i64),
|
||||
Float(f64),
|
||||
String(EcoString),
|
||||
Null
|
||||
}
|
||||
|
||||
impl Hash for Const {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
use Const::*;
|
||||
match self {
|
||||
Int(x) => x.hash(state),
|
||||
Float(x) => x.to_bits().hash(state),
|
||||
Bool(x) => x.hash(state),
|
||||
String(x) => x.hash(state),
|
||||
x @ Null => x.hash(state),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for Const {
|
||||
|
||||
@@ -89,7 +89,7 @@ impl<'vm> Func<'vm> {
|
||||
}
|
||||
}
|
||||
|
||||
vm.eval(self.func.opcodes.clone(), env)
|
||||
vm.eval(self.func.opcodes.iter().copied(), env)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ impl<'vm> Thunk<'vm> {
|
||||
_Thunk::SuspendedFrom(self as *const Thunk),
|
||||
)
|
||||
.unwrap_code();
|
||||
let value = vm.eval(opcodes.clone(), env.get().unwrap().clone())?;
|
||||
let value = vm.eval(opcodes.iter().copied(), env.get().unwrap().clone())?;
|
||||
let _ = std::mem::replace(
|
||||
&mut *self.thunk.borrow_mut(),
|
||||
_Thunk::Value(value.clone().into()),
|
||||
|
||||
Reference in New Issue
Block a user