mirror of
https://github.com/encounter/objdiff.git
synced 2026-07-10 12:18:36 -07:00
Fix cache issue when parsing the same file with different side params (#341)
This commit is contained in:
@@ -572,7 +572,7 @@ impl GuestDiffConfig for ResourceDiffConfig {
|
||||
}
|
||||
}
|
||||
|
||||
struct CachedObject(Weak<obj::Object>, u64);
|
||||
struct CachedObject(Weak<obj::Object>, u64, diff::DiffSide);
|
||||
|
||||
struct ObjectCache(RefCell<Vec<CachedObject>>);
|
||||
|
||||
@@ -608,12 +608,13 @@ impl GuestObject for ResourceObject {
|
||||
diff_side: DiffSide,
|
||||
) -> Result<Object, String> {
|
||||
let hash = xxh3_64(&data);
|
||||
let core_diff_side: objdiff_core::diff::DiffSide = diff_side.into();
|
||||
let mut cached = None;
|
||||
OBJECT_CACHE.borrow_mut().retain(|c| {
|
||||
if c.0.strong_count() == 0 {
|
||||
return false;
|
||||
}
|
||||
if c.1 == hash {
|
||||
if c.1 == hash && c.2 == core_diff_side {
|
||||
cached = c.0.upgrade();
|
||||
}
|
||||
true
|
||||
@@ -623,9 +624,9 @@ impl GuestObject for ResourceObject {
|
||||
}
|
||||
let diff_config = diff_config.get::<ResourceDiffConfig>().0.borrow();
|
||||
let obj = Rc::new(
|
||||
obj::read::parse(&data, &diff_config, diff_side.into()).map_err(|e| e.to_string())?,
|
||||
obj::read::parse(&data, &diff_config, core_diff_side).map_err(|e| e.to_string())?,
|
||||
);
|
||||
OBJECT_CACHE.borrow_mut().push(CachedObject(Rc::downgrade(&obj), hash));
|
||||
OBJECT_CACHE.borrow_mut().push(CachedObject(Rc::downgrade(&obj), hash, core_diff_side));
|
||||
Ok(Object::new(ResourceObject(obj, hash)))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user