1- package dotty .tools .dotc .util
1+ package dotty .tools
2+ package dotc .util
23
34object GenericHashMap :
45
@@ -22,7 +23,7 @@ object GenericHashMap:
2223 * However, a table of size up to DenseLimit will be re-sized only
2324 * once the number of elements reaches the table's size.
2425 */
25- abstract class GenericHashMap [Key <: AnyRef , Value >: Null <: AnyRef ]
26+ abstract class GenericHashMap [Key <: AnyRef , Value ]
2627 (initialCapacity : Int , capacityMultiple : Int ) extends MutableMap [Key , Value ]:
2728 import GenericHashMap .DenseLimit
2829
@@ -57,17 +58,20 @@ abstract class GenericHashMap[Key <: AnyRef, Value >: Null <: AnyRef]
5758 protected def isEqual (x : Key , y : Key ): Boolean
5859
5960 /** Turn successor index or hash code `x` into a table index */
60- private def index (x : Int ): Int = x & (table.length - 2 )
61+ inline protected def index (x : Int ): Int = x & (table.length - 2 )
6162
62- private def firstIndex (key : Key ) = if isDense then 0 else index(hash(key))
63- private def nextIndex (idx : Int ) =
63+ inline protected def firstIndex (key : Key ) = if isDense then 0 else index(hash(key))
64+ inline protected def nextIndex (idx : Int ) =
6465 Stats .record(statsItem(" miss" ))
6566 index(idx + 2 )
6667
67- private def keyAt (idx : Int ): Key = table(idx).asInstanceOf [Key ]
68- private def valueAt (idx : Int ): Value = table(idx + 1 ).asInstanceOf [Value ]
68+ inline protected def keyAt (idx : Int ): Key = table(idx).asInstanceOf [Key ]
69+ inline protected def valueAt (idx : Int ): Value = table(idx + 1 ).asInstanceOf [Value ]
6970
70- def lookup (key : Key ): Value =
71+ inline protected def setTable (idx : Int , value : Value ) =
72+ table(idx) = value.asInstanceOf [AnyRef ]
73+
74+ def lookup (key : Key ): Value | Null =
7175 Stats .record(statsItem(" lookup" ))
7276 var idx = firstIndex(key)
7377 var k = keyAt(idx)
@@ -83,12 +87,12 @@ abstract class GenericHashMap[Key <: AnyRef, Value >: Null <: AnyRef]
8387 var k = keyAt(idx)
8488 while k != null do
8589 if isEqual(k, key) then
86- table (idx + 1 ) = value
90+ setTable (idx + 1 , value)
8791 return
8892 idx = nextIndex(idx)
8993 k = keyAt(idx)
9094 table(idx) = key
91- table (idx + 1 ) = value
95+ setTable (idx + 1 , value)
9296 used += 1
9397 if used > limit then growTable()
9498
@@ -109,7 +113,7 @@ abstract class GenericHashMap[Key <: AnyRef, Value >: Null <: AnyRef]
109113 // hash(k) is then logically at or before hole; can be moved forward to fill hole
110114 then
111115 table(hole) = k
112- table (hole + 1 ) = valueAt(idx)
116+ setTable (hole + 1 , valueAt(idx) )
113117 hole = idx
114118 table(hole) = null
115119 used -= 1
@@ -118,9 +122,9 @@ abstract class GenericHashMap[Key <: AnyRef, Value >: Null <: AnyRef]
118122 k = keyAt(idx)
119123
120124 def getOrElseUpdate (key : Key , value : => Value ): Value =
121- var v = lookup(key)
125+ var v : Value | Null = lookup(key)
122126 if v == null then v = value
123- v
127+ v.uncheckedNN
124128
125129 private def addOld (key : Key , value : AnyRef ): Unit =
126130 Stats .record(statsItem(" re-enter" ))
0 commit comments