Skip to content

Commit

Permalink
Cleanup new symbol allocation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
pettyjamesm authored and sopel39 committed Jan 24, 2022
1 parent ca0946b commit ff8efb2
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import io.trino.sql.tree.Identifier;
import io.trino.sql.tree.SymbolReference;

import javax.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -67,7 +69,7 @@ public Symbol newHashSymbol()
return newSymbol("$hashValue", BigintType.BIGINT);
}

public Symbol newSymbol(String nameHint, Type type, String suffix)
public Symbol newSymbol(String nameHint, Type type, @Nullable String suffix)
{
requireNonNull(nameHint, "nameHint is null");
requireNonNull(type, "type is null");
Expand All @@ -92,13 +94,11 @@ public Symbol newSymbol(String nameHint, Type type, String suffix)
unique = unique + "$" + suffix;
}

String attempt = unique;
while (symbols.containsKey(new Symbol(attempt))) {
attempt = unique + "_" + nextId();
Symbol symbol = new Symbol(unique);
while (symbols.putIfAbsent(symbol, type) != null) {
symbol = new Symbol(unique + "_" + nextId());
}

Symbol symbol = new Symbol(attempt);
symbols.put(symbol, type);
return symbol;
}

Expand Down

0 comments on commit ff8efb2

Please sign in to comment.