Skip to content

Commit

Permalink
PDFBOX-5660: simplify hashCode() and equals(), test name first becaus…
Browse files Browse the repository at this point in the history
…e Map.equals() is expensive, by Axel Howind

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1914469 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 8, 2023
1 parent 9f93a2d commit a776dc6
Showing 1 changed file with 4 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -72,11 +73,7 @@ public Integer getReplacementForGlyphs(List<Integer> glyphIds)
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((featureMap == null) ? 0 : featureMap.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
return Objects.hash(featureMap, name);
}

@Override
Expand All @@ -86,37 +83,11 @@ public boolean equals(Object obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
if (obj == null || getClass() != obj.getClass())
{
return false;
}
MapBackedScriptFeature other = (MapBackedScriptFeature) obj;
if (featureMap == null)
{
if (other.featureMap != null)
{
return false;
}
}
else if (!featureMap.equals(other.featureMap))
{
return false;
}
if (name == null)
{
if (other.name != null)
{
return false;
}
}
else if (!name.equals(other.name))
{
return false;
}
return true;
return Objects.equals(name, this.name) && Objects.equals(featureMap, this.featureMap);
}
}

0 comments on commit a776dc6

Please sign in to comment.