Skip to content

Commit

Permalink
Remove flawed caching strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
n1hility committed Sep 9, 2014
1 parent fb66f22 commit 22b3e70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 217 deletions.
138 changes: 7 additions & 131 deletions src/main/java/org/jboss/jandex/GenericSignatureParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,10 @@ MethodSignature parseMethodSignature(String signature) {
}

private Type parseClassTypeSignature() {
int end = scanReferenceTypeEnd();
String signature = this.signature;
NameTable.Slice slice = names.createSlice(signature, pos, end);
Type type = names.getType(slice);

if (type != null) {
this.pos = end;
return type;
}

DotName name = parseName();
Type[] types = parseTypeArguments();
Type type = null;

if (types.length > 0) {
type = new ParameterizedType(name, types, null);
Expand All @@ -305,32 +297,7 @@ private Type parseClassTypeSignature() {
}
}
this.pos++; // ;
type = type != null ? type : new ClassType(name);
names.storeType(slice, type);
return type;
}

private int scanReferenceTypeEnd() {
String signature = this.signature;
int i = pos;
int open = 0;

while (i < signature.length()) {
switch (signature.charAt(i++)) {
case '<':
open++;
break;
case '>':
open--;
break;
case ';':
if (open == 0) {
return i;
}
}
}

throw new IllegalArgumentException("Invalid signature, class type is missing terminator");
return type != null ? type : new ClassType(name);
}

private Type[] parseTypeArguments() {
Expand All @@ -348,14 +315,6 @@ private Type[] parseTypeList(boolean argument) {
}
pos++;

int end = scanListEnd();
NameTable.Slice slice = names.createSlice(signature, pos, end);
Type[] typeList = names.getTypeList(slice);
if (typeList != null) {
this.pos = end;
return typeList;
}

List<Type> types = new ArrayList<Type>();
for (;;) {
Type t = argument ? parseTypeArgument() : parseTypeParameter();
Expand All @@ -364,29 +323,8 @@ private Type[] parseTypeList(boolean argument) {
}
types.add(t);
}
return names.storeTypeList(slice, types.toArray(new Type[types.size()]));
}

private int scanListEnd() {
String signature = this.signature;
int i = pos;
int open = 0;

while (i < signature.length()) {
switch (signature.charAt(i++)) {
case '<':
open++;
break;
case '>':
if (--open < 0) {
return i;
}

break;
}
}

throw new IllegalArgumentException("Invalid signature, class type is missing terminator");
return types.toArray(new Type[types.size()]);
}

private Type parseTypeArgument() {
Expand All @@ -409,16 +347,8 @@ private Type parseTypeArgument() {
}

private Type parseWildCard(boolean isExtends) {
int end = scanReferenceTypeEnd();
NameTable.Slice slice = names.createSlice(signature, pos, end);
Type type = names.getType(slice);
if (type != null) {
pos = end;
return type;
}

Type bound = parseReferenceType();
return names.storeType(slice, new WildcardType(bound, isExtends));
return new WildcardType(bound, isExtends);
}

private Type parseTypeParameter() {
Expand All @@ -430,13 +360,6 @@ private Type parseTypeParameter() {
return null;
}

int end = scanTypeParameterEnd();
NameTable.Slice slice = names.createSlice(signature, start, end);
TypeVariable type = (TypeVariable) names.getType(slice);
if (type != null) {
return type;
}

int bound = advancePast(':');
String name = names.intern(signature.substring(start, bound));

Expand All @@ -453,47 +376,11 @@ private Type parseTypeParameter() {
bounds.add(parseReferenceType());
}

type = new TypeVariable(name, bounds.toArray(new Type[bounds.size()]));
names.storeType(slice, type);
typeParameters.put(type.identifier(), type);
TypeVariable type = new TypeVariable(name, bounds.toArray(new Type[bounds.size()]));
typeParameters.put(name, type);
return type;
}

private int scanTypeParameterEnd() {
String signature = this.signature;
int i = pos;
int open = 0;

while (i < signature.length() - 1) {
char c = signature.charAt(i++);
switch (c) {
case ':': {
char peek = signature.charAt(i);
if (peek != 'T' && peek != 'L' && peek != '[') {
return i;
}
break;
}
case '<':
open++;
break;
case '>':
open--;
break;
case ';':
if (open == 0) {
char peek = signature.charAt(i);
if (peek != ':') {
return i;
}
}
break;
}
}

throw new IllegalArgumentException("Invalid signature, class type is missing terminator");
}

private Type parseReturnType() {
if (signature.charAt(pos) == 'V') {
pos++;
Expand All @@ -520,19 +407,8 @@ private Type parseReferenceType() {

private Type parseArrayType() {
int mark = this.pos;
int end = scanReferenceTypeEnd();
NameTable.Slice slice = names.createSlice(signature, mark, end);

Type type = names.getType(slice);
if (type != null) {
pos = end;
return type;
}

int last = advanceNot('[');
type = new ArrayType(parseJavaType(), last - mark);
names.storeType(slice, type);
return type;
return new ArrayType(parseJavaType(), last - mark);
}

private Type parseTypeVariable() {
Expand Down
86 changes: 0 additions & 86 deletions src/main/java/org/jboss/jandex/NameTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,92 +29,6 @@ class NameTable {
private StrongInternPool<String> stringPool = new StrongInternPool<String>();
private StrongInternPool<DotName> namePool = new StrongInternPool<DotName>();
private Map<String, DotName> names = new HashMap<String, DotName>();
private Map<Slice, Type> types = new HashMap<Slice, Type>();
private Map<Slice, Type[]> typeLists = new HashMap<Slice, Type[]>();

static class Slice {
private final String string;
private final int start;
private final int end;

private Slice(String string, int start, int end) {
this.string = string;
this.start = start;
this.end = end;
}

static Slice create(String string, int start, int end) {
if (start < 0 || start >= end || end < 0 || end > string.length()) {
throw new IllegalArgumentException();
}

return new Slice(string, start, end);
}

public int hashCode() {
int hash = 0;
int start = this.start;
int end = this.end;

for (int i = start; i < end; i++) {
hash = 31 * hash + string.charAt(i);
}

return hash;
}

public boolean equals(Object other) {
if (!(other instanceof Slice)) {
return false;
}

Slice otherSlice = (Slice) other;
int otherStart = otherSlice.start;
int otherEnd = otherSlice.end;
int start = this.start;
int end = this.end;
String otherString = otherSlice.string;
String string = this.string;

if (otherEnd - otherStart != end - start) {
return false;
}

while (start < end) {
if (string.charAt(start++) != otherString.charAt(otherStart++)) {
return false;
}
}

return true;
}

public String toString() {
return string.substring(start, end);
}
}

Slice createSlice(String string, int start,int end) {
return Slice.create(string, start, end);
}

Type getType(Slice slice) {
return types.get(slice);
}

Type storeType(Slice slice, Type type) {
types.put(slice, type);
return type;
}

Type[] getTypeList(Slice slice) {
return typeLists.get(slice);
}

Type[] storeTypeList(Slice slice, Type[] typeList) {
typeLists.put(slice, typeList);
return typeList;
}

DotName convertToName(String name) {
return convertToName(name, '.');
Expand Down

0 comments on commit 22b3e70

Please sign in to comment.