Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenquotes.git

Remove counting of skipped characters for performance boost

AuthorDave Jarvis <email>
Date2022-08-13 16:47:45 GMT-0700
Commita511db7a8b8a1fa79a9a2460a52d79888ada1db2
Parentcd880ed
src/main/java/com/whitemagicsoftware/keenquotes/FastCharacterIterator.java
* Parse all characters that match a given function.
*
- * @param f The function that determines when slurping stops.
- * @return The number of characters parsed.
+ * @param f The function that determines when skipping stops.
*/
- public int skip( final Function<Character, Boolean> f ) {
+ public void skip( final Function<Character, Boolean> f ) {
assert f != null;
-
- final var began = index();
do {
next();
}
while( f.apply( current() ) );
// The loop always overshoots by one character.
prev();
-
- return index() - began;
}
src/main/java/com/whitemagicsoftware/keenquotes/Lexer.java
}
else if( curr == '.' ) {
- token =
- i.skip( next -> next == '.' || next == ' ' && i.peek() == '.' ) == 0
- ? PERIOD
- : ELLIPSIS;
+ final var start = i.index();
+
+ i.skip( next -> next == '.' || next == ' ' && i.peek() == '.' );
+
+ token = i.index() - start == 0 ? PERIOD : ELLIPSIS;
}
else if( curr == '"' ) {
Delta7 lines added, 11 lines removed, 4-line decrease