提交 75ee4d97 编写于 作者: S Santiago Pastorino

Merge pull request #3464 from kennyj/avoid_to_call_twice

avoided to call `Marshal.dump` twice
...@@ -559,7 +559,7 @@ def initialize(value, options = {}) ...@@ -559,7 +559,7 @@ def initialize(value, options = {})
@value = nil @value = nil
else else
@value = Marshal.dump(value) @value = Marshal.dump(value)
if should_compress?(value, options) if should_compress?(@value, options)
@value = Zlib::Deflate.deflate(@value) @value = Zlib::Deflate.deflate(@value)
@compressed = true @compressed = true
end end
...@@ -613,14 +613,11 @@ def size ...@@ -613,14 +613,11 @@ def size
end end
private private
def should_compress?(value, options) def should_compress?(serialized_value, options)
if options[:compress] && value if options[:compress]
unless value.is_a?(Numeric)
compress_threshold = options[:compress_threshold] || DEFAULT_COMPRESS_LIMIT compress_threshold = options[:compress_threshold] || DEFAULT_COMPRESS_LIMIT
serialized_value = value.is_a?(String) ? value : Marshal.dump(value)
return true if serialized_value.size >= compress_threshold return true if serialized_value.size >= compress_threshold
end end
end
false false
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册