You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2019/03/04 04:32:01 UTC
[directory-ldap-api] 06/06: Improved the hashcode pre-computation
protection: we use a temporary variable to store the value,
so that concurrent calls don't impact the final value
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
commit 2a77152705392ccb4e1af4313fe4dc30bc676816
Author: emmanuel lecharny <el...@apache.org>
AuthorDate: Mon Mar 4 05:31:53 2019 +0100
Improved the hashcode pre-computation protection: we use a temporary
variable to store the value, so that concurrent calls don't impact the
final value
---
.../directory/api/ldap/model/entry/DefaultAttribute.java | 10 ++++++----
.../apache/directory/api/ldap/model/entry/DefaultEntry.java | 4 ++--
.../java/org/apache/directory/api/ldap/model/name/Ava.java | 6 +++---
.../java/org/apache/directory/api/ldap/model/name/Rdn.java | 6 +++---
4 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
index 4b8471d..f948d53 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultAttribute.java
@@ -1889,22 +1889,24 @@ public class DefaultAttribute implements Attribute, Cloneable
*/
private void rehash()
{
- h = 37;
+ int hTmp = 37;
if ( isHR != null )
{
- h = h * 17 + isHR.hashCode();
+ hTmp = hTmp * 17 + isHR.hashCode();
}
if ( id != null )
{
- h = h * 17 + id.hashCode();
+ hTmp = hTmp * 17 + id.hashCode();
}
if ( attributeType != null )
{
- h = h * 17 + attributeType.hashCode();
+ hTmp = hTmp * 17 + attributeType.hashCode();
}
+
+ h = hTmp;
}
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java
index 25f1bf4..218d552 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/DefaultEntry.java
@@ -546,8 +546,8 @@ public final class DefaultEntry implements Entry
*/
private void rehash()
{
- h = 37;
- h = h * 17 + dn.hashCode();
+ int hTmp = 37;
+ h = hTmp * 17 + dn.hashCode();
}
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
index 01b47ec..df5febf 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Ava.java
@@ -1470,10 +1470,10 @@ public class Ava implements Externalizable, Cloneable, Comparable<Ava>
{
if ( h == 0 )
{
- h = 37;
+ int hTmp = 37;
- h = h * 17 + ( normType != null ? normType.hashCode() : 0 );
- h = h * 17 + ( value != null ? value.hashCode() : 0 );
+ hTmp = hTmp * 17 + ( normType != null ? normType.hashCode() : 0 );
+ h = hTmp * 17 + ( value != null ? value.hashCode() : 0 );
}
return h;
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
index 311361d..0f79ed3 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
@@ -1730,7 +1730,7 @@ public class Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable
{
if ( h == 0 )
{
- h = 37;
+ int hTmp = 37;
switch ( nbAvas )
{
@@ -1740,7 +1740,7 @@ public class Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable
case 1:
// We have a single Ava
- h = h * 17 + ava.hashCode();
+ h = hTmp * 17 + ava.hashCode();
break;
default:
@@ -1748,7 +1748,7 @@ public class Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable
for ( Ava ata : avas )
{
- h = h * 17 + ata.hashCode();
+ h = hTmp * 17 + ata.hashCode();
}
break;