fastParseOn method

  1. @override
  2. @noBoundsChecks
int fastParseOn(
  1. String buffer,
  2. int position
)
override

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
@noBoundsChecks
int fastParseOn(String buffer, int position) {
  if (position < buffer.length) {
    var codeUnit = buffer.codeUnitAt(position++);
    if (_isLeadSurrogate(codeUnit) && position < buffer.length) {
      final nextCodeUnit = buffer.codeUnitAt(position);
      if (_isTrailSurrogate(nextCodeUnit)) {
        codeUnit = _combineSurrogatePair(codeUnit, nextCodeUnit);
        position++;
      }
    }
    if (predicate.test(codeUnit)) {
      return position;
    }
  }
  return -1;
}