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
+32
View File
@@ -5,6 +5,38 @@ use objects::{
Value, VmError,
};
#[test]
fn dictionary_text_and_managed_string_keys_share_entries_and_keep_first_identity() {
let mut store = ObjectStore::new().unwrap();
let dict = store.new_dict().unwrap();
for text in ["", "camera", "中文🙂"] {
let key = store.new_string(text).unwrap();
store
.dict_set(dict, Value::Object(key), Value::Bool(false))
.unwrap();
store
.dict_set(dict, Value::Text(text.into()), Value::Bool(true))
.unwrap();
assert_eq!(
store.dict_get_name(dict, text).unwrap(),
Some(Value::Bool(true))
);
assert_eq!(
store.dict_items(dict).unwrap().last().unwrap().0,
Value::Object(key)
);
assert_eq!(
store.dict_get(dict, &Value::Object(key)).unwrap(),
Some(Value::Bool(true))
);
store.release(key).unwrap();
assert!(store.dict_delete(dict, &Value::Text(text.into())).unwrap());
assert_eq!(store.dict_get_name(dict, text).unwrap(), None);
}
store.release(dict).unwrap();
assert_eq!(store.object_count(), 0);
}
#[test]
fn standalone_storage_preserves_identity_validates_edges_and_collects_cycles() {
let mut store = ObjectStore::new().unwrap();