Skip to content

Commit 2af53bc

Browse files
authored
Use IdentityHashMap for reference counting (#44)
1 parent 0886e67 commit 2af53bc

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

core/src/main/scala/scala/scalanative/loop/internals/HandleUtils.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import scala.scalanative.runtime._
55
import scala.scalanative.runtime.Intrinsics._
66
import scala.scalanative.unsafe.Ptr
77
import scala.scalanative.libc.stdlib
8-
import scala.collection.mutable
98
import LibUV._
109

1110
private[loop] object HandleUtils {
12-
private val references = mutable.Map.empty[Object, Int]
11+
private val references = new java.util.IdentityHashMap[Object, Int]()
1312

1413
@inline def getData[T <: Object](handle: Ptr[Byte]): T = {
1514
// data is the first member of uv_loop_t
@@ -25,8 +24,7 @@ private[loop] object HandleUtils {
2524
// data is the first member of uv_loop_t
2625
val ptrOfPtr = handle.asInstanceOf[Ptr[Ptr[Byte]]]
2726
if (obj != null) {
28-
if (references.contains(obj)) references(obj) += 1
29-
else references(obj) = 1
27+
references.put(obj, references.get(obj) + 1)
3028
val rawptr = castObjectToRawPtr(obj)
3129
!ptrOfPtr = fromRawPtr[Byte](rawptr)
3230
} else {
@@ -40,8 +38,8 @@ private[loop] object HandleUtils {
4038
if (getData(handle) != null) {
4139
uv_close(handle, onCloseCB)
4240
val data = getData[Object](handle)
43-
val current = references(data)
44-
if (current > 1) references(data) -= 1
41+
val current = references.get(data)
42+
if (current > 1) references.put(data, current - 1)
4543
else references.remove(data)
4644
setData(handle, null)
4745
}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.6.1
1+
sbt.version=1.6.2

0 commit comments

Comments
 (0)