Minor optimizations.
authorJesse Glick <jglick@netbeans.org>
Mon, 10 Aug 2009 14:36:37 -0400
changeset 816a608b762794e
parent 815 fae825a66188
child 817 fb3f7efc8c45
Minor optimizations.
openide.util/src/org/openide/util/EditableProperties.java
     1.1 --- a/openide.util/src/org/openide/util/EditableProperties.java	Fri Aug 07 16:56:20 2009 -0400
     1.2 +++ b/openide.util/src/org/openide/util/EditableProperties.java	Mon Aug 10 14:36:37 2009 -0400
     1.3 @@ -92,14 +92,6 @@
     1.4  
     1.5      private final boolean alphabetize;
     1.6      
     1.7 -    private static final String keyValueSeparators = "=: \t\r\n\f";
     1.8 -
     1.9 -    private static final String strictKeyValueSeparators = "=:";
    1.10 -
    1.11 -    private static final String whiteSpaceChars = " \t\r\n\f";
    1.12 -
    1.13 -    private static final String commentChars = "#!";
    1.14 -    
    1.15      private static final String INDENT = "    ";
    1.16  
    1.17      // parse states:
    1.18 @@ -402,11 +394,14 @@
    1.19      // does line start with comment delimiter? (whitespaces are ignored)
    1.20      private static boolean isComment(String line) {
    1.21          line = trimLeft(line);
    1.22 -        if (line.length() != 0 && commentChars.indexOf(line.charAt(0)) != -1) {
    1.23 -            return true;
    1.24 -        } else {
    1.25 -            return false;
    1.26 +        if (line.length() > 0) {
    1.27 +            switch (line.charAt(0)) {
    1.28 +            case '#':
    1.29 +            case '!':
    1.30 +                return true;
    1.31 +            }
    1.32          }
    1.33 +        return false;
    1.34      }
    1.35  
    1.36      // is line empty? (whitespaces are ignored)
    1.37 @@ -417,11 +412,19 @@
    1.38      // remove all whitespaces from left
    1.39      private static String trimLeft(String line) {
    1.40          int start = 0;
    1.41 -        while (start < line.length()) {
    1.42 -            if (whiteSpaceChars.indexOf(line.charAt(start)) == -1) {
    1.43 +        int len = line.length();
    1.44 +        NONWS: while (start < len) {
    1.45 +            switch (line.charAt(start)) {
    1.46 +            case ' ':
    1.47 +            case '\t':
    1.48 +            case '\r':
    1.49 +            case '\n':
    1.50 +            case '\f':
    1.51 +                start++;
    1.52                  break;
    1.53 +            default:
    1.54 +                break NONWS;
    1.55              }
    1.56 -            start++;
    1.57          }
    1.58          return line.substring(start);
    1.59      }
    1.60 @@ -576,6 +579,9 @@
    1.61          }
    1.62          
    1.63          private String mergeLines(List<String> lines) {
    1.64 +            if (lines.size() == 1) {
    1.65 +                return trimLeft(lines.get(0));
    1.66 +            }
    1.67              StringBuilder line = new StringBuilder();
    1.68              Iterator<String> it = lines.iterator();
    1.69              while (it.hasNext()) {
    1.70 @@ -592,14 +598,22 @@
    1.71          
    1.72          private void splitKeyValue(String line) {
    1.73              int separatorIndex = 0;
    1.74 -            while (separatorIndex < line.length()) {
    1.75 +            int len = line.length();
    1.76 +            POS: while (separatorIndex < len) {
    1.77                  char ch = line.charAt(separatorIndex);
    1.78                  if (ch == '\\') {
    1.79                      // ignore next one character
    1.80                      separatorIndex++;
    1.81                  } else {
    1.82 -                    if (keyValueSeparators.indexOf(ch) != -1) {
    1.83 -                        break;
    1.84 +                    switch (ch) {
    1.85 +                    case '=':
    1.86 +                    case ':':
    1.87 +                    case ' ':
    1.88 +                    case '\t':
    1.89 +                    case '\r':
    1.90 +                    case '\n':
    1.91 +                    case '\f':
    1.92 +                        break POS;
    1.93                      }
    1.94                  }
    1.95                  separatorIndex++;
    1.96 @@ -610,7 +624,9 @@
    1.97                  value = "";
    1.98                  return;
    1.99              }
   1.100 -            if (strictKeyValueSeparators.indexOf(line.charAt(0)) != -1) {
   1.101 +            switch (line.charAt(0)) {
   1.102 +            case '=':
   1.103 +            case ':':
   1.104                  line = trimLeft(line.substring(1));
   1.105              }
   1.106              value = decode(line);