Skip to content

Commit

Permalink
Update MessageCompiler.scala
Browse files Browse the repository at this point in the history
inline sb append, ~5x speed up due to unboxed `sb.append(c)`
  • Loading branch information
isaacl authored Jul 1, 2018
1 parent 54f057c commit b6be55e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions project/MessageCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,15 @@ ${content mkString "\n"}
val sb = new java.lang.StringBuilder(s.size + 10) // wet finger style
var i = 0
while (i < s.length) {
sb.append {
s.charAt(i) match {
case '<' => "&lt;";
case '>' => "&gt;";
case '&' => "&amp;";
case '"' => "&quot;";
case '\'' => "&#39;";
case '\r' => "";
case '\n' => "<br />";
case c => c
}
s.charAt(i) match {
case '<' => sb append "&lt;"
case '>' => sb append "&gt;"
case '&' => sb append "&amp;"
case '"' => sb append "&quot;"
case '\'' => sb append "&#39;"
case '\r' => ()
case '\n' => sb append "<br />"
case c => sb append c
}
i += 1
}
Expand Down

0 comments on commit b6be55e

Please sign in to comment.