mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Eliminate unneeded clones in find_or_create
...and use it to eliminate duplicate hash lookups and string copies in shape_text.
This commit is contained in:
parent
1c5ec6f3ec
commit
d2717c4475
3 changed files with 34 additions and 41 deletions
|
@ -13,7 +13,7 @@ fn test_hashcache() {
|
|||
assert!(cache.find(&1).is_some());
|
||||
assert!(cache.find(&2).is_none());
|
||||
|
||||
cache.find_or_create(&2, |_v| { Cell::new("two") });
|
||||
cache.find_or_create(2, || { Cell::new("two") });
|
||||
assert!(cache.find(&1).is_some());
|
||||
assert!(cache.find(&2).is_some());
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ fn test_lru_cache() {
|
|||
assert!(cache.find(&4).is_some()); // (2, 4) (no change)
|
||||
|
||||
// Test find_or_create.
|
||||
cache.find_or_create(&1, |_| { Cell::new("one") }); // (4, 1)
|
||||
cache.find_or_create(1, || { Cell::new("one") }); // (4, 1)
|
||||
|
||||
assert!(cache.find(&1).is_some()); // (4, 1) (no change)
|
||||
assert!(cache.find(&2).is_none()); // (4, 1) (no change)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue