mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Improve performance of subtyping and assignability checks for protocols (#19824)
This commit is contained in:
parent
fc72ff4a94
commit
fd35435281
1 changed files with 8 additions and 5 deletions
|
@ -47,16 +47,19 @@ impl<T: Hash + Eq + Copy, R: Copy> CycleDetector<T, R> {
|
|||
}
|
||||
|
||||
pub(crate) fn visit(&mut self, item: T, func: impl FnOnce(&mut Self) -> R) -> R {
|
||||
if let Some(ty) = self.cache.get(&item) {
|
||||
return *ty;
|
||||
}
|
||||
|
||||
// We hit a cycle
|
||||
if !self.seen.insert(item) {
|
||||
return self.fallback;
|
||||
}
|
||||
if let Some(ty) = self.cache.get(&item) {
|
||||
self.seen.pop();
|
||||
return *ty;
|
||||
}
|
||||
|
||||
let ret = func(self);
|
||||
self.cache.insert(item, ret);
|
||||
self.seen.pop();
|
||||
self.cache.insert(item, ret);
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue