compareToString method
Compares against a decoded string without allocating one.
Returns a negative number, zero or a positive number following the same ordering as compareTo.
Implementation
int compareToString(String other) {
var i = start;
var j = 0;
while (i < end && j < other.length) {
final unit = other.codeUnitAt(j);
final (rune, bytesUsed) = _runeAt(bytes, i, end);
if (rune < 0) return 1; // malformed bytes sort after valid text
final otherRune = unit >= 0xD800 && unit <= 0xDBFF
? 0x10000 +
((unit - 0xD800) << 10) +
(other.codeUnitAt(j + 1) - 0xDC00)
: unit;
final diff = rune - otherRune;
if (diff != 0) return diff;
i += bytesUsed;
j += otherRune > 0xFFFF ? 2 : 1;
}
return (end - i) - (other.length - j);
}