Skip to content

Commit a6c50c1

Browse files
committed
Fixed a bug in LRUcache which prevented sizes >= 8.
1 parent ca3ff28 commit a6c50c1

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ object Types {
327327
}
328328

329329
/** The member of this type with the given name */
330-
final def member(name: Name)(implicit ctx: Context): Denotation = /*>|>*/ track("member-" + name) /*<|<*/ {
330+
final def member(name: Name)(implicit ctx: Context): Denotation = /*>|>*/ track("member") /*<|<*/ {
331331
findMember(name, widenIfUnstable, EmptyFlags)
332332
}
333333

src/dotty/tools/dotc/util/LRUCache.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.dotc.util
22

33
import reflect.ClassTag
4+
import annotation.tailrec
45

56
/** A least-recently-used cache for Key -> Value computations
67
* It currently keeps the last 8 associations, but this can be
@@ -29,6 +30,7 @@ class LRUCache[Key >: Null : ClassTag, Value >: Null: ClassTag] {
2930
* if key was not found.
3031
*/
3132
def lookup(key: Key): Value = {
33+
@tailrec
3234
def lookupNext(prev: Int, current: Int, nx: SixteenNibbles): Value = {
3335
val follow = nx(current)
3436
if (keys(current) == key) {
@@ -89,7 +91,7 @@ class LRUCache[Key >: Null : ClassTag, Value >: Null: ClassTag] {
8991
object LRUCache {
9092

9193
/** The number of retained elements in the cache; must be at most 16. */
92-
val Retained = 8
94+
val Retained = 16
9395

9496
/** The initial ring: 0 -> 1 -> ... -> 7 -> 0 */
9597
val initialRing =

src/dotty/tools/dotc/util/SixteenNibbles.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SixteenNibbles(val bits: Long) extends AnyVal {
1212

1313
def updated(idx: Int, value: Int): SixteenNibbles =
1414
new SixteenNibbles(
15-
(bits & ~(Mask << (idx * Width))) |
15+
(bits & ~(LongMask << (idx * Width))) |
1616
((value & Mask).toLong << (idx * Width)))
1717

1818
def elements: IndexedSeq[Int] = (0 until 16) map apply
@@ -24,4 +24,5 @@ class SixteenNibbles(val bits: Long) extends AnyVal {
2424
object SixteenNibbles {
2525
final val Width = 4
2626
final val Mask = (1 << Width) - 1
27+
final val LongMask = Mask.toLong
2728
}

0 commit comments

Comments
 (0)