Skip to content

Commit b78d0be

Browse files
committed
Revert imperative Utility.escape from 81d7e2a
1 parent 5b53104 commit b78d0be

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

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

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

137124
/**

0 commit comments

Comments
 (0)