Skip to content

Commit b833999

Browse files
committed
Revert imperative Utility.escape from 81d7e2a
1 parent ddc4bb0 commit b833999

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

shared/src/main/scala/scala/xml/Utility.scala

+5-17
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,13 @@ object Utility extends AnyRef with parsing.TokenTests {
110110
final def escape(text: String, s: StringBuilder): StringBuilder = {
111111
// Implemented per XML spec:
112112
// http://www.w3.org/International/questions/qa-controls
113-
// imperative code 3x-4x faster than current implementation
114-
// dpp (David Pollak) 2010/02/03
115-
val len = text.length
116-
var pos = 0
117-
while (pos < len) {
118-
text.charAt(pos) match {
119-
case '<' => s.append("&lt;")
120-
case '>' => s.append("&gt;")
121-
case '&' => s.append("&amp;")
122-
case '"' => s.append("&quot;")
123-
case '\n' => s.append('\n')
124-
case '\r' => s.append('\r')
125-
case '\t' => s.append('\t')
126-
case c => if (c >= ' ') s.append(c)
113+
text.iterator.foldLeft(s) { (s, c) =>
114+
escMap.get(c) match {
115+
case Some(str) => s ++= str
116+
case _ => if c >= ' ' || "\n\r\t".contains(c) => s += c
117+
case _ => s // noop
127118
}
128-
129-
pos += 1
130119
}
131-
s
132120
}
133121

134122
/**

0 commit comments

Comments
 (0)