summaryrefslogtreecommitdiff
path: root/sources/scalac/symtab/Type.java
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-03-04 01:24:34 +0000
committerpaltherr <paltherr@epfl.ch>2004-03-04 01:24:34 +0000
commit3d5478d4e16815bbb353eb718d5a1c5e712706d4 (patch)
treefc26c06967b98f7f192533b1e050291de452a64d /sources/scalac/symtab/Type.java
parent90feb7ffbda8d58320ad018a96267c2360ff9f8a (diff)
downloadscala-3d5478d4e16815bbb353eb718d5a1c5e712706d4.tar.gz
scala-3d5478d4e16815bbb353eb718d5a1c5e712706d4.tar.bz2
scala-3d5478d4e16815bbb353eb718d5a1c5e712706d4.zip
- Optimized creation of ThisTypeMaps
Diffstat (limited to 'sources/scalac/symtab/Type.java')
-rw-r--r--sources/scalac/symtab/Type.java46
1 files changed, 28 insertions, 18 deletions
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index 559b462e64..fed9d8055e 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -1572,51 +1572,61 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
* - TypeRef(_, D, _) -> TypeRef(_, Int, _)
*/
private static class ThisTypeMap extends Map {
- private final HashMap/*<Symbol,Type>*/ subst;
- public ThisTypeMap(Symbol clasz, Type type) {
- this.subst = new HashMap();
- initialize(clasz, type);
+ private static Map create(Symbol clasz, Type type) {
+ HashMap subst = getSubst(clasz, type, 0);
+ return subst == null ? IdMap : new ThisTypeMap(subst);
}
- private void initialize(Symbol clasz, Type type) {
+ private static HashMap getSubst(Symbol clasz, Type type, int capacity){
switch (type) {
case NoPrefix:
- return;
+ return getSubst(capacity);
case ThisType(Symbol symbol):
- if (symbol == clasz) return;
+ if (symbol == clasz) return getSubst(capacity);
}
- subst.put(clasz, type);
Type base = type.baseType(clasz);
switch (base) {
case TypeRef(Type prefix, Symbol symbol, Type[] args):
+ capacity += 1 + args.length;
+ HashMap subst = getSubst(clasz.owner(), prefix, capacity);
+ subst.put(clasz, type);
Symbol[] params = clasz.typeParams();
assert symbol == clasz && args.length == params.length:
- type + "@" + Debug.show(clasz) + " -> " + base;
+ type + " @ " + Debug.show(clasz) + " -> " + base;
for (int i = 0; i < params.length; i++) {
assert params[i].isParameter(): Debug.show(params[i]);
subst.put(params[i], args[i]);
}
- initialize(clasz.owner(), prefix);
- break;
+ return subst;
default:
throw Debug.abort("illegal case",
- type + "@" + Debug.show(clasz) + " -> " + base);
+ type + " @ " + Debug.show(clasz) + " -> " + base);
}
}
+ private static HashMap getSubst(int capacity) {
+ return capacity == 0 ? null : new HashMap(capacity);
+ }
+
+ private final HashMap/*<Symbol,Type>*/ subst;
+
+ private ThisTypeMap(HashMap subst) {
+ this.subst = subst;
+ }
+
public Type apply(Type type) {
switch (type) {
case ThisType(Symbol symbol):
- Type lookup = (Type)subst.get(symbol);
+ Object lookup = subst.get(symbol);
if (lookup == null) break;
- return lookup;
- case TypeRef(Type prefix, Symbol symbol, Type[] args):
+ return (Type)lookup;
+ case TypeRef(NoPrefix, Symbol symbol, Type[] args):
if (!symbol.isParameter()) break;
assert args.length == 0: type;
- Type lookup = (Type)subst.get(symbol);
+ Object lookup = subst.get(symbol);
if (lookup == null) break;
- return lookup;
+ return (Type)lookup;
}
return map(type);
}
@@ -1629,7 +1639,7 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
/** Returns a ThisTypeMap of given class and type. */
public static Map getThisTypeMap(Symbol clasz, Type type) {
- return new ThisTypeMap(clasz, type);
+ return ThisTypeMap.create(clasz, type);
}
/** A map for substitutions of thistypes.