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