From aacffa11d0a0e78174ba121153963138a5694855 Mon Sep 17 00:00:00 2001 From: Ryan Rawson Date: Fri, 1 Oct 2010 23:48:10 +0000 Subject: [PATCH] HBASE-2753 Remove sorted() methods from Result now that Gets are Scans git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1003710 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + .../java/org/apache/hadoop/hbase/client/Result.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4abe7533afd..a8d8494f40a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -564,6 +564,7 @@ Release 0.21.0 - Unreleased in transition HBASE-3064 Long sleeping in HConnectionManager after thread is interrupted (Bruno Dumon via Stack) + HBASE-2753 Remove sorted() methods from Result now that Gets are Scans IMPROVEMENTS HBASE-1760 Cleanup TODOs in HTable diff --git a/src/main/java/org/apache/hadoop/hbase/client/Result.java b/src/main/java/org/apache/hadoop/hbase/client/Result.java index 02ddb4d098e..4fe19a51337 100644 --- a/src/main/java/org/apache/hadoop/hbase/client/Result.java +++ b/src/main/java/org/apache/hadoop/hbase/client/Result.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.client; +import com.google.common.collect.Ordering; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.SplitKeyValue; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; @@ -149,12 +150,18 @@ public class Result implements Writable { * @return sorted array of KeyValues */ public KeyValue[] sorted() { - if (isEmpty()) { + if (isEmpty()) { // used for side effect! return null; } - Arrays.sort(kvs, KeyValue.COMPARATOR); + if (!sorted) { + assert Ordering.from(KeyValue.COMPARATOR).isOrdered(Arrays.asList(kvs)); + + Arrays.sort(kvs, KeyValue.COMPARATOR); + sorted = true; + } return kvs; } + private boolean sorted = false; /** * Map of families to all versions of its qualifiers and values.