perf: borrow dictionary string keys during equality checks

This commit is contained in:
2026-11-11 15:47:48 +08:00
parent f3e1670c58
commit fd247aca1f
2 changed files with 46 additions and 13 deletions
+14 -13
View File
@@ -196,19 +196,7 @@ impl ObjectStore {
}
fn key_equal(&self, left: &Value, right: &Value) -> Result<bool, VmError> {
let text = |value: &Value| -> Result<Option<String>, VmError> {
Ok(match value {
Value::Text(text) => Some(text.clone()),
Value::Object(reference) => self
.object(*reference)?
.payload()
.as_any()
.downcast_ref::<EndorStringObject>()
.map(|string| string.as_str().to_owned()),
_ => None,
})
};
if let (Some(left), Some(right)) = (text(left)?, text(right)?) {
if let (Some(left), Some(right)) = (self.key_text(left)?, self.key_text(right)?) {
return Ok(left == right);
}
match (left, right) {
@@ -219,6 +207,19 @@ impl ObjectStore {
}
}
fn key_text<'a>(&'a self, value: &'a Value) -> Result<Option<&'a str>, VmError> {
Ok(match value {
Value::Text(text) => Some(text.as_str()),
Value::Object(reference) => self
.object(*reference)?
.payload()
.as_any()
.downcast_ref::<EndorStringObject>()
.map(EndorStringObject::as_str),
_ => None,
})
}
pub fn new_cell(&mut self, value: Option<Value>) -> Result<ObjectRef, VmError> {
self.allocate(EndorCellObject::new(value))
}