Skip to content

Commit 03b442b

Browse files
committed
use only one size? and no size calls on dst in default optimized? implementation, resolves #137
1 parent 666a97f commit 03b442b

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Add proper handling of `ImageOptim.respond_to?` [@toy](https://github.com/toy)
66
* Fix an issue not working OptiPNG `interlace` option [#136](https://github.com/toy/image_optim/pull/136) [@mrk21](https://github.com/mrk21)
7+
* Minimize number of file system calls in default implementation of `optimized?` [#137](https://github.com/toy/image_optim/issues/137) [@toy](https://github.com/toy)
78

89
## v0.23.0 (2016-07-17)
910

lib/image_optim/worker.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def resolve_used_bins!
7373

7474
# Check if operation resulted in optimized file
7575
def optimized?(src, dst)
76-
dst.size? && dst.size < src.size
76+
dst_size = dst.size?
77+
dst_size && dst_size < src.size
7778
end
7879

7980
# Short inspect

spec/image_optim/worker/optipng_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
describe '#optimized?' do
6060
let(:src){ instance_double(ImageOptim::Path, src_options) }
6161
let(:dst){ instance_double(ImageOptim::Path, dst_options) }
62-
let(:src_options){ {:size? => 10, :size => 10} }
63-
let(:dst_options){ {:size? => 9, :size => 9} }
62+
let(:src_options){ {:size => 10} }
63+
let(:dst_options){ {:size? => 9} }
6464
let(:instance){ described_class.new(ImageOptim.new, instance_options) }
6565
let(:instance_options){ {} }
6666

@@ -75,7 +75,7 @@
7575
end
7676

7777
context 'when dst is not empty' do
78-
let(:dst_options){ {:size? => 20, :size => 20} }
78+
let(:dst_options){ {:size? => 20} }
7979
it{ is_expected.to be_truthy }
8080
end
8181
end
@@ -89,12 +89,12 @@
8989
end
9090

9191
context 'when dst is greater than or equal to src' do
92-
let(:dst_options){ {:size? => 10, :size => 10} }
92+
let(:dst_options){ {:size? => 10} }
9393
it{ is_expected.to be_falsy }
9494
end
9595

9696
context 'when dst is less than src' do
97-
let(:dst_options){ {:size? => 9, :size => 9} }
97+
let(:dst_options){ {:size? => 9} }
9898
it{ is_expected.to be_truthy }
9999
end
100100
end

0 commit comments

Comments
 (0)