[
https://issues.apache.org/jira/browse/AVRO-4061?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
David Mollitor updated AVRO-4061:
---------------------------------
Description:
{code:java}
int h = hash;
if (h == 0) {
byte[] bytes = this.bytes;
int length = this.length;
for (int i = 0; i < length; i++) {
h = h * 31 + bytes[i];
}
this.hash = h;
}
{code}
If this is an empty string, the value of "h" will always be zero, and therefore
will not be cached correctly. An empty string will try to re-calculate the hash
every time. Instead, make "h" default to 1 to avoid this condition. This change
also makes the hash function equivalent to the JDK hash function.
was:
{code:java}
int h = hash;
if (h == 0) {
byte[] bytes = this.bytes;
int length = this.length;
for (int i = 0; i < length; i++) {
h = h * 31 + bytes[i];
}
this.hash = h;
}
{code}
If this is an empty string, the value of "h" will always be zero, and therefore
will not be cached correctly. An empty string will try to re-calculate the hash
every time. Instead, make "h" default to 1 to avoid this condition.
> Use Default Value of 1 For UTF8 Hash
> ------------------------------------
>
> Key: AVRO-4061
> URL: https://issues.apache.org/jira/browse/AVRO-4061
> Project: Apache Avro
> Issue Type: Improvement
> Components: java
> Affects Versions: 1.12.0
> Reporter: David Mollitor
> Assignee: David Mollitor
> Priority: Trivial
> Labels: pull-request-available
> Fix For: 1.12.1, 1.13.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> {code:java}
> int h = hash;
> if (h == 0) {
> byte[] bytes = this.bytes;
> int length = this.length;
> for (int i = 0; i < length; i++) {
> h = h * 31 + bytes[i];
> }
> this.hash = h;
> }
> {code}
> If this is an empty string, the value of "h" will always be zero, and
> therefore will not be cached correctly. An empty string will try to
> re-calculate the hash every time. Instead, make "h" default to 1 to avoid
> this condition. This change also makes the hash function equivalent to the
> JDK hash function.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)