Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-3531

Multiple replace function call can be replaced with a single for loop to improve performance

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Won't Fix
    • 1.4.9
    • None
    • site
    • None

    Description

      ./apache-wicket-1.4.9/src/wicket/src/main/java/org/apache/wicket/Component.java   line: 1562
      ./apache-wicket-1.4.9/src/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/DiskPageStore.java   line: 410
      

      more than 3 consecutive replace() is called to remove the special characters. It's 3+ times slower than using a for loop replace them all.

      e.g.
       - str.replace('a', '#');
       - str.replace('b', '%');
      
       + StringBuilder sb = new StringBuilder( str.length() );
       + for (int i=0; i < str.length(); i++)
       +  {
       +           char c = str.charAt(i);
       +         if ( c == 'a' )
       +               sb.append('#');
       +       else if ( c== 'b' )
       +               sb.append('%');
       +       else 
       +              sb.append(c); 
       +  }
       +  str  = sb.toString();
      

      This bug has the same problem as the MySQL bug : http://bugs.mysql.com/bug.php?id=45699

      Attachments

        1. test.java
          1 kB
          Bruno Borges

        Activity

          People

            ivaynberg Igor Vaynberg
            nancyesmis Xiaoming Shi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: