@@ -165,16 +165,15 @@ object Names {
165
165
override def asTermName : TermName = this
166
166
167
167
@ sharable // because it is only modified in the synchronized block of toTypeName.
168
- @ volatile private var _typeName : TypeName = null
168
+ private var myTypeName : TypeName = null
169
+ // Note: no @volatile needed since type names are immutable and therefore safely published
169
170
170
- override def toTypeName : TypeName = {
171
- if (_typeName == null )
171
+ override def toTypeName : TypeName =
172
+ if myTypeName == null then
172
173
synchronized {
173
- if (_typeName == null )
174
- _typeName = new TypeName (this )
174
+ if myTypeName == null then myTypeName = new TypeName (this )
175
175
}
176
- _typeName
177
- }
176
+ myTypeName
178
177
179
178
override def likeSpaced (name : Name ): TermName = name.toTermName
180
179
@@ -528,25 +527,25 @@ object Names {
528
527
529
528
def enterIfNew (cs : Array [Char ], offset : Int , len : Int ): SimpleName =
530
529
Stats .record(statsItem(" put" ))
531
- val table = currentTable
532
- var idx = hashValue(cs, offset, len) & (table .length - 1 )
533
- var name = table (idx).asInstanceOf [SimpleName ]
530
+ val myTable = currentTable // could be outdated under parallel execution
531
+ var idx = hashValue(cs, offset, len) & (myTable .length - 1 )
532
+ var name = myTable (idx).asInstanceOf [SimpleName ]
534
533
while name != null do
535
534
if name.length == len && Names .equals(name.start, cs, offset, len) then
536
535
return name
537
536
Stats .record(statsItem(" miss" ))
538
- idx = (idx + 1 ) & (table .length - 1 )
539
- name = table (idx).asInstanceOf [SimpleName ]
537
+ idx = (idx + 1 ) & (myTable .length - 1 )
538
+ name = myTable (idx).asInstanceOf [SimpleName ]
540
539
Stats .record(statsItem(" addEntryAt" ))
541
540
synchronized {
542
- if (table eq currentTable) && table (idx) == null then
541
+ if (myTable eq currentTable) && myTable (idx) == null then
543
542
// Our previous unsynchronized computation of the next free index is still correct.
544
543
// This relies on the fact that table entries go from null to non-null, and then
545
544
// stay the same. Note that we do not need the table or the entry in it to be
546
545
// volatile since SimpleNames are immutable, and hence safely published.
547
546
// The same holds for the chrs array. We might miss before the synchronized
548
547
// on published characters but that would make name comparison false, which
549
- // means we end up in the synchronized block here, where we get the correct state
548
+ // means we end up in the synchronized block here, where we get the correct state.
550
549
name = SimpleName (nc, len)
551
550
ensureCapacity(nc + len)
552
551
Array .copy(cs, offset, chrs, nc, len)
0 commit comments