Commons Lang
  1. Commons Lang
  2. LANG-162

[lang] replace() length calculation improvement

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: Other

      Description

      static String replace(String text, String repl, String with, int max)

      PROBLEM:
      This method incurs the calculation of the search string ("repl") every time a
      match is found.

      int start = 0, end = 0;
      while ((end = text.indexOf(repl, start)) != -1)

      { buf.append(text.substring(start, end)).append(with); start = end + repl.length(); ... }

      PROPOSED SOLUTION:
      Move it out of the loop.

      int start = 0, end = 0, replLen = repl.length();
      while ((end = text.indexOf(repl, start)) != -1)

      { buf.append(text.substring(start, end)).append(with); start = end + replLen; ... }

        Activity

        Mark Thomas made changes -
        Workflow jira [ 12371942 ] Default workflow, editable Closed status [ 12602192 ]
        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Henri Yandell made changes -
        Fix Version/s 2.2 [ 12311702 ]
        Henri Yandell made changes -
        Affects Version/s 2.1 Final [ 12311701 ]
        Henri Yandell made changes -
        Project Commons [ 12310458 ] Commons Lang [ 12310481 ]
        Fix Version/s 2.2 [ 12311686 ]
        Component/s Lang [ 12311121 ]
        Affects Version/s 2.1 Final [ 12311659 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Key COM-2885 LANG-162
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 39368 12343037
        Paul Benedict created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul Benedict
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development