From b3d65fab9b444ed6f97685d56a1a2462e3c07359 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 9 Apr 2011 21:09:59 -0600 Subject: [PATCH] fix handling of interfaces in isAssignableFrom The old version was both incorrect (in the case where both arguments are interfaces) and inefficient. --- src/machine.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/machine.cpp b/src/machine.cpp index bc6d1bdf63..2f7f896e2f 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -3176,13 +3176,12 @@ isAssignableFrom(Thread* t, object a, object b) } } - for (; b; b = classSuper(t, b)) { - object itable = classInterfaceTable(t, b); - if (itable) { - for (unsigned i = 0; i < arrayLength(t, itable); i += 2) { - if (arrayBody(t, itable, i) == a) { - return true; - } + object itable = classInterfaceTable(t, b); + if (itable) { + unsigned stride = (classFlags(t, b) & ACC_INTERFACE) ? 1 : 2; + for (unsigned i = 0; i < arrayLength(t, itable); i += stride) { + if (arrayBody(t, itable, i) == a) { + return true; } } }