summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/mutable/FlatHashTable.scala
diff options
context:
space:
mode:
authorJames Iry <james.iry@typesafe.com>2013-01-04 14:26:45 -0800
committerJames Iry <james.iry@typesafe.com>2013-01-04 14:48:35 -0800
commit4d4ba75e33ea2a46a80edabe80066a917768c968 (patch)
tree81e2cfc63e2147be82c0fcfc41aaf25262696b82 /src/library/scala/collection/mutable/FlatHashTable.scala
parentdc0d1c91c8d2bf0fd333d168cc8decee7eca9ec7 (diff)
downloadscala-4d4ba75e33ea2a46a80edabe80066a917768c968.tar.gz
scala-4d4ba75e33ea2a46a80edabe80066a917768c968.tar.bz2
scala-4d4ba75e33ea2a46a80edabe80066a917768c968.zip
SI-6908 Cleanup of FlatHashTable nulls based on review
Uses pattern matching in findEntry instead of an if. Uses a named object NullSentinel instead of a val.\ Makes NullSentinel private. Uses isInstanceOf instead of equality on NullSentinel. Makes searchEntry a val instead of a var.
Diffstat (limited to 'src/library/scala/collection/mutable/FlatHashTable.scala')
-rw-r--r--src/library/scala/collection/mutable/FlatHashTable.scala17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala
index 1e073e1b5e..9f7193495d 100644
--- a/src/library/scala/collection/mutable/FlatHashTable.scala
+++ b/src/library/scala/collection/mutable/FlatHashTable.scala
@@ -108,10 +108,12 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] {
}
/** Finds an entry in the hash table if such an element exists. */
- protected def findEntry(elem: A): Option[A] = {
- val entry = findElemImpl(elem)
- if (null == entry) None else Some(entryToElem(entry))
- }
+ protected def findEntry(elem: A): Option[A] =
+ findElemImpl(elem) match {
+ case null => None
+ case entry => Some(entryToElem(entry))
+ }
+
/** Checks whether an element is contained in the hash table. */
protected def containsElem(elem: A): Boolean = {
@@ -119,7 +121,7 @@ trait FlatHashTable[A] extends FlatHashTable.HashUtils[A] {
}
private def findElemImpl(elem: A): AnyRef = {
- var searchEntry = elemToEntry(elem)
+ val searchEntry = elemToEntry(elem)
var h = index(searchEntry.hashCode)
var curEntry = table(h)
while (null != curEntry && curEntry != searchEntry) {
@@ -371,8 +373,9 @@ private[collection] object FlatHashTable {
override def initialValue = new scala.util.Random
}
- val NullSentinel = new AnyRef {
+ private object NullSentinel {
override def hashCode = 0
+ override def toString = "NullSentinel"
}
/** The load factor for the hash table; must be < 500 (0.5)
@@ -428,7 +431,7 @@ private[collection] object FlatHashTable {
* Does the inverse translation of elemToEntry
*/
protected final def entryToElem(entry : AnyRef) : A =
- (if (NullSentinel eq entry) null else entry).asInstanceOf[A]
+ (if (entry.isInstanceOf[NullSentinel.type]) null else entry).asInstanceOf[A]
}
}