Skip to content

Commit 4ea01f8

Browse files
authored
fixes inifinte loop in ClassEntry::instance_of (#188)
1 parent 3b1e2e3 commit 4ea01f8

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

src/zend/class.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,19 @@ impl ClassEntry {
3737
///
3838
/// # Parameters
3939
///
40-
/// * `ce` - The inherited class entry to check.
41-
pub fn instance_of(&self, ce: &ClassEntry) -> bool {
42-
if self == ce {
40+
/// * `other` - The inherited class entry to check.
41+
pub fn instance_of(&self, other: &ClassEntry) -> bool {
42+
if self == other {
4343
return true;
4444
}
4545

46-
if ce.flags().contains(ClassFlags::Interface) {
47-
let interfaces = match self.interfaces() {
48-
Some(interfaces) => interfaces,
49-
None => return false,
50-
};
51-
52-
for i in interfaces {
53-
if ce == i {
54-
return true;
55-
}
56-
}
57-
} else {
58-
loop {
59-
let parent = match self.parent() {
60-
Some(parent) => parent,
61-
None => return false,
62-
};
63-
64-
if parent == ce {
65-
return true;
66-
}
67-
}
46+
if other.is_interface() {
47+
return self
48+
.interfaces()
49+
.map_or(false, |mut it| it.any(|ce| ce == other));
6850
}
6951

70-
false
52+
std::iter::successors(self.parent(), |p| p.parent()).any(|ce| ce == other)
7153
}
7254

7355
/// Returns an iterator of all the interfaces that the class implements.

0 commit comments

Comments
 (0)