Remove 40KB of allocations (4,100 objects) from home feed

(When using dummy data)

* to_s(16) allocates a string per character
  Instead of converting the ord to hex and determining if the hex
  is over 2 characters long, just see if the ord is over 255.
* .match allocates a MatchData instance and sets all sorts of backrefs
  ($1, $2, etc). match? just returns a boolean.
This commit is contained in:
rubic0n 2021-02-18 00:45:21 -06:00
parent 006322cff7
commit b1445d09b6

View File

@ -370,7 +370,7 @@ class Formatter
escaped = text.chars.map do |c|
output = begin
if c.ord.to_s(16).length > 2 && UNICODE_ESCAPE_BLACKLIST_RE.match(c).nil?
if c.ord > 255 && !UNICODE_ESCAPE_BLACKLIST_RE.match?(c)
CGI.escape(c)
else
c