Skip to content

Commit

Permalink
Deduplicate EnumSets of UseScopes
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed May 22, 2020
1 parent 68011f8 commit f7e1812
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
package sbt.internal.inc

import java.util
import java.util.concurrent.ConcurrentHashMap

import xsbti.UseScope

case class UsedName private (name: String, scopes: util.EnumSet[UseScope])

object UsedName {
private[this] val internedUseUseScope =
new ConcurrentHashMap[util.EnumSet[UseScope], util.EnumSet[UseScope]]()

def apply(name: String, scopes: Iterable[UseScope] = Nil): UsedName = {
val useScopes = util.EnumSet.noneOf(classOf[UseScope])
Expand All @@ -27,7 +30,8 @@ object UsedName {

def make(name: String, useScopes: util.EnumSet[UseScope]): UsedName = {
val escapedName = escapeControlChars(name)
new UsedName(escapedName, useScopes)
val interned = internedUseUseScope.computeIfAbsent(useScopes, x => x)
new UsedName(escapedName, interned)
}

private def escapeControlChars(name: String) = {
Expand Down

0 comments on commit f7e1812

Please sign in to comment.