diff options
author | Sam <sam.saffron@gmail.com> | 2013-09-09 16:24:10 +1000 |
---|---|---|
committer | Sam <sam.saffron@gmail.com> | 2013-09-10 00:22:06 +1000 |
commit | 16a0033784a459563140e4f3df2c4973f105bbf9 (patch) | |
tree | cc3cf0615897d30720b40e536373cc08a366bba0 | |
parent | 0adc7ceb9359426fee21d5e554dd62ec7d535e34 (diff) | |
download | rack-16a0033784a459563140e4f3df2c4973f105bbf9.tar.gz |
avoid copying entire payload just to calc md5
-rw-r--r-- | lib/rack/etag.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/rack/etag.rb b/lib/rack/etag.rb index 3f5006a6..5fa09abd 100644 --- a/lib/rack/etag.rb +++ b/lib/rack/etag.rb @@ -55,10 +55,14 @@ module Rack def digest_body(body) parts = [] - body.each { |part| parts << part } - string_body = parts.join - digest = Digest::MD5.hexdigest(string_body) unless string_body.empty? - [digest, parts] + digest = nil + + body.each do |part| + parts << part + (digest ||= Digest::MD5.new) << part unless part.empty? + end + + [digest && digest.hexdigest, parts] end end end |