[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2122?page=c...
]
Xavier Le Vourch commented on HHH-2122:
---------------------------------------
No I did not perform a performance test but I guess you already knew that...
My main motivation was to test the new rules and patches for false positives I sent to the
PMD project that have been integrated in the current dev version. To do so, I'm
running tests on several open source libraries and as a side effect, I'm sending
patches to the relevant projects containing fixes for a few of the detected problems.
If you look closely, there's no change in the API. It's just avoiding creating
temporary objects, avoiding unneeded String objects in the generated byte code or doing
checks that are not needed based on the Java specification.
Anyway, you can discard the patch if you do not want to integrate it.
Below I'll list a short explanation of the perceived advantages I see in the changes.
Xavier
Double.valueOf(x).doubleValue() -> Double.parseDouble(x)
temporary Double is not created
append("x") -> append('x')
string is not stored in byte code, adding a char is also less complex
x != null && x instanceof X -> x instanceof X
Java spec
list.toArray uses correctly sized array as argument
temporary zero sized array not created
new String(str) -> str
useless copy of immutable object
if (expr == false) -> if (!expr)
OK, that one is not really needed but the fact that it appears only once means that
it's not really a standard construct in your code base
append(s1 + s2) -> append(s1).append(s2)
temporary StringBuffer object created for "s1 + s2" and then added to the
enclosing
StringBuffer.
loop over array to add to list -> list.addAll(Arrays.asList(<array>))
less complex, less prone to error in loop
extra ; removed
again appears only once. Depending on context, extra ; can change behavior, not in this
case though.
name.toLowerCase().equals("rowid") ->
name.equalsIgnoreCase("rowid")
temporary String object created, appears only once, equalsIgnoreCase() used elsewhere
use of System.arraycopy instead of loop
arraycopy is native and should be the faster way to copy the array. resulting Java code
is also less complex and more maintainable.
optimization patch based on pmd rules
-------------------------------------
Key: HHH-2122
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2122
Project: Hibernate3
Type: Patch
Environment: latest svn source
Reporter: Xavier Le Vourch
Priority: Minor
Attachments: Optimizations.patch
I've run pmd with a custom ruleset and made a few optimization changes:
Double.valueOf(x).doubleValue() -> Double.parseDouble(x)
append("x") -> append('x')
x != null && x instanceof X -> x instanceof X
list.toArray uses correctly sized array as argument
new String(str) -> str
if (expr == false) -> if (!expr)
append(s1 + s2) -> append(s1).append(s2)
loop over array to add to list -> list.addAll(Arrays.asList(<array>))
extra ; removed
name.toLowerCase().equals("rowid") ->
name.equalsIgnoreCase("rowid")
use of System.arraycopy instead of loop
I could break the patch in several parts if that makes it easier to analyze.
Xavier
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira