commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [commons-codec] branch release updated: [CODEC-276] Reliance on default encoding in MurmurHash2 and MurmurHash3.
Date Mon, 30 Dec 2019 14:09:04 GMT
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/release by this push:
     new b207c45  [CODEC-276] Reliance on default encoding in MurmurHash2 and MurmurHash3.
b207c45 is described below

commit b207c452cd354583fa8c4bf10dfa9e70f24dbe55
Author: Gary Gregory <garydgregory@gmail.com>
AuthorDate: Mon Dec 30 09:09:00 2019 -0500

    [CODEC-276] Reliance on default encoding in MurmurHash2 and MurmurHash3.
    
    Reuse our StringUtils.getBytesUtf8(text).
---
 .../java/org/apache/commons/codec/digest/MurmurHash2.java  | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
index 12c1c2d..98698ad 100644
--- a/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
+++ b/src/main/java/org/apache/commons/codec/digest/MurmurHash2.java
@@ -17,8 +17,7 @@
 
 package org.apache.commons.codec.digest;
 
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
+import org.apache.commons.codec.binary.StringUtils;
 
 /**
  * Implementation of the MurmurHash2 32-bit and 64-bit hash functions.
@@ -51,13 +50,6 @@ import java.nio.charset.StandardCharsets;
  */
 public final class MurmurHash2 {
 
-    /**
-     * Default Charset used to convert strings into bytes.
-     * 
-     * Consider private; package private for tests only.
-     */
-    static final Charset GET_BYTES_CHARSET = StandardCharsets.UTF_8;
-
     // Constants for 32-bit variant
     private static final int M32 = 0x5bd1e995;
     private static final int R32 = 24;
@@ -154,7 +146,7 @@ public final class MurmurHash2 {
      * @see #hash32(byte[], int, int)
      */
     public static int hash32(final String text) {
-        final byte[] bytes = text.getBytes(GET_BYTES_CHARSET);
+        final byte[] bytes = StringUtils.getBytesUtf8(text);
         return hash32(bytes, bytes.length);
     }
 
@@ -268,7 +260,7 @@ public final class MurmurHash2 {
      * @see #hash64(byte[], int, int)
      */
     public static long hash64(final String text) {
-        final byte[] bytes = text.getBytes(GET_BYTES_CHARSET);
+        final byte[] bytes = StringUtils.getBytesUtf8(text);
         return hash64(bytes, bytes.length);
     }
 


Mime
View raw message