Skip to content

Commit 424b280

Browse files
committed
graph: Avoid cloning keys when building load_related candidate set
Hold borrowed `EntityKey` references in the candidate `BTreeSet` instead of cloning into owned keys. The keys borrow from `stored`, `self.updates`, and `self.handler_updates`, all of which outlive the candidate set.
1 parent 126d168 commit 424b280

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

graph/src/components/store/entity_cache.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,12 @@ impl EntityCache {
306306
// region are compatible with the query. The latter catches
307307
// entities an in-block write has moved into the matching set or
308308
// created fresh in this block.
309-
let mut candidates: BTreeSet<EntityKey> = stored.keys().cloned().collect();
309+
let mut candidates: BTreeSet<&EntityKey> = stored.keys().collect();
310310
for key in self.updates.keys().chain(self.handler_updates.keys()) {
311311
if key.entity_type == query.entity_type
312312
&& key.causality_region == query.causality_region
313313
{
314-
candidates.insert(key.clone());
314+
candidates.insert(key);
315315
}
316316
}
317317

@@ -320,17 +320,17 @@ impl EntityCache {
320320
// Resolve the entity's final in-block state by layering
321321
// store baseline, then self.updates, then self.handler_updates.
322322
// Each layer's op may mutate, replace, or remove the entity.
323-
let mut entity: Option<Entity> = stored.get(&key).cloned();
324-
if let Some(op) = self.updates.get(&key).cloned() {
323+
let mut entity: Option<Entity> = stored.get(key).cloned();
324+
if let Some(op) = self.updates.get(key).cloned() {
325325
entity = op.apply_to(&entity).map_err(|e| key.unknown_attribute(e))?;
326326
}
327-
if let Some(op) = self.handler_updates.get(&key).cloned() {
327+
if let Some(op) = self.handler_updates.get(key).cloned() {
328328
entity = op.apply_to(&entity).map_err(|e| key.unknown_attribute(e))?;
329329
}
330330

331331
// Include the entity only if its final state still matches the query.
332332
if let Some(entity) = entity
333-
&& query.matches(&key, &entity)
333+
&& query.matches(key, &entity)
334334
{
335335
result.push(entity);
336336
}

0 commit comments

Comments
 (0)