Skip to content

Commit f128625

Browse files
committed
Reduce allocations by extracting inline Hash to a constant
Intuitively, I would rather use `case` statement if RuboCop allows, but... 🤷
1 parent c81b52d commit f128625

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/simplecov-html.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,20 @@ def assets_path(name)
8484
File.join("./assets", SimpleCov::Formatter::HTMLFormatter::VERSION, name)
8585
end
8686

87+
# Only have a few content types, just hardcode them
88+
CONTENT_TYPES = {
89+
".js" => "text/javascript",
90+
".png" => "image/png",
91+
".gif" => "image/gif",
92+
".css" => "text/css",
93+
}.freeze
94+
8795
def asset_inline(name)
8896
path = File.join(@public_assets_dir, name)
97+
base64_content = Base64.strict_encode64 File.read(path)
8998

90-
# Only have a few content types, just hardcode them
91-
content_type = {
92-
".js" => "text/javascript",
93-
".png" => "image/png",
94-
".gif" => "image/gif",
95-
".css" => "text/css",
96-
}[File.extname(name)]
99+
content_type = CONTENT_TYPES[File.extname(name)]
97100

98-
base64_content = Base64.strict_encode64 File.read(path)
99101
"data:#{content_type};base64,#{base64_content}"
100102
end
101103

0 commit comments

Comments
 (0)