[
https://issues.apache.org/jira/browse/LANG-340?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12609605#action_12609605
]
Robert Scholte commented on LANG-340:
-
I think I have to agree with Henri. And there's an important difference between
both code-samples:
The EqualsBuilder-implementation first checks the label, followed by the name,
while the self-written one first checks the name.
Normally names would be more unique then labels, so I'm not really surprised
the second implementation is faster.
> performance problem with EqualsBuilder.append()
> ---
>
> Key: LANG-340
> URL: https://issues.apache.org/jira/browse/LANG-340
> Project: Commons Lang
> Issue Type: Improvement
>Affects Versions: 2.3
>Reporter: Ramil Israfilov
> Fix For: 3.0
>
>
> We are using EqualsBuilder for construction of equals() method in our
> javabeans.
> For example we have a class:
> public class SimpleRecord{
> String name;
> String label;
> ...
> public boolean equals(Object object) {
> return new EqualsBuilder().append(this.label, rhs.label).append(
> this.getName(), rhs.getName()).isEquals();
> }
> So far so good.
> But one of our applications uses extensively Stack to push/pop SimpleRecord
> bean. And it was working very slow.
> After profiling of application we saw that most of the time JVM spent in
> equals() method of SimpleRecord. (it is called during peek() which is calling
> remove() from Stack)
> If we replace EqualsBuilder by following code our application worked 3 times
> faster ! Could you make some optimizations ?
> if (!(object instanceof SimpleRecord)) {
> return false;
> }
> SimpleRecord rhs = (SimpleRecord) object;
> if (this.getName() == null && rhs.getName() != null) {
> return false;
> } else
> if (rhs.getName() == null && this.getName() != null) {
> return false;
> } else
> if (this.label == null && rhs.label != null) {
> return false;
> } else
> if (rhs.label == null && this.label != null) {
> return false;
> } else
> if (this.label == null && rhs.label == null) {
> return this.getName().equals(rhs.getName());
> } else
>
> return this.getName().equals(rhs.getName()) &&
> this.label.equals(rhs.label);
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.