diff options
author | schneems <richard.schneeman+foo@gmail.com> | 2018-09-06 10:05:00 -0500 |
---|---|---|
committer | schneems <richard.schneeman+foo@gmail.com> | 2018-09-06 10:13:42 -0500 |
commit | 8eb3cd8e56eacb9e0054326a0c0545a7b64c1c22 (patch) | |
tree | f0626b91117da5d845822027ad2bd44ac6343e6a /activesupport/lib | |
parent | 12fadea8aee3981654149d6e8ff5099bca31c679 (diff) | |
download | rails-8eb3cd8e56eacb9e0054326a0c0545a7b64c1c22.tar.gz rails-8eb3cd8e56eacb9e0054326a0c0545a7b64c1c22.tar.bz2 rails-8eb3cd8e56eacb9e0054326a0c0545a7b64c1c22.zip |
Faster File Store
Memory before 1826584.8 memory after: 1797795.6 difference: 1.58% memory (speed) savings.
When the key is not longer than the limit we can avoid allocating two strings and an array.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/cache/file_store.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/cache/file_store.rb b/activesupport/lib/active_support/cache/file_store.rb index a0f44aac0f..04c54c30d0 100644 --- a/activesupport/lib/active_support/cache/file_store.rb +++ b/activesupport/lib/active_support/cache/file_store.rb @@ -127,15 +127,19 @@ module ActiveSupport hash = Zlib.adler32(fname) hash, dir_1 = hash.divmod(0x1000) dir_2 = hash.modulo(0x1000) - fname_paths = [] # Make sure file name doesn't exceed file system limits. - begin - fname_paths << fname[0, FILENAME_MAX_SIZE] - fname = fname[FILENAME_MAX_SIZE..-1] - end until fname.blank? + if fname.length < FILENAME_MAX_SIZE + fname_paths = fname + else + fname_paths = [] + begin + fname_paths << fname[0, FILENAME_MAX_SIZE] + fname = fname[FILENAME_MAX_SIZE..-1] + end until fname.blank? + end - File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, *fname_paths) + File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, fname_paths) end # Translate a file path into a key. |