fastParseOn method
Parses buffer starting at position without allocating a Result.
An optimized version of parseOn that gains its speed advantage by avoiding unnecessary memory allocations.
Overridden in most concrete subclasses to implement the optimized logic.
Takes a buffer and the current position in that buffer. Returns a new
(positive) position in case of a successful parse, or -1 in case of a
failure.
Subclasses do not necessarily have to override this method, since it is emulated using parseOn.
Implementation
@override
int fastParseOn(String buffer, int position) {
var count = 0;
var current = position;
while (count < min) {
final result = delegate.fastParseOn(buffer, current);
if (result < 0) return -1;
assert(current < result, '$delegate must always consume');
current = result;
count++;
}
final positions = <int>[current];
while (count < max) {
final result = delegate.fastParseOn(buffer, current);
if (result < 0) break;
assert(current < result, '$delegate must always consume');
positions.add(current = result);
count++;
}
for (;;) {
final limiter = limit.fastParseOn(buffer, positions.last);
if (limiter < 0) {
if (count == 0) return -1;
positions.removeLast();
count--;
if (positions.isEmpty) return -1;
} else {
return positions.last;
}
}
}