private static Method findMethod(ObjArray methods, Symbol name, Symbol signature) { int len = (int) methods.getLength(); // methods are sorted, so do binary search int l = 0; int h = len - 1; while (l <= h) { int mid = (l + h) >> 1; Method m = (Method) methods.getObjAt(mid); int res = m.getName().fastCompare(name); if (res == 0) { // found matching name; do linear search to find matching signature // first, quick check for common case if (m.getSignature().equals(signature)) return m; // search downwards through overloaded methods int i; for (i = mid - 1; i >= l; i--) { Method m1 = (Method) methods.getObjAt(i); if (!m1.getName().equals(name)) break; if (m1.getSignature().equals(signature)) return m1; } // search upwards for (i = mid + 1; i <= h; i++) { Method m1 = (Method) methods.getObjAt(i); if (!m1.getName().equals(name)) break; if (m1.getSignature().equals(signature)) return m1; } // not found if (Assert.ASSERTS_ENABLED) { int index = linearSearch(methods, name, signature); if (index != -1) { throw new DebuggerException("binary search bug: should have found entry " + index); } } return null; } else if (res < 0) { l = mid + 1; } else { h = mid - 1; } } if (Assert.ASSERTS_ENABLED) { int index = linearSearch(methods, name, signature); if (index != -1) { throw new DebuggerException("binary search bug: should have found entry " + index); } } return null; }
private static int linearSearch(ObjArray methods, Symbol name, Symbol signature) { int len = (int) methods.getLength(); for (int index = 0; index < len; index++) { Method m = (Method) methods.getObjAt(index); if (m.getSignature().equals(signature) && m.getName().equals(name)) { return index; } } return -1; }