mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-10 10:31:29 -10:00
Stats screen: look item registry ids up once per sort, not per row
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
7bd4244e2f
commit
8396106b2e
1 file changed
+11
-2
@@ -329,9 +329,18 @@ impl Game<'_> {
|
||||
});
|
||||
if let Some((col, order)) = self.stats_ui.sort {
|
||||
let ty = COLUMNS[col].0;
|
||||
let ids = &self.res.items().registry_order;
|
||||
// `Item.getId`: one pass over the registry, not a scan per row
|
||||
// (the screen asks for its rows several times a frame).
|
||||
let ids: std::collections::HashMap<&str, usize> = self
|
||||
.res
|
||||
.items()
|
||||
.registry_order
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(n, id)| (&**id, n))
|
||||
.collect();
|
||||
sort_rows(&mut items, order, |i| {
|
||||
let id = ids.iter().position(|x| **x == *i).unwrap_or(usize::MAX);
|
||||
let id = ids.get(i).copied().unwrap_or(usize::MAX);
|
||||
(self.stat_item(ty, i).unwrap_or(-1), id)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user