Skip to content

Commit

Permalink
LDEV-5203 optimize checkPrimaryTypes matching
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitzer committed Dec 19, 2024
1 parent fc4dd1b commit ed711a6
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions core/src/main/java/lucee/commons/lang/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ public static Class toClass(PageContext pc, String className) throws ClassExcept
}

private static Class checkPrimaryTypesBytecodeDef(String className, Class defaultValue) {
if (className.charAt(0) == '[') {
if (className.equals("[V")) return void.class;
if (className.equals("[Z")) return boolean.class;
if (className.equals("[B")) return byte.class;
if (className.equals("[I")) return int.class;
if (className.equals("[J")) return long.class;
if (className.equals("[F")) return float.class;
if (className.equals("[D")) return double.class;
if (className.equals("[C")) return char.class;
if (className.equals("[S")) return short.class;
if (className.length() == 2 && className.charAt(0) == '[') {
char pt = className.charAt(1);
if (pt == 'V') return void.class;
if (pt == 'Z') return boolean.class;
if (pt == 'B') return byte.class;
if (pt == 'I') return int.class;
if (pt == 'J') return long.class;
if (pt == 'F') return float.class;
if (pt == 'D') return double.class;
if (pt == 'C') return char.class;
if (pt == 'S') return short.class;
}
return defaultValue;
}
Expand All @@ -98,6 +99,8 @@ private static Class checkPrimaryTypes(String className, Class defaultValue) {
isRef = true;
}

if (lcClassName.length() > 9) return defaultValue; // short circuit longest below match is "character"

if (lcClassName.equals("void")) {
return void.class;
}
Expand Down

0 comments on commit ed711a6

Please sign in to comment.