Skip to content

Commit 066b018

Browse files
committed
fix: make sure JVM and SJS TASTy is alined
1 parent a1941f0 commit 066b018

File tree

1 file changed

+4
-60
lines changed

1 file changed

+4
-60
lines changed

library-js/src/scala/Symbol.scala

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ final class Symbol private (val name: String) extends Serializable {
3939
override def equals(other: Any) = this eq other.asInstanceOf[AnyRef]
4040
}
4141

42-
// Modified to use Scala.js specific cache
43-
object Symbol extends JSUniquenessCache[Symbol] {
42+
object Symbol extends UniquenessCache[String, Symbol] {
4443
override def apply(name: String): Symbol = super.apply(name)
4544
protected def valueFromKey(name: String): Symbol = new Symbol(name)
4645
protected def keyFromValue(sym: Symbol): Option[String] = Some(sym.name)
4746
}
4847

49-
private[scala] abstract class JSUniquenessCache[V]
50-
{
48+
// Modified to use Scala.js specific cache
49+
private[scala] abstract class UniquenessCache[K, V >: Null] {
5150
private val cache = js.Dictionary.empty[V]
5251

5352
protected def valueFromKey(k: String): V
@@ -57,59 +56,4 @@ private[scala] abstract class JSUniquenessCache[V]
5756
cache.getOrElseUpdate(name, valueFromKey(name))
5857

5958
def unapply(other: V): Option[String] = keyFromValue(other)
60-
}
61-
62-
/** This is private so it won't appear in the library API, but
63-
* abstracted to offer some hope of reusability. */
64-
/* DELETED for Scala.js
65-
private[scala] abstract class UniquenessCache[K >: js.String, V >: Null]
66-
{
67-
68-
import java.lang.ref.WeakReference
69-
import java.util.WeakHashMap
70-
import java.util.concurrent.locks.ReentrantReadWriteLock
71-
72-
private[this] val rwl = new ReentrantReadWriteLock()
73-
private[this] val rlock = rwl.readLock
74-
private[this] val wlock = rwl.writeLock
75-
private[this] val map = new WeakHashMap[K, WeakReference[V]]
76-
77-
protected def valueFromKey(k: K): V
78-
protected def keyFromValue(v: V): Option[K]
79-
80-
def apply(name: K): V = {
81-
def cached(): V = {
82-
rlock.lock
83-
try {
84-
val reference = map get name
85-
if (reference == null) null
86-
else reference.get // will be null if we were gc-ed
87-
}
88-
finally rlock.unlock
89-
}
90-
def updateCache(): V = {
91-
wlock.lock
92-
try {
93-
val res = cached()
94-
if (res != null) res
95-
else {
96-
// If we don't remove the old String key from the map, we can
97-
// wind up with one String as the key and a different String as
98-
// the name field in the Symbol, which can lead to surprising GC
99-
// behavior and duplicate Symbols. See scala/bug#6706.
100-
map remove name
101-
val sym = valueFromKey(name)
102-
map.put(name, new WeakReference(sym))
103-
sym
104-
}
105-
}
106-
finally wlock.unlock
107-
}
108-
109-
val res = cached()
110-
if (res == null) updateCache()
111-
else res
112-
}
113-
def unapply(other: V): Option[K] = keyFromValue(other)
114-
}
115-
*/
59+
}

0 commit comments

Comments
 (0)