Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/model/TypeSystemData.java @ 16814:e8d9b3827d4b
Truffle-DSL: added hashing for type lookups.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Wed, 13 Aug 2014 18:06:18 +0200 |
parents | 23415229349b |
children | b8470fcec3a3 |
comparison
equal
deleted
inserted
replaced
16813:f3a1020472cf | 16814:e8d9b3827d4b |
---|---|
33 public class TypeSystemData extends Template { | 33 public class TypeSystemData extends Template { |
34 | 34 |
35 private List<TypeData> types; | 35 private List<TypeData> types; |
36 private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>(); | 36 private List<TypeMirror> primitiveTypeMirrors = new ArrayList<>(); |
37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); | 37 private List<TypeMirror> boxedTypeMirrors = new ArrayList<>(); |
38 private Map<TypeMirror, TypeData> cachedTypes = new HashMap<>(); | |
38 | 39 |
39 private List<ImplicitCastData> implicitCasts; | 40 private List<ImplicitCastData> implicitCasts; |
40 private List<TypeCastData> casts; | 41 private List<TypeCastData> casts; |
41 private List<TypeCheckData> checks; | 42 private List<TypeCheckData> checks; |
42 | 43 |
56 this.types = types; | 57 this.types = types; |
57 if (types != null) { | 58 if (types != null) { |
58 for (TypeData typeData : types) { | 59 for (TypeData typeData : types) { |
59 primitiveTypeMirrors.add(typeData.getPrimitiveType()); | 60 primitiveTypeMirrors.add(typeData.getPrimitiveType()); |
60 boxedTypeMirrors.add(typeData.getBoxedType()); | 61 boxedTypeMirrors.add(typeData.getBoxedType()); |
62 cachedTypes.put(typeData.getPrimitiveType(), typeData); | |
61 } | 63 } |
62 } | 64 } |
63 } | 65 } |
64 | 66 |
65 public void setImplicitCasts(List<ImplicitCastData> implicitCasts) { | 67 public void setImplicitCasts(List<ImplicitCastData> implicitCasts) { |
150 } | 152 } |
151 return types.get(index); | 153 return types.get(index); |
152 } | 154 } |
153 | 155 |
154 public int findType(TypeMirror type) { | 156 public int findType(TypeMirror type) { |
155 for (int i = 0; i < types.size(); i++) { | 157 TypeData data = cachedTypes.get(type); |
156 if (ElementUtils.typeEquals(types.get(i).getPrimitiveType(), type)) { | 158 if (data != null) { |
157 return i; | 159 return data.getIndex(); |
158 } | |
159 } | 160 } |
160 return -1; | 161 return -1; |
161 } | 162 } |
162 | 163 |
163 @Override | 164 @Override |