Skip to content

Commit

Permalink
Attempt #1 to optimize findMember
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky authored and adriaanm committed Jul 14, 2012
1 parent 026a70d commit 1a73aa0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/reflect/scala/reflect/internal/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
* SynchronizedScope as mixin.
*/
class Scope protected[Scopes] (initElems: ScopeEntry = null) extends Iterable[Symbol] {

/** A bitset containing the last 6 bits of the start value of every name
* stored in this scope.
*/
var fingerPrints: Long = 0L

protected[Scopes] def this(base: Scope) = {
this(base.elems)
Expand Down Expand Up @@ -95,7 +100,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
*
* @param e ...
*/
protected def enter(e: ScopeEntry) {
protected def enterEntry(e: ScopeEntry) {
elemsCache = null
if (hashtable ne null)
enterInHash(e)
Expand All @@ -113,7 +118,11 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
*
* @param sym ...
*/
def enter[T <: Symbol](sym: T): T = { enter(newScopeEntry(sym, this)); sym }
def enter[T <: Symbol](sym: T): T = {
fingerPrints |= (1L << sym.name.start)
enterEntry(newScopeEntry(sym, this))
sym
}

/** enter a symbol, asserting that no symbol with same name exists in scope
*
Expand Down Expand Up @@ -344,7 +353,7 @@ trait Scopes extends api.Scopes { self: SymbolTable =>
/** The empty scope (immutable).
*/
object EmptyScope extends Scope {
override def enter(e: ScopeEntry) {
override def enterEntry(e: ScopeEntry) {
abort("EmptyScope.enter")
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1045,14 +1045,17 @@ trait Types extends api.Types { self: SymbolTable =>
var continue = true
var self: Type = null
var membertpe: Type = null
val fingerPrint: Long = (1L << name.start)
while (continue) {
continue = false
val bcs0 = baseClasses
var bcs = bcs0
while (!bcs.isEmpty) {
val decls = bcs.head.info.decls
var entry =
if (name == nme.ANYNAME) decls.elems else decls.lookupEntry(name)
if (name == nme.ANYNAME) decls.elems
else if ((fingerPrint & decls.fingerPrints) == 0) null
else decls.lookupEntry(name)
while (entry ne null) {
val sym = entry.sym
if (sym hasAllFlags requiredFlags) {
Expand Down

0 comments on commit 1a73aa0

Please sign in to comment.