Skip to content

Commit 3c4092b

Browse files
authored
Fix cache issue when parsing the same file with different side params (#341)
1 parent 0f599be commit 3c4092b

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

objdiff-wasm/src/api.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl GuestDiffConfig for ResourceDiffConfig {
572572
}
573573
}
574574

575-
struct CachedObject(Weak<obj::Object>, u64);
575+
struct CachedObject(Weak<obj::Object>, u64, diff::DiffSide);
576576

577577
struct ObjectCache(RefCell<Vec<CachedObject>>);
578578

@@ -608,12 +608,13 @@ impl GuestObject for ResourceObject {
608608
diff_side: DiffSide,
609609
) -> Result<Object, String> {
610610
let hash = xxh3_64(&data);
611+
let core_diff_side: objdiff_core::diff::DiffSide = diff_side.into();
611612
let mut cached = None;
612613
OBJECT_CACHE.borrow_mut().retain(|c| {
613614
if c.0.strong_count() == 0 {
614615
return false;
615616
}
616-
if c.1 == hash {
617+
if c.1 == hash && c.2 == core_diff_side {
617618
cached = c.0.upgrade();
618619
}
619620
true
@@ -623,9 +624,9 @@ impl GuestObject for ResourceObject {
623624
}
624625
let diff_config = diff_config.get::<ResourceDiffConfig>().0.borrow();
625626
let obj = Rc::new(
626-
obj::read::parse(&data, &diff_config, diff_side.into()).map_err(|e| e.to_string())?,
627+
obj::read::parse(&data, &diff_config, core_diff_side).map_err(|e| e.to_string())?,
627628
);
628-
OBJECT_CACHE.borrow_mut().push(CachedObject(Rc::downgrade(&obj), hash));
629+
OBJECT_CACHE.borrow_mut().push(CachedObject(Rc::downgrade(&obj), hash, core_diff_side));
629630
Ok(Object::new(ResourceObject(obj, hash)))
630631
}
631632

0 commit comments

Comments
 (0)