perf: borrow dictionary string keys during equality checks
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user