File tree Expand file tree Collapse file tree 1 file changed +5
-17
lines changed
shared/src/main/scala/scala/xml Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Original file line number Diff line number Diff 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(" <" )
120- case '>' => s.append(" >" )
121- case '&' => s.append(" &" )
122- case '"' => s.append(" "" )
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 /**
You can’t perform that action at this time.
0 commit comments