Skip to content

Commit 1a73aa0

Browse files
oderskyAdriaan Moors
authored and
Adriaan Moors
committed
Attempt #1 to optimize findMember
Keeps fingerprints in scopes which are bitsets telling you what the last 6 bits of each hashcode of the names stored in the scope are. findMember will avoid looking in a scope if inferprints do not match.
1 parent 026a70d commit 1a73aa0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/reflect/scala/reflect/internal/Scopes.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
4242
* SynchronizedScope as mixin.
4343
*/
4444
class Scope protected[Scopes] (initElems: ScopeEntry = null) extends Iterable[Symbol] {
45+
46+
/** A bitset containing the last 6 bits of the start value of every name
47+
* stored in this scope.
48+
*/
49+
var fingerPrints: Long = 0L
4550

4651
protected[Scopes] def this(base: Scope) = {
4752
this(base.elems)
@@ -95,7 +100,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
95100
*
96101
* @param e ...
97102
*/
98-
protected def enter(e: ScopeEntry) {
103+
protected def enterEntry(e: ScopeEntry) {
99104
elemsCache = null
100105
if (hashtable ne null)
101106
enterInHash(e)
@@ -113,7 +118,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
113118
*
114119
* @param sym ...
115120
*/
116-
def enter[T <: Symbol](sym: T): T = { enter(newScopeEntry(sym, this)); sym }
121+
def enter[T <: Symbol](sym: T): T = {
122+
fingerPrints |= (1L << sym.name.start)
123+
enterEntry(newScopeEntry(sym, this))
124+
sym
125+
}
117126

118127
/** enter a symbol, asserting that no symbol with same name exists in scope
119128
*
@@ -344,7 +353,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
344353
/** The empty scope (immutable).
345354
*/
346355
object EmptyScope extends Scope {
347-
override def enter(e: ScopeEntry) {
356+
override def enterEntry(e: ScopeEntry) {
348357
abort("EmptyScope.enter")
349358
}
350359
}

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,14 +1045,17 @@ trait Types extends api.Types { self: SymbolTable =>
10451045
var continue = true
10461046
var self: Type = null
10471047
var membertpe: Type = null
1048+
val fingerPrint: Long = (1L << name.start)
10481049
while (continue) {
10491050
continue = false
10501051
val bcs0 = baseClasses
10511052
var bcs = bcs0
10521053
while (!bcs.isEmpty) {
10531054
val decls = bcs.head.info.decls
10541055
var entry =
1055-
if (name == nme.ANYNAME) decls.elems else decls.lookupEntry(name)
1056+
if (name == nme.ANYNAME) decls.elems
1057+
else if ((fingerPrint & decls.fingerPrints) == 0) null
1058+
else decls.lookupEntry(name)
10561059
while (entry ne null) {
10571060
val sym = entry.sym
10581061
if (sym hasAllFlags requiredFlags) {

0 commit comments

Comments
 (0)