Merge pull request #2532 from WalterCouto/test2

don't unnecessary fetch all tokens when grabbing an interval of text …
This commit is contained in:
Terence Parr 2019-12-11 08:48:54 -08:00 committed by GitHub
commit 8be60804ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -358,17 +358,18 @@ std::string BufferedTokenStream::getSourceName() const
}
std::string BufferedTokenStream::getText() {
fill();
return getText(misc::Interval(0U, size() - 1));
}
std::string BufferedTokenStream::getText(const misc::Interval &interval) {
lazyInit();
fill();
size_t start = interval.a;
size_t stop = interval.b;
if (start == INVALID_INDEX || stop == INVALID_INDEX) {
return "";
}
sync(stop);
if (stop >= _tokens.size()) {
stop = _tokens.size() - 1;
}