Reduce string allocation in file_store.rb by 516 bytes (#363)

Reduce string allocation in file_store.rb by 516 bytes (#363)

Before:

Total allocated: 2765 bytes (21 objects)
Total retained:  111 bytes (1 objects)

allocated memory by gem
-----------------------------------
      2765  rack-mini-profiler/lib

allocated memory by file
-----------------------------------
      2765  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb

allocated memory by location
-----------------------------------
      1546  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:19
       596  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:40
       383  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:27
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:153
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:155
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:145
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:29

After:

Total allocated: 2359 bytes (15 objects)
Total retained:  166 bytes (1 objects)

allocated memory by gem
-----------------------------------
      2359  rack-mini-profiler/lib

allocated memory by file
-----------------------------------
      2359  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb

allocated memory by location
-----------------------------------
      1601  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:19
       438  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:27
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:153
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:155
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:40
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:145
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:29
From 51c9abe5d4b90fdc2d616cc8f6cebbc9794a1d68 Mon Sep 17 00:00:00 2001
From: Richard Schneeman <richard.schneeman+no-recruiters@gmail.com>
Date: Sun, 9 Dec 2018 20:38:25 -0600
Subject: [PATCH] Reduce string allocation in file_store.rb by 516 bytes (#363)

Before:

`‍``
Total allocated: 2765 bytes (21 objects)
Total retained:  111 bytes (1 objects)

allocated memory by gem
-----------------------------------
      2765  rack-mini-profiler/lib

allocated memory by file
-----------------------------------
      2765  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb

allocated memory by location
-----------------------------------
      1546  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:19
       596  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:40
       383  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:27
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:153
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:155
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:145
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:29
`‍``

After:

`‍``
Total allocated: 2359 bytes (15 objects)
Total retained:  166 bytes (1 objects)

allocated memory by gem
-----------------------------------
      2359  rack-mini-profiler/lib

allocated memory by file
-----------------------------------
      2359  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb

allocated memory by location
-----------------------------------
      1601  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:19
       438  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:27
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:153
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:155
        80  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:40
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:145
        40  /Users/rschneeman/Dropbox/projects/rack-mini-profiler/lib/mini_profiler/storage/file_store.rb:29
`‍``

diff --git a/lib/mini_profiler/storage/file_store.rb b/lib/mini_profiler/storage/file_store.rb
index 1d11dde..26238ac 100644
--- a/lib/mini_profiler/storage/file_store.rb
+++ b/lib/mini_profiler/storage/file_store.rb
@@ -33,11 +33,11 @@ module Rack
         private
         if RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin|bccwin/
           def path(key)
-            @path + "/" + @prefix  + "_" + key.tr(':', '_')
+            @path.dup << "/" << @prefix  << "_" << key.gsub(/:/, '_')
           end
         else
           def path(key)
-            @path + "/" + @prefix  + "_" + key
+            @path.dup << "/" << @prefix << "_" << key
           end
         end
       end

GitHub