Browse Source

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
master
Matthew Jason Benson 15 years ago
parent
commit
3628209a35
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      src/main/org/apache/tools/ant/PropertyHelper.java

+ 9
- 5
src/main/org/apache/tools/ant/PropertyHelper.java View File

@@ -188,14 +188,18 @@ public class PropertyHelper implements GetProperty {
public String parsePropertyName( public String parsePropertyName(
String s, ParsePosition pos, ParseNextProperty notUsed) { String s, ParsePosition pos, ParseNextProperty notUsed) {
int index = pos.getIndex(); 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) { 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); pos.setIndex(end + 1);
return s.substring(start, end);
return start == end ? "" : s.substring(start, end);
} }
return null; return null;
} }


Loading…
Cancel
Save