Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-604

Optimize isBlank() for untrimmed strings

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: 3.0
    • Fix Version/s: None
    • Component/s: lang.*
    • Labels:
      None

      Description

      Change isBlank() to start iteration in the middle of the String.
      So you get better performance for untrimmed Strings like " dummy ".

      Here is my proposal:

      public static boolean isBlank(CharSequence cs) {
      int strLen;
      if (cs == null || (strLen = cs.length()) == 0)

      { return true; }

      int mid = strLen / 2, i = mid;
      for (; i < strLen; i++) {
      if (!Character.isWhitespace(cs.charAt))

      { return false; }
      }
      for (i = 0; i < mid; i++) {
      if (!Character.isWhitespace(cs.charAt)) { return false; }

      }
      return true;
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kguelzau Kai G├╝lzau
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: