diff --git a/src/Parsers/TokenIterator.cpp b/src/Parsers/TokenIterator.cpp index 08877e0b2fe..ecff8b0d482 100644 --- a/src/Parsers/TokenIterator.cpp +++ b/src/Parsers/TokenIterator.cpp @@ -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 []. diff --git a/src/Parsers/TokenIterator.h b/src/Parsers/TokenIterator.h index b84bec57817..62570f49358 100644 --- a/src/Parsers/TokenIterator.h +++ b/src/Parsers/TokenIterator.h @@ -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() {