From 3628209a35e131e6fccc47532908925b2a5ec9ab Mon Sep 17 00:00:00 2001 From: Matthew Jason Benson Date: Fri, 9 Apr 2010 20:37:46 +0000 Subject: [PATCH] problems 49079, 48961 Address indexOf inefficiency in PropertyHelper default propertyexpander implementation. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@932588 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/PropertyHelper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/org/apache/tools/ant/PropertyHelper.java b/src/main/org/apache/tools/ant/PropertyHelper.java index 422891575..924bdfdab 100644 --- a/src/main/org/apache/tools/ant/PropertyHelper.java +++ b/src/main/org/apache/tools/ant/PropertyHelper.java @@ -188,14 +188,18 @@ public class PropertyHelper implements GetProperty { public String parsePropertyName( String s, ParsePosition pos, ParseNextProperty notUsed) { int index = pos.getIndex(); - if (s.indexOf("${", index) == index) { - int end = s.indexOf('}', index); + //directly check near, triggering characters: + if (s.length() - index >= 3 + && '$' == s.charAt(index) && '{' == s.charAt(index + 1)) { + int start = index + 2; + //defer to String.indexOf() for protracted check: + int end = s.indexOf('}', start); if (end < 0) { - throw new BuildException("Syntax error in property: " + s); + throw new BuildException("Syntax error in property: " + + s.substring(index)); } - int start = index + 2; pos.setIndex(end + 1); - return s.substring(start, end); + return start == end ? "" : s.substring(start, end); } return null; }