Browse files

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.
  • Loading branch information...
1 parent e01aba1 commit ad912c08a91b90f6a7b30ae75b4a3a5f6c513bd4 @fxn fxn committed Jul 8, 2011
Showing with 4 additions and 3 deletions.
  1. +2 −2 actionpack/lib/action_view/asset_paths.rb
  2. +2 −1 actionpack/test/template/asset_tag_helper_test.rb
View
4 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 @@ def compute_asset_host(source)
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
View
3 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 @@ def test_caching_javascript_include_tag_when_caching_on_and_using_subdirectory
@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(
%(<script src="http://a#{number}.example.com/javascripts/cache/money.js" type="text/javascript"></script>),
javascript_include_tag(:all, :cache => "cache/money")

4 comments on commit ad912c0

@josevalim
Ruby on Rails member

Who is Aaron?

@fxn
Ruby on Rails member

Excuse me, should the message say Señor Aaron :).

@tenderlove
Ruby on Rails member

meow meow meow!

@sikachu
Ruby on Rails member

🐱 🐱 🐱

Please sign in to comment.