From ed711a668910160509fd9c7f4e6f4fc08b436aeb Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Thu, 19 Dec 2024 17:57:25 +0100 Subject: [PATCH] LDEV-5203 optimize checkPrimaryTypes matching https://luceeserver.atlassian.net/browse/LDEV-5203 --- .../java/lucee/commons/lang/ClassUtil.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/lucee/commons/lang/ClassUtil.java b/core/src/main/java/lucee/commons/lang/ClassUtil.java index 8e4354f6f4..bc1cf1b71c 100644 --- a/core/src/main/java/lucee/commons/lang/ClassUtil.java +++ b/core/src/main/java/lucee/commons/lang/ClassUtil.java @@ -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; } @@ -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; }