mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-12 05:27:07 +00:00
Simplify logic for guaranteeing stable sort order of references
This commit is contained in:
parent
1a4bd3ab2e
commit
4191e3adee
1 changed files with 8 additions and 7 deletions
|
@ -328,9 +328,11 @@ impl KeyPathReferenceSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root_ids.sort_by_key(|id| &self.references[*id]);
|
|
||||||
|
|
||||||
while results.len() < root_ids.len() {
|
while results.len() < root_ids.len() {
|
||||||
|
// Just to guarantee a stable result when the inputs are randomized,
|
||||||
|
// sort references lexicographically in absence of any dependency relationship.
|
||||||
|
root_ids[results.len()..].sort_by_key(|id| &self.references[*id]);
|
||||||
|
|
||||||
let root_id = root_ids[results.len()];
|
let root_id = root_ids[results.len()];
|
||||||
let root = mem::take(&mut self.references[root_id]);
|
let root = mem::take(&mut self.references[root_id]);
|
||||||
results.push(root);
|
results.push(root);
|
||||||
|
@ -356,13 +358,9 @@ impl KeyPathReferenceSet {
|
||||||
for (_, successor_id) in self.dependencies.drain(first_dep_ix..last_dep_ix) {
|
for (_, successor_id) in self.dependencies.drain(first_dep_ix..last_dep_ix) {
|
||||||
self.dependency_counts[successor_id] -= 1;
|
self.dependency_counts[successor_id] -= 1;
|
||||||
if self.dependency_counts[successor_id] == 0 {
|
if self.dependency_counts[successor_id] == 0 {
|
||||||
if let Err(ix) = root_ids[results.len()..].binary_search(&successor_id) {
|
root_ids.push(successor_id);
|
||||||
root_ids.insert(results.len() + ix, successor_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
root_ids[results.len()..].sort_by_key(|id| &self.references[*id]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,6 +897,9 @@ mod tests {
|
||||||
("n.d.e", "f"),
|
("n.d.e", "f"),
|
||||||
("a.b.c", "n.d"),
|
("a.b.c", "n.d"),
|
||||||
("r", "a"),
|
("r", "a"),
|
||||||
|
("q.q.q", "r.s"),
|
||||||
|
("r.t", "q"),
|
||||||
|
("x.x", "r.r"),
|
||||||
("v.w", "x"),
|
("v.w", "x"),
|
||||||
("v.y", "x"),
|
("v.y", "x"),
|
||||||
("v.z", "x"),
|
("v.z", "x"),
|
||||||
|
|
Loading…
Reference in a new issue