@@ -14,6 +14,7 @@ import Flags._
14
14
import scala .util .control .ControlThrowable
15
15
import scala .annotation .tailrec
16
16
import util .Statistics
17
+ import scala .runtime .ObjectRef
17
18
18
19
/* A standard type pattern match:
19
20
case ErrorType =>
@@ -1031,9 +1032,21 @@ trait Types extends api.Types { self: SymbolTable =>
1031
1032
1032
1033
// Console.println("find member " + name.decode + " in " + this + ":" + this.baseClasses)//DEBUG
1033
1034
var members : Scope = null
1035
+ var membertpes : mutable.Map [Symbol , Type ] = null
1036
+ var required = requiredFlags
1034
1037
var excluded = excludedFlags | DEFERRED
1035
1038
var continue = true
1036
1039
var self : Type = null
1040
+
1041
+ def getMtpe (cache : mutable.Map [Symbol , Type ], sym : Symbol ): Type = cache get sym match {
1042
+ case Some (tpe) if tpe ne null =>
1043
+ tpe
1044
+ case _ =>
1045
+ val result = self memberType sym
1046
+ cache(sym) = result
1047
+ result
1048
+ }
1049
+
1037
1050
while (continue) {
1038
1051
continue = false
1039
1052
val bcs0 = baseClasses
@@ -1044,29 +1057,31 @@ trait Types extends api.Types { self: SymbolTable =>
1044
1057
while (entry ne null ) {
1045
1058
val sym = entry.sym
1046
1059
val flags = sym.flags
1047
- if ((flags & requiredFlags ) == requiredFlags ) {
1060
+ if ((flags & required ) == required ) {
1048
1061
val excl = flags & excluded
1049
1062
if (excl == 0L &&
1050
1063
(// omit PRIVATE LOCALS unless selector class is contained in class owning the def.
1051
1064
(bcs eq bcs0) ||
1052
1065
(flags & PrivateLocal ) != PrivateLocal ||
1053
1066
(bcs0.head.hasTransOwner(bcs.head)))) {
1054
- if (members eq null ) members = newScope
1055
- var prevEntry = members.lookupEntry(sym.name)
1056
- var symtpe : Type = null
1057
- while ((prevEntry ne null ) &&
1058
- ! ((prevEntry.sym eq sym) ||
1059
- (prevEntry.sym.owner ne sym.owner) &&
1060
- ! sym.hasFlag(PRIVATE ) && {
1061
- if (self eq null ) self = this .narrow
1062
- if (symtpe eq null ) symtpe = self.memberType(sym)
1063
- self.memberType(prevEntry.sym) matches symtpe
1064
- })) {
1065
- prevEntry = members lookupNextEntry prevEntry
1067
+ if (members eq null ) {
1068
+ members = newScope
1069
+ membertpes = new mutable.HashMap
1066
1070
}
1067
- if (prevEntry eq null ) {
1068
- members enter sym
1071
+ var others : ScopeEntry = members.lookupEntry(sym.name)
1072
+ var symtpe : Type = null
1073
+ while ((others ne null ) && {
1074
+ val other = others.sym
1075
+ (other ne sym) &&
1076
+ ((other.owner eq sym.owner) ||
1077
+ (flags & PRIVATE ) != 0 || {
1078
+ if (self eq null ) self = this .narrow
1079
+ if (symtpe eq null ) symtpe = self.memberType(sym)
1080
+ ! (getMtpe(membertpes, other) matches symtpe)
1081
+ })}) {
1082
+ others = members lookupNextEntry others
1069
1083
}
1084
+ if (others eq null ) members enter sym
1070
1085
} else if (excl == DEFERRED ) {
1071
1086
continue = true
1072
1087
}
@@ -1076,6 +1091,7 @@ trait Types extends api.Types { self: SymbolTable =>
1076
1091
// excluded = excluded | LOCAL
1077
1092
bcs = bcs.tail
1078
1093
} // while (!bcs.isEmpty)
1094
+ required |= DEFERRED
1079
1095
excluded = excludedFlags
1080
1096
} // while (continue)
1081
1097
Statistics .popTimer(typeOpsStack, start)
@@ -1116,20 +1132,23 @@ trait Types extends api.Types { self: SymbolTable =>
1116
1132
var self : Type = null
1117
1133
val fingerPrint : Long = name.fingerPrint
1118
1134
1119
- def getMtpe (sym : Symbol , idx : Int ): Type = {
1135
+ def getMtpe (idx : Int , sym : Symbol ): Type = {
1120
1136
var result = membertpes(idx)
1121
- if (result eq null ) { result = self memberType sym; membertpes(idx) = result }
1137
+ if (result eq null ) {
1138
+ result = self memberType sym
1139
+ membertpes(idx) = result
1140
+ }
1122
1141
result
1123
1142
}
1124
1143
1125
- def addMtpe (xs : Array [Type ], tpe : Type , idx : Int ): Array [Type ] =
1126
- if (idx < xs.length ) {
1144
+ def addMtpe (xs : Array [Type ], idx : Int , tpe : Type ): Array [Type ] =
1145
+ if (idx < xs.length) {
1127
1146
xs(idx) = tpe
1128
1147
xs
1129
1148
} else {
1130
1149
val ys = new Array [Type ](xs.length * 2 )
1131
1150
Array .copy(xs, 0 , ys, 0 , xs.length)
1132
- addMtpe(ys, tpe, idx )
1151
+ addMtpe(ys, idx, tpe )
1133
1152
}
1134
1153
1135
1154
while (continue) {
@@ -1173,7 +1192,7 @@ trait Types extends api.Types { self: SymbolTable =>
1173
1192
membertpes(1 ) = symtpe
1174
1193
}
1175
1194
} else {
1176
- var others = members
1195
+ var others : List [ Symbol ] = members
1177
1196
var idx = 0
1178
1197
var symtpe : Type = null
1179
1198
while ((others ne null ) && {
@@ -1183,7 +1202,7 @@ trait Types extends api.Types { self: SymbolTable =>
1183
1202
(flags & PRIVATE ) != 0 || {
1184
1203
if (self eq null ) self = this .narrow
1185
1204
if (symtpe eq null ) symtpe = self.memberType(sym)
1186
- ! (getMtpe(other, idx ) matches symtpe)
1205
+ ! (getMtpe(idx, other ) matches symtpe)
1187
1206
})}) {
1188
1207
others = others.tail
1189
1208
idx += 1
@@ -1192,7 +1211,7 @@ trait Types extends api.Types { self: SymbolTable =>
1192
1211
val lastM1 = new :: (sym, null )
1193
1212
lastM.tl = lastM1
1194
1213
lastM = lastM1
1195
- membertpes = addMtpe(membertpes, symtpe, idx )
1214
+ membertpes = addMtpe(membertpes, idx, symtpe )
1196
1215
}
1197
1216
}
1198
1217
} else if (excl == DEFERRED ) {
@@ -1205,8 +1224,8 @@ trait Types extends api.Types { self: SymbolTable =>
1205
1224
// excluded = excluded | LOCAL
1206
1225
bcs = if (name == nme.CONSTRUCTOR ) Nil else bcs.tail
1207
1226
} // while (!bcs.isEmpty)
1208
- excluded = excludedFlags
1209
1227
required |= DEFERRED
1228
+ excluded = excludedFlags
1210
1229
} // while (continue)
1211
1230
Statistics .popTimer(typeOpsStack, start)
1212
1231
if (suspension ne null ) suspension foreach (_.suspended = false )
0 commit comments