From 555a9bae72107f18a79cff16aa4e0b448b6cd915 Mon Sep 17 00:00:00 2001 From: Jean-Remi Desjardins Date: Mon, 19 Nov 2012 21:41:17 -0500 Subject: findEntry implementation code more concise and DRYer. --- src/library/scala/collection/mutable/FlatHashTable.scala | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/library') diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala index c0299479f3..91e95e039b 100644 --- a/src/library/scala/collection/mutable/FlatHashTable.scala +++ b/src/library/scala/collection/mutable/FlatHashTable.scala @@ -110,24 +110,23 @@ 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] = { - var h = index(elemHashCode(elem)) - var entry = table(h) - while (null != entry && entry != elem) { - h = (h + 1) % table.length - entry = table(h) - } + val entry = findEntryImpl(elem) if (null == entry) None else Some(entry.asInstanceOf[A]) } /** Checks whether an element is contained in the hash table. */ protected def containsEntry(elem: A): Boolean = { + null != findEntryImpl(elem) + } + + private def findEntryImpl(elem: A): AnyRef = { var h = index(elemHashCode(elem)) var entry = table(h) while (null != entry && entry != elem) { h = (h + 1) % table.length entry = table(h) } - null != entry + entry } /** Add entry if not yet in table. -- cgit v1.2.3