Skip to content

Commit

Permalink
Make a pyobject cache for Symbol.name
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Dec 23, 2023
1 parent 6645a70 commit 2cabb5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/rs/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct Symbol {
pub vrom: Option<u64>,

pub align: Option<u64>,

#[cfg(feature = "python_bindings")]
chached_name: Option<PyObject>,
}

impl Symbol {
Expand All @@ -35,6 +38,9 @@ impl Symbol {
size,
vrom,
align,

#[cfg(feature = "python_bindings")]
chached_name: None,
}
}

Expand All @@ -45,6 +51,9 @@ impl Symbol {
size: None,
vrom: None,
align: None,

#[cfg(feature = "python_bindings")]
chached_name: None,
}
}

Expand Down Expand Up @@ -136,12 +145,19 @@ pub(crate) mod python_bindings {
/* Getters and setters */

#[getter]
fn get_name(&self) -> PyResult<String> {
Ok(self.name.clone())
fn get_name(&mut self) -> PyObject {
Python::with_gil(|py| {
if self.chached_name.is_none() {
self.chached_name = Some(self.name.to_object(py));
}

self.chached_name.as_ref().unwrap().to_object(py)
})
}

#[setter]
fn set_name(&mut self, value: String) -> PyResult<()> {
self.chached_name = None;
self.name = value;
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions tests/check_progress_nonmatchings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def getProgress(mapPath: Path, version: str, pathIndex: int=2) -> tuple[mapfile_


cases: list[tuple[Path, str, mapfile_parser.ProgressStats]] = [
(Path("tests/maps/drmario64.cn.map"), "cn", mapfile_parser.ProgressStats(undecompedSize=273028, decompedSize=199196)),
(Path("tests/maps/drmario64.us.lld.map"), "us", mapfile_parser.ProgressStats(undecompedSize=170720, decompedSize=272764)),
(Path("tests/maps/drmario64.us.map"), "us", mapfile_parser.ProgressStats(undecompedSize=170720, decompedSize=272128)),
(Path("tests/maps/drmario64.cn.map"), "cn", mapfile_parser.ProgressStats(undecompedSize=273028, decompedSize=199196)),
(Path("tests/maps/drmario64.us.lld.map"), "us", mapfile_parser.ProgressStats(undecompedSize=170720, decompedSize=272764)),
(Path("tests/maps/drmario64.us.map"), "us", mapfile_parser.ProgressStats(undecompedSize=170720, decompedSize=272128)),
(Path("tests/maps/puzzleleague64.usa.map"), "usa", mapfile_parser.ProgressStats(undecompedSize=263668, decompedSize=454604)),
]

Expand Down

0 comments on commit 2cabb5e

Please sign in to comment.