Skip to content

Commit 070f48a

Browse files
committed
Revert imperative Utility.escape from 81d7e2a
1 parent 2ee8750 commit 070f48a

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

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

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

136123
/**

0 commit comments

Comments
 (0)