Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-7149 Use a WeakHashSet for type uniqueness #2605

Merged
merged 3 commits into from Jun 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/reflect/scala/reflect/internal/SymbolTable.scala
Expand Up @@ -307,27 +307,20 @@ abstract class SymbolTable extends macros.Universe
}

object perRunCaches {
import java.lang.ref.WeakReference
import scala.collection.generic.Clearable

// Weak references so the garbage collector will take care of
// letting us know when a cache is really out of commission.
private val caches = mutable.HashSet[WeakReference[Clearable]]()
private val caches = WeakHashSet[Clearable]()

def recordCache[T <: Clearable](cache: T): T = {
caches += new WeakReference(cache)
caches += cache
cache
}

def clearAll() = {
debuglog("Clearing " + caches.size + " caches.")
caches foreach { ref =>
val cache = ref.get()
if (cache == null)
caches -= ref
else
cache.clear()
}
caches foreach (_.clear)
}

def newWeakMap[K, V]() = recordCache(mutable.WeakHashMap[K, V]())
Expand Down
4 changes: 2 additions & 2 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -3668,13 +3668,13 @@ trait Types
// Hash consing --------------------------------------------------------------

private val initialUniquesCapacity = 4096
private var uniques: util.HashSet[Type] = _
private var uniques: util.WeakHashSet[Type] = _
private var uniqueRunId = NoRunId

protected def unique[T <: Type](tp: T): T = {
if (Statistics.canEnable) Statistics.incCounter(rawTypeCount)
if (uniqueRunId != currentRunId) {
uniques = util.HashSet[Type]("uniques", initialUniquesCapacity)
uniques = util.WeakHashSet[Type](initialUniquesCapacity)
perRunCaches.recordCache(uniques)
uniqueRunId = currentRunId
}
Expand Down