Permalink
Browse files

avoid copying entire payload just to calc md5

  • Loading branch information...
1 parent 0adc7ce commit 16a0033784a459563140e4f3df2c4973f105bbf9 @SamSaffron committed Sep 9, 2013
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/rack/etag.rb
View
@@ -55,10 +55,14 @@ def skip_caching?(headers)
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?
@SamSaffron

SamSaffron Sep 9, 2013

Owner

should this be part && part.empty? since [nil].join == ""

+ end
+
+ [digest && digest.hexdigest, parts]
end
end
end

0 comments on commit 16a0033

Please sign in to comment.