From 113e6217d0524c75fa43b1f2f779784d729e463e Mon Sep 17 00:00:00 2001 From: Gareth Edwards Date: Fri, 11 Sep 2026 21:19:44 +1000 Subject: [PATCH] Compile the tag attribute regex once, not per tag [ai] CFMLStartTag.getAttributes ran Pattern.compile(REG_ATTRIBUTES, CASE_INSENSITIVE) on every call, i.e. for every tag with attributes in a scan. Hoisted to a static final field. Co-Authored-By: Claude Opus 5 --- .../src/main/java/cfml/parsing/cfmentat/tag/CFMLStartTag.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cfml.parsing/src/main/java/cfml/parsing/cfmentat/tag/CFMLStartTag.java b/cfml.parsing/src/main/java/cfml/parsing/cfmentat/tag/CFMLStartTag.java index 9c838f7..adb2f15 100644 --- a/cfml.parsing/src/main/java/cfml/parsing/cfmentat/tag/CFMLStartTag.java +++ b/cfml.parsing/src/main/java/cfml/parsing/cfmentat/tag/CFMLStartTag.java @@ -23,6 +23,8 @@ public AttributeItem(int linePos, int i, int inputPos, String attrName, String a } static protected final String REG_ATTRIBUTES = "(?si)(\\w+)[\\s=]+(((\\x22|\\x27|#)((?!\\4).|\\4{2})*\\4))"; + // Compiled once: getAttributes() runs for every tag with attributes in a scan. + static private final Pattern ATTRIBUTES_PATTERN = Pattern.compile(REG_ATTRIBUTES, Pattern.CASE_INSENSITIVE); private static CFMLStartTag INSTANCE = null; protected CFMLStartTag(final String description, final String startDelimiter, final String closingDelimiter, @@ -121,7 +123,7 @@ protected ArrayList getAttributes(String inData) { Matcher matcher; Pattern pattern; String attributeName, attributeValue; - pattern = Pattern.compile(REG_ATTRIBUTES, Pattern.CASE_INSENSITIVE); + pattern = ATTRIBUTES_PATTERN; matcher = pattern.matcher(inData); if (inData.trim().endsWith("&")) { userMessage(0, "stripAttributes", "Last attribute cannot be an ampersand", "ERR", null);