Skip to content

Commit

Permalink
Merge pull request #67 from sparsetech/feat/parser-performance
Browse files Browse the repository at this point in the history
Improve performance of HTML parser on JVM
  • Loading branch information
tindzk authored Oct 3, 2020
2 parents 1c37d02 + 8e70cc9 commit 7a0d566
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/scala/pine/Reader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ private[pine] class Reader(data: String) {
def lookahead(value: Char): Boolean = data(offset) == value

/** Returns true if `value` matches */
def lookahead(value: String): Boolean = rest().startsWith(value)
def lookahead(value: String): Boolean = {
if (value.length > data.length - offset) false
else {
var i = 0
while (i < value.length) {
if (value(i) != data(offset + i)) return false
i += 1
}

true
}
}

/** Returns true if `value` matches and places pointer afterwards */
def prefix(value: Char): Boolean =
Expand All @@ -31,7 +42,7 @@ private[pine] class Reader(data: String) {

/** Returns true if `value` matches and places pointer afterwards */
def prefix(value: String): Boolean =
rest().startsWith(value) && {
lookahead(value) && {
offset += value.length
true
}
Expand Down

0 comments on commit 7a0d566

Please sign in to comment.