From ad912c08a91b90f6a7b30ae75b4a3a5f6c513bd4 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Fri, 8 Jul 2011 00:58:14 +0200 Subject: use Zlib.crc2 rather that bytes.sum, as per Aaron's suggestion That integer is rather irrelevant, the only thing that matters is that it is consistent and with no apparent bias. Zlib.crc32 is 8-10 times faster than bytes.sum, so use that. --- actionpack/lib/action_view/asset_paths.rb | 4 ++-- actionpack/test/template/asset_tag_helper_test.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_view/asset_paths.rb b/actionpack/lib/action_view/asset_paths.rb index 77a8c5322f..96d8fd0dfe 100644 --- a/actionpack/lib/action_view/asset_paths.rb +++ b/actionpack/lib/action_view/asset_paths.rb @@ -1,3 +1,4 @@ +require 'zlib' require 'active_support/core_ext/file' module ActionView @@ -111,8 +112,7 @@ module ActionView args << current_request if (arity > 1 || arity < 0) && has_request? host.call(*args) else - source_num = source.bytes.sum - (host =~ /%d/) ? host % (source_num % 4) : host + (host =~ /%d/) ? host % (Zlib.crc32(source) % 4) : host end end end diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb index 717e0e9065..d5bd7256f7 100644 --- a/actionpack/test/template/asset_tag_helper_test.rb +++ b/actionpack/test/template/asset_tag_helper_test.rb @@ -1,3 +1,4 @@ +require 'zlib' require 'abstract_unit' require 'active_support/ordered_options' @@ -689,7 +690,7 @@ class AssetTagHelperTest < ActionView::TestCase @controller.config.asset_host = 'http://a%d.example.com' config.perform_caching = true - number = '/javascripts/cache/money.js'.bytes.sum % 4 + number = Zlib.crc32('/javascripts/cache/money.js') % 4 assert_dom_equal( %(), javascript_include_tag(:all, :cache => "cache/money") -- cgit v1.2.3