Skip to content

Commit

Permalink
micro optimization to tuple parsing;
Browse files Browse the repository at this point in the history
make some local vars explicitly final;
  • Loading branch information
esaulpaugh committed Jan 16, 2021
1 parent 7dcc615 commit 822f436
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/java/com/esaulpaugh/headlong/abi/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private static ABIType<?> buildType(final String rawType, ABIType<?> baseType) {
throw new IllegalArgumentException("unrecognized type: \"" + rawType + '"');
}

private static int parseLen(String lenStr) {
private static int parseLen(final String lenStr) {
try {
if(leadDigitValid(lenStr.charAt(0)) || lenStr.equals("0")) {
final int length = Integer.parseInt(lenStr);
Expand All @@ -153,7 +153,7 @@ private static int parseLen(String lenStr) {
throw new IllegalArgumentException("bad array length");
}

private static ABIType<?> resolveBaseType(String baseTypeStr) {
private static ABIType<?> resolveBaseType(final String baseTypeStr) {
if(baseTypeStr.charAt(0) == '(') {
return parseTupleType(baseTypeStr);
}
Expand All @@ -170,8 +170,8 @@ private static BigDecimalType tryParseFixed(final String type) {
final String mStr = type.substring(idx + "fixed".length(), indexOfX);
final String nStr = type.substring(indexOfX + 1); // everything after x
if (leadDigitValid(mStr.charAt(0)) && leadDigitValid(nStr.charAt(0))) {
int M = Integer.parseInt(mStr); // no parseUnsignedInt on Android?
int N = Integer.parseInt(nStr);
final int M = Integer.parseInt(mStr); // no parseUnsignedInt on Android?
final int N = Integer.parseInt(nStr);
if (Integers.mod(M, 8) == 0 && M >= 8 && M <= 256 && N > 0 && N <= 80) {
return new BigDecimalType((unsigned ? "ufixed" : "fixed") + M + 'x' + N, M, N, unsigned);
}
Expand Down Expand Up @@ -247,11 +247,14 @@ private static int findSubtupleEnd(String parentTypeString, int i) {

private static int nextTerminator(String signature, int i) {
final int comma = signature.indexOf(',', i);
final int close = signature.indexOf(')', i);
return comma == -1
? close
: close == -1
? comma
: Math.min(comma, close);
if(comma < 0) {
return signature.indexOf(')', i);
}
for ( ; i < comma; i++) {
if (signature.charAt(i) == ')') {
return i;
}
}
return comma;
}
}

0 comments on commit 822f436

Please sign in to comment.