Skip to content

Commit

Permalink
Revert imperative Utility.escape from 81d7e2a
Browse files Browse the repository at this point in the history
  • Loading branch information
ashawley committed Feb 7, 2017
1 parent 9cb7579 commit 3b917fb
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,25 +113,12 @@ object Utility extends AnyRef with parsing.TokenTests {
final def escape(text: String, s: StringBuilder): StringBuilder = {
// Implemented per XML spec:
// http://www.w3.org/International/questions/qa-controls
// imperative code 3x-4x faster than current implementation
// dpp (David Pollak) 2010/02/03
val len = text.length
var pos = 0
while (pos < len) {
text.charAt(pos) match {
case '<' => s.append("&lt;")
case '>' => s.append("&gt;")
case '&' => s.append("&amp;")
case '"' => s.append("&quot;")
case '\n' => s.append('\n')
case '\r' => s.append('\r')
case '\t' => s.append('\t')
case c => if (c >= ' ') s.append(c)
text.iterator.foldLeft(s) { (s, c) =>
escMap.get(c) match {
case Some(str) => s ++= str
case _ if c >= ' ' || "\n\r\t".contains(c) => s += c
}

pos += 1
}
s
}

/**
Expand Down

0 comments on commit 3b917fb

Please sign in to comment.