Move Tokens::operator and optimize the common path

This commit is contained in:
Raúl Marín 2022-10-14 16:20:56 +02:00
parent 96a1cb4a79
commit 7b96a7b798
2 changed files with 20 additions and 16 deletions

View File

@ -4,6 +4,25 @@
namespace DB
{
const Token & Tokens::operator[](size_t index)
{
if (likely(index < data.size()))
return data[index];
while (data.empty() || !data.back().isEnd())
{
Token token = lexer.nextToken();
if (token.isSignificant())
{
data.emplace_back(std::move(token));
if (index < data.size())
return data[index];
}
}
return data.back();
}
UnmatchedParentheses checkUnmatchedParentheses(TokenIterator begin)
{
/// We have just two kind of parentheses: () and [].

View File

@ -25,22 +25,7 @@ private:
public:
Tokens(const char * begin, const char * end, size_t max_query_size = 0) : lexer(begin, end, max_query_size) {}
const Token & operator[] (size_t index)
{
while (true)
{
if (index < data.size())
return data[index];
if (!data.empty() && data.back().isEnd())
return data.back();
Token token = lexer.nextToken();
if (token.isSignificant())
data.emplace_back(token);
}
}
const Token & operator[](size_t index);
const Token & max()
{