Hubert Law created AUTOTAG-24: ---------------------------------- Summary: Efficiency of regular expression under AbstractModelBody.evaluateAsString Key: AUTOTAG-24 URL: https://issues.apache.org/jira/browse/AUTOTAG-24 Project: Tiles Autotag Issue Type: Improvement Affects Versions: 1.2.0 Reporter: Hubert Law
Despite AUTOTAG-21 the regex still eats up CPU time due to the inefficiency of the pattern {{s*$}} which, in case of long consecutive white-space in the middle of the body, consumes O(n^2^) time while failing to match (since it will attempt to start matching at each white space position). Matching the actual non-whitespace content directly may be more efficient in this case, e.g {{private static final Pattern PATTERN = Pattern.compile("^\\s*(\\S(?:.*\\S)?)\\s*$");}} {{if (body != null) {}} {{ final Matcher matcher = PATTERN.matcher(body);}} {{ if (matcher.matches()) {}} {{ body = matcher.group(1);}} {{ } else {}} {{ body = null;}} {{ } }} {{}}} Backtracking is limited to the final white spaces, in linear time. -- This message was sent by Atlassian JIRA (v7.6.3#76005)