You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ec...@apache.org on 2016/04/08 21:32:12 UTC
[20/52] [abbrv] hbase git commit: HBASE-15569 Make
Bytes.toStringBinary faster
HBASE-15569 Make Bytes.toStringBinary faster
Signed-off-by: stack <st...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/ff6a3395
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/ff6a3395
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/ff6a3395
Branch: refs/heads/HBASE-14850
Commit: ff6a3395821fd1a7857b35b11d45b81743a75e61
Parents: 7d3a89c
Author: Junegunn Choi <ju...@gmail.com>
Authored: Thu Mar 31 13:20:26 2016 +0900
Committer: stack <st...@apache.org>
Committed: Thu Mar 31 21:23:44 2016 -0700
----------------------------------------------------------------------
.../main/java/org/apache/hadoop/hbase/util/Bytes.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/ff6a3395/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 aae6c4c..7b9eb0b 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
@@ -626,6 +626,10 @@ public class Bytes implements Comparable<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:
@@ -643,13 +647,12 @@ public class Bytes implements Comparable<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();