From b1445d09b6d2b0e573f37b6b0de10fec949861ca Mon Sep 17 00:00:00 2001 From: rubic0n Date: Thu, 18 Feb 2021 00:45:21 -0600 Subject: [PATCH] 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. --- app/lib/formatter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 21cd4f17..068fab7c 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -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