mirror of https://github.com/astral-sh/ruff
[red-knot] Short-circuit bool calls on bool (#16292)
## Summary This avoids looking up `__bool__` on class `bool` for every `Type::Instance(bool).bool()` call. 1% performance win on cold cache, 4% win on incremental performance.
This commit is contained in:
parent
1be4394155
commit
f62e5406f2
|
|
@ -1452,7 +1452,9 @@ impl<'db> Type<'db> {
|
|||
Type::AlwaysTruthy => Truthiness::AlwaysTrue,
|
||||
Type::AlwaysFalsy => Truthiness::AlwaysFalse,
|
||||
instance_ty @ Type::Instance(InstanceType { class }) => {
|
||||
if class.is_known(db, KnownClass::NoneType) {
|
||||
if class.is_known(db, KnownClass::Bool) {
|
||||
Truthiness::Ambiguous
|
||||
} else if class.is_known(db, KnownClass::NoneType) {
|
||||
Truthiness::AlwaysFalse
|
||||
} else {
|
||||
// We only check the `__bool__` method for truth testing, even though at
|
||||
|
|
|
|||
Loading…
Reference in New Issue