You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by bh...@apache.org on 2019/11/16 03:28:20 UTC

[hadoop-ozone] branch master updated: HDDS-2405. int2ByteString unnecessary byte array allocation (#197)

This is an automated email from the ASF dual-hosted git repository.

bharat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 79e3ff9  HDDS-2405. int2ByteString unnecessary byte array allocation (#197)
79e3ff9 is described below

commit 79e3ff9a4bc2691426c0e15249effc066f86b7e2
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Sat Nov 16 04:28:12 2019 +0100

    HDDS-2405. int2ByteString unnecessary byte array allocation (#197)
---
 .../main/java/org/apache/hadoop/ozone/common/Checksum.java   | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/Checksum.java b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/Checksum.java
index ff6ef93..98974ee 100644
--- a/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/Checksum.java
+++ b/hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/common/Checksum.java
@@ -19,8 +19,6 @@ package org.apache.hadoop.ozone.common;
 
 import com.google.common.annotations.VisibleForTesting;
 
-import java.io.DataOutputStream;
-import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -29,6 +27,7 @@ import java.util.List;
 import java.util.function.Function;
 import java.util.function.Supplier;
 
+import com.google.common.primitives.Ints;
 import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
 import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos
     .ChecksumType;
@@ -62,14 +61,7 @@ public class Checksum {
   }
 
   public static ByteString int2ByteString(int n) {
-    final ByteString.Output out = ByteString.newOutput();
-    try(DataOutputStream dataOut = new DataOutputStream(out)) {
-      dataOut.writeInt(n);
-    } catch (IOException e) {
-      throw new IllegalStateException(
-          "Failed to write integer n = " + n + " to a ByteString", e);
-    }
-    return out.toByteString();
+    return ByteString.copyFrom(Ints.toByteArray(n));
   }
 
   private static Function<ByteBuffer, ByteString> newChecksumByteBufferFunction(


---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: ozone-commits-help@hadoop.apache.org