fasterer 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 606c81ada0fb247e236a2f92ae042f363b5f4cbf
4
- data.tar.gz: 323879b3d6230968fd2207d41d85ac697700d1c7
3
+ metadata.gz: 48ef235d9ddbd7e96e9e40c0543f593488f614f9
4
+ data.tar.gz: 43e7c00823bf1d792adef3bcf62e17b2c9a7f30b
5
5
  SHA512:
6
- metadata.gz: 444e1a9af93389bfe9a05adb3f03af1d689ee0f461ff35568a449493e4c85af73890fabf231e94341ae48d7e27611bf582fc9102e4286265d00e220d352c39ee
7
- data.tar.gz: 496a9e543b07ef7cb190a765387391a2b1bc0c5dcfbc823f49cb735749d6ff48b1677efdc81404ee8665bf9b4d07633ca471d41df970a740257d0935b7f8d8e6
6
+ metadata.gz: bdf479d3be8d49e4a9fcc9a287c96673d0e17590cf3b4e64602178a7dd04197ecee65e604eace3d1bdf453cfdfeedd38a08872dac646111a90fe69dd5e778b0b
7
+ data.tar.gz: 9ba93e58e71713d66aa2d0ef2465e13eabf9f1e91335c862add5bd6ddbdb779969b002f3cb968d454ec81ebff1eb254f8ecb5a69834714ddfb430991068e01a3
data/.fasterer.yml CHANGED
@@ -8,6 +8,7 @@ speedups:
8
8
  map_flatten_vs_flat_map: true
9
9
  reverse_each_vs_reverse_each: true
10
10
  select_first_vs_detect: true
11
+ select_last_vs_reverse_detect: true
11
12
  sort_vs_sort_by: true
12
13
  fetch_with_argument_vs_block: true
13
14
  keys_each_vs_each_key: true
data/fasterer.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake', '~> 10.0'
26
- spec.add_development_dependency 'rspec', '~> 3.1'
26
+ spec.add_development_dependency 'rspec', '~> 3.2'
27
27
  spec.add_development_dependency 'pry', '~> 0.10'
28
28
  end
@@ -62,7 +62,10 @@ module Fasterer
62
62
  'Calling blocks with call is slower than yielding',
63
63
 
64
64
  gsub_vs_tr:
65
- 'Using tr is faster than gsub when replacing a single character in a string with another single character'
65
+ 'Using tr is faster than gsub when replacing a single character in a string with another single character',
66
+
67
+ select_last_vs_reverse_detect:
68
+ 'Array#select.last is slower than Array#reverse.detect'
66
69
  }
67
70
 
68
71
  end
@@ -39,6 +39,8 @@ module Fasterer
39
39
  check_fetch_offense
40
40
  when :merge!
41
41
  check_merge_bang_offense
42
+ when :last
43
+ check_last_offense
42
44
  end
43
45
  end
44
46
 
@@ -142,5 +144,14 @@ module Fasterer
142
144
  end
143
145
  end
144
146
 
147
+ def check_last_offense
148
+ return method_call unless method_call.receiver.is_a?(MethodCall)
149
+
150
+ case method_call.receiver.name
151
+ when :select
152
+ add_offense(:select_last_vs_reverse_detect)
153
+ end
154
+ end
155
+
145
156
  end
146
157
  end
@@ -1,3 +1,3 @@
1
1
  module Fasterer
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fasterer::Analyzer do
4
+
5
+ let(:test_file_path) { RSpec.root.join('support', 'analyzer', '25_select_last_vs_reverse_detect.rb') }
6
+
7
+ it 'should detect select last once' do
8
+ analyzer = Fasterer::Analyzer.new(test_file_path)
9
+ analyzer.scan
10
+ expect(analyzer.errors[:select_last_vs_reverse_detect].count).to eq(1)
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ def slow
2
+ ARRAY.select { |x| (x % 10).zero? }.last
3
+ end
4
+
5
+ def fast
6
+ ARRAY.reverse.detect { |x| (x % 10).zero? }
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fasterer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damir Svrtan
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.1'
75
+ version: '3.2'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.1'
82
+ version: '3.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +147,7 @@ files:
147
147
  - spec/lib/fasterer/analyzer/18_block_vs_symbol_to_proc_spec.rb
148
148
  - spec/lib/fasterer/analyzer/19_proc_call_vs_yield_spec.rb
149
149
  - spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb
150
+ - spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
150
151
  - spec/lib/fasterer/analyzer/98_misc_spec.rb
151
152
  - spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
152
153
  - spec/lib/fasterer/method_call_spec.rb
@@ -170,6 +171,7 @@ files:
170
171
  - spec/support/analyzer/18_block_vs_symbol_to_proc.rb
171
172
  - spec/support/analyzer/19_proc_call_vs_yield.rb
172
173
  - spec/support/analyzer/24_gsub_vs_tr.rb
174
+ - spec/support/analyzer/25_select_last_vs_reverse_detect.rb
173
175
  - spec/support/analyzer/98_misc.rb
174
176
  - spec/support/analyzer/99_exceptional_files.rb
175
177
  - spec/support/binary_call/simple_comparison.rb
@@ -244,6 +246,7 @@ test_files:
244
246
  - spec/lib/fasterer/analyzer/18_block_vs_symbol_to_proc_spec.rb
245
247
  - spec/lib/fasterer/analyzer/19_proc_call_vs_yield_spec.rb
246
248
  - spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb
249
+ - spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
247
250
  - spec/lib/fasterer/analyzer/98_misc_spec.rb
248
251
  - spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
249
252
  - spec/lib/fasterer/method_call_spec.rb
@@ -267,6 +270,7 @@ test_files:
267
270
  - spec/support/analyzer/18_block_vs_symbol_to_proc.rb
268
271
  - spec/support/analyzer/19_proc_call_vs_yield.rb
269
272
  - spec/support/analyzer/24_gsub_vs_tr.rb
273
+ - spec/support/analyzer/25_select_last_vs_reverse_detect.rb
270
274
  - spec/support/analyzer/98_misc.rb
271
275
  - spec/support/analyzer/99_exceptional_files.rb
272
276
  - spec/support/binary_call/simple_comparison.rb