mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-02 15:01:19 -05:00
Merge pull request #4961 from wanikhawar/perf/hashset-stacks-cull
perf(catalog,cull): look photo ids up in hash sets instead of lists
This commit is contained in:
@@ -132,11 +132,13 @@ impl Catalog {
|
||||
|
||||
/// Ops that dissolve every stack containing one of `photos`.
|
||||
pub fn ungroup_ops(&self, photos: &[PhotoId]) -> Vec<Op> {
|
||||
let photos: HashSet<PhotoId> = photos.iter().copied().collect();
|
||||
self.stacks.values().filter(|s| s.photos.iter().any(|p| photos.contains(p))).map(|s| Op::RemoveStack { id: s.id }).collect()
|
||||
}
|
||||
|
||||
/// Ops that take `photos` out of their stacks (a stack left with one photo is dissolved).
|
||||
pub fn remove_from_stacks_ops(&self, photos: &[PhotoId]) -> Vec<Op> {
|
||||
let photos: HashSet<PhotoId> = photos.iter().copied().collect();
|
||||
self.stacks
|
||||
.values()
|
||||
.filter(|s| s.photos.iter().any(|p| photos.contains(p)))
|
||||
|
||||
@@ -167,12 +167,13 @@ fn analyze(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
/// takes over, and the rest of the selection stays selected.
|
||||
fn keep_active_shown(s: &mut Session) {
|
||||
let vis = s.visible_cloned();
|
||||
let vis_set: std::collections::HashSet<PhotoId> = vis.iter().copied().collect();
|
||||
if let Some(a) = s.selection.active
|
||||
&& !vis.contains(&a)
|
||||
&& !vis_set.contains(&a)
|
||||
&& let Some(st) = s.catalog.stack_of(a)
|
||||
{
|
||||
let top = vis.iter().copied().find(|p| st.photos.contains(p)).unwrap_or(st.top());
|
||||
s.selection.ids.retain(|id| vis.contains(id));
|
||||
s.selection.ids.retain(|id| vis_set.contains(id));
|
||||
if !s.selection.ids.contains(&top) {
|
||||
s.selection.ids.push(top);
|
||||
}
|
||||
@@ -239,8 +240,9 @@ fn move_to_burst(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
old.entry(g).or_insert_with(|| index.get(&g).cloned().unwrap_or_default());
|
||||
}
|
||||
let mut new = old.clone();
|
||||
let moved: std::collections::HashSet<PhotoId> = ids.iter().copied().collect();
|
||||
for members in new.values_mut() {
|
||||
members.retain(|m| !ids.contains(m));
|
||||
members.retain(|m| !moved.contains(m));
|
||||
}
|
||||
if let Some(g) = target {
|
||||
let members = new.entry(g).or_default();
|
||||
|
||||
Reference in New Issue
Block a user