From bc4d17e56000c1d6a704fadece204c88ca19275e Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Wed, 16 Mar 2011 10:21:29 -0700 Subject: [PATCH] UniqueId.suggest: remove unnecessary memory allocation. If there was N suggestions, we'd allocate N strings unnecessarily. When trying to check whether a UID is already in the cache, we can check either the forward mapping (name -> ID) or the backward mapping (ID -> name), but the former doesn't require any memory allocation so do that instead (the latter requires converting a byte[] to a String). Change-Id: I11b1e30e6c8f4f5cfadd2068216610311a950393 Reviewed-by: Berk D. Demir --- src/uid/UniqueId.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uid/UniqueId.java b/src/uid/UniqueId.java index 2ef5675c8b..7a60b3ec40 100644 --- a/src/uid/UniqueId.java +++ b/src/uid/UniqueId.java @@ -392,14 +392,14 @@ public List suggest(final String search) throws HBaseException { final byte[] key = row.get(0).key(); final String name = fromBytes(key); final byte[] id = row.get(0).value(); - final String cached_name = idCache.get(new String(id)); - if (cached_name == null) { + final byte[] cached_id = nameCache.get(name); + if (cached_id == null) { addIdToCache(name, id); addNameToCache(id, name); - } else if (!cached_name.equals(name)) { + } else if (!Arrays.equals(id, cached_id)) { throw new IllegalStateException("WTF? For kind=" + kind() - + " id=" + Arrays.toString(id) + " I already have name=" - + cached_name + " in cache, but I just scanned name=" + name); + + " name=" + name + ", we have id=" + Arrays.toString(cached_id) + + " in cache, but just scanned id=" + Arrays.toString(id)); } suggestions.add(name); if ((short) suggestions.size() > MAX_SUGGESTIONS) {