Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 45262190A4 for ; Fri, 1 Apr 2016 04:29:33 +0000 (UTC) Received: (qmail 67234 invoked by uid 500); 1 Apr 2016 04:29:28 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 67196 invoked by uid 500); 1 Apr 2016 04:29:28 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 67187 invoked by uid 99); 1 Apr 2016 04:29:28 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Apr 2016 04:29:28 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 05E0FDFC73; Fri, 1 Apr 2016 04:29:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: stack@apache.org To: commits@hbase.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-15569 Make Bytes.toStringBinary faster Date: Fri, 1 Apr 2016 04:29:28 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-1.2 8d8a7107d -> 8f05f84cc HBASE-15569 Make Bytes.toStringBinary faster Signed-off-by: stack Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/8f05f84c Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/8f05f84c Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/8f05f84c Branch: refs/heads/branch-1.2 Commit: 8f05f84cc94d39efa232fb3e53f0cffec92581f9 Parents: 8d8a710 Author: Junegunn Choi Authored: Thu Mar 31 13:20:26 2016 +0900 Committer: stack Committed: Thu Mar 31 21:29:18 2016 -0700 ---------------------------------------------------------------------- .../java/org/apache/hadoop/hbase/util/Bytes.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/8f05f84c/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java ---------------------------------------------------------------------- diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java index 52150c0..822da6a 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java @@ -367,7 +367,7 @@ public class Bytes { final byte [] b2) { return toString(b1, 0, b1.length) + sep + toString(b2, 0, b2.length); } - + /** * This method will convert utf8 encoded bytes into a string. If the given byte array is null, * this method will return null. @@ -438,6 +438,10 @@ public class Bytes { return toStringBinary(toBytes(buf)); } + private static final char[] HEX_CHARS_UPPER = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' + }; + /** * Write a printable representation of a byte array. Non-printable * characters are hex escaped in the format \\x%02X, eg: @@ -455,13 +459,12 @@ public class Bytes { if (off + len > b.length) len = b.length - off; for (int i = off; i < off + len ; ++i ) { int ch = b[i] & 0xFF; - if ((ch >= '0' && ch <= '9') - || (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z') - || " `~!@#$%^&*()-_=+[]{}|;:'\",.<>/?".indexOf(ch) >= 0 ) { + if (ch >= ' ' && ch <= '~' && ch != '\\') { result.append((char)ch); } else { - result.append(String.format("\\x%02X", ch)); + result.append("\\x"); + result.append(HEX_CHARS_UPPER[ch / 0x10]); + result.append(HEX_CHARS_UPPER[ch % 0x10]); } } return result.toString();