Skip to content

Commit

Permalink
Make SymbolLookup.indexOrThrow() more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
FourteenBrush committed Jun 20, 2024
1 parent a96cb91 commit 7d1769d
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class SymbolLookup {
* @throws SyntaxException when this symbol is already inserted.
*/
public void insert(Symbol symbol) {
// TODO: maybe have some "trusted" insert that doesn't validate symbol name again
putVal(symbol, true);
}

Expand Down Expand Up @@ -202,10 +203,12 @@ char getCharacter() {
}

private static int indexOrThrow(char value) {
// TODO: optimize calls
Assert.isTrue(value <= MAX_RANGE_CHAR, "character %s is not allowed in a symbol name", value);
byte idx = indexLookup[value];
Assert.isTrue(idx != INVALID_IDX, "character %s is not allowed in a symbol name", value);
int idx = -1; // dummy value to make the compiler stop complaining

Assert.isTrue(
value <= MAX_RANGE_CHAR && (idx = indexLookup[value]) != INVALID_IDX,
"character %s is not allowed in a symbol name", value
);
return idx;
}

Expand Down

0 comments on commit 7d1769d

Please sign in to comment.