aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandy Ryza <sandy@cloudera.com>2014-04-25 17:55:04 -0700
committerPatrick Wendell <pwendell@gmail.com>2014-04-25 17:55:04 -0700
commit87cf35c2d6acc9649b3fb05648b79b9862b3959b (patch)
treebe0ef584b7064cd3639ac0c1a903468b904b71d1
parent027f1b85f961ce16ee069afe3d90a36dce009994 (diff)
downloadspark-87cf35c2d6acc9649b3fb05648b79b9862b3959b.tar.gz
spark-87cf35c2d6acc9649b3fb05648b79b9862b3959b.tar.bz2
spark-87cf35c2d6acc9649b3fb05648b79b9862b3959b.zip
SPARK-1632. Remove unnecessary boxing in compares in ExternalAppendOnlyM...
...ap Author: Sandy Ryza <sandy@cloudera.com> Closes #559 from sryza/sandy-spark-1632 and squashes the following commits: a6cd352 [Sandy Ryza] Only compute hashes once 04e3884 [Sandy Ryza] SPARK-1632. Remove unnecessary boxing in compares in ExternalAppendOnlyMap
-rw-r--r--core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala8
1 files changed, 5 insertions, 3 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala b/core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala
index d615767284..170f09be21 100644
--- a/core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala
+++ b/core/src/main/scala/org/apache/spark/util/collection/ExternalAppendOnlyMap.scala
@@ -337,8 +337,8 @@ class ExternalAppendOnlyMap[K, V, C](
}
override def compareTo(other: StreamBuffer): Int = {
- // minus sign because mutable.PriorityQueue dequeues the max, not the min
- -minKeyHash.compareTo(other.minKeyHash)
+ // descending order because mutable.PriorityQueue dequeues the max, not the min
+ if (other.minKeyHash < minKeyHash) -1 else if (other.minKeyHash == minKeyHash) 0 else 1
}
}
}
@@ -422,7 +422,9 @@ class ExternalAppendOnlyMap[K, V, C](
private[spark] object ExternalAppendOnlyMap {
private class KCComparator[K, C] extends Comparator[(K, C)] {
def compare(kc1: (K, C), kc2: (K, C)): Int = {
- kc1._1.hashCode().compareTo(kc2._1.hashCode())
+ val hash1 = kc1._1.hashCode()
+ val hash2 = kc2._1.hashCode()
+ if (hash1 < hash2) -1 else if (hash1 == hash2) 0 else 1
}
}
}