You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lenya.apache.org by bu...@apache.org on 2011/03/13 04:22:47 UTC
DO NOT REPLY [Bug 50921] New: Multiple replace function call can be
replaced with a single for loop to improve performance
https://issues.apache.org/bugzilla/show_bug.cgi?id=50921
Summary: Multiple replace function call can be replaced with a
single for loop to improve performance
Product: Lenya
Version: 2.0.3
Platform: PC
Status: NEW
Severity: normal
Priority: P2
Component: Miscellaneous
AssignedTo: dev@lenya.apache.org
ReportedBy: xiaoming@cs.wisc.edu
./apache-lenya-2.0.3-src/externals/cocoon_2_1_x/src/java/org/apache/cocoon/bean/Target.java
line: 371
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.
{noformat}
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();
{noformat}
This bug has the same problem as the MySQL bug :
http://bugs.mysql.com/bug.php?id=45699
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org
DO NOT REPLY [Bug 50921] Multiple replace function call can be
replaced with a single for loop to improve performance
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50921
Richard Frovarp <rf...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |WONTFIX
OS/Version| |All
--- Comment #1 from Richard Frovarp <rf...@apache.org> 2011-03-14 14:57:13 EDT ---
Thank you for the report. The affected code you point to is actually in the
Cocoon code base, not the Lenya code base and is beyond our control.
The one thing about the replacement code is it is far less readable. If there
isn't data to show that code block is a problem, I prefer readable over
optimized.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org