Skip to content

Commit

Permalink
merge exact and like argument comparison into one and improve "like" …
Browse files Browse the repository at this point in the history
…process.
  • Loading branch information
michaeloffner committed Dec 17, 2024
1 parent 05cdcc7 commit fa4e9da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
10 changes: 6 additions & 4 deletions core/src/main/java/lucee/runtime/reflection/Reflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,22 @@ public static boolean isInstaneOf(Class src, String trg) {
*
*/
public static boolean isInstaneOf(Class src, Class trg, boolean exatctMatch) {
if (exatctMatch) return trg.isAssignableFrom(src);

if (src.isArray() && trg.isArray()) {
return isInstaneOf(src.getComponentType(), trg.getComponentType(), exatctMatch);
return isInstaneOf(src.getComponentType(), trg.getComponentType(), false);
}

if (src == trg || (!exatctMatch && src.getName().equals(trg.getName()))) return true;
if (src == trg || (src.getName().equals(trg.getName()))) return true;

// Interface
if (trg.isInterface()) {
return _checkInterfaces(src, trg, exatctMatch);
return _checkInterfaces(src, trg, false);
}
// Extends

while (src != null) {
if (src == trg || (!exatctMatch && src.getName().equals(trg.getName()))) return true;
if (src == trg || (src.getName().equals(trg.getName()))) return true;
src = src.getSuperclass();
}
return trg == Object.class;
Expand Down
32 changes: 4 additions & 28 deletions core/src/main/java/lucee/transformer/dynamic/meta/Clazz.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,16 @@ public static Method getMethodMatch(Clazz clazz, final Collection.Key methodName

Reflector.checkAccessibility(clazz, methodName);

// exact comparsion
outer: for (Method m: methods) {
if (m != null) {
Class[] parameterTypes = m.getArgumentClasses();
for (int y = 0; y < parameterTypes.length; y++) {
if (Reflector.toReferenceClass(parameterTypes[y]) != clazzArgs[y]) continue outer;
}
return m;
}
}
// exact += (SystemUtil.millis() - start);
// start = SystemUtil.millis();

// like comparsion
outer: for (Method m: methods) {
if (m != null) {
Class[] parameterTypes = m.getArgumentClasses();
for (int y = 0; y < parameterTypes.length; y++) {
if (!Reflector.like(clazzArgs[y], Reflector.toReferenceClass(parameterTypes[y]))) continue outer;
if (!Reflector.toReferenceClass(parameterTypes[y]).isAssignableFrom(clazzArgs[y])) continue outer;
}
return m;
}
}
// like += (SystemUtil.millis() - start);
// start = SystemUtil.millis();

// cache
StringBuilder sb = new StringBuilder(100).append(clazz.id()).append(methodName).append(';');
Expand Down Expand Up @@ -290,27 +275,18 @@ public static Constructor getConstructorMatch(Clazz clazz, Object[] args, boolea
List<Constructor> constructors = clazz.getConstructors(args.length);
if (constructors != null && constructors.size() > 0) {
Class[] clazzArgs = Reflector.getClasses(args);
// exact comparsion
outer: for (Constructor c: constructors) {
if (c != null) {

Class[] parameterTypes = c.getArgumentClasses();
for (int y = 0; y < parameterTypes.length; y++) {
if (Reflector.toReferenceClass(parameterTypes[y]) != clazzArgs[y]) continue outer;
}
return c;
}
}
// like comparsion
outer: for (Constructor c: constructors) {
if (c != null) {

Class[] parameterTypes = c.getArgumentClasses();
for (int y = 0; y < parameterTypes.length; y++) {
if (!Reflector.like(clazzArgs[y], Reflector.toReferenceClass(parameterTypes[y]))) continue outer;
if (!Reflector.toReferenceClass(parameterTypes[y]).isAssignableFrom(clazzArgs[y])) continue outer;
}
return c;
}
}

// convert comparsion
Pair<Constructor, Object[]> result = null;
int _rating = 0;
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.2.0.224-SNAPSHOT"/>
<property name="version" value="6.2.0.225-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.2.0.224-SNAPSHOT</version>
<version>6.2.0.225-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit fa4e9da

Please sign in to comment.