aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorDillon Welch <daw0328@gmail.com>2018-03-29 19:29:55 -0700
committerDillon Welch <daw0328@gmail.com>2018-07-23 15:37:06 -0700
commitd108288c2f684233298f97f18ac00de0b016deaa (patch)
tree0656fd6f20d662d854a3fc93e80dfbc0baec063d /activesupport
parenta4398e412c042b297039cc216f6536b0c048bd9c (diff)
downloadrails-d108288c2f684233298f97f18ac00de0b016deaa.tar.gz
rails-d108288c2f684233298f97f18ac00de0b016deaa.tar.bz2
rails-d108288c2f684233298f97f18ac00de0b016deaa.zip
Turn on performance based cops
Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb6
-rw-r--r--activesupport/lib/active_support/message_encryptor.rb4
-rw-r--r--activesupport/lib/active_support/testing/parallelization.rb16
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb4
-rw-r--r--activesupport/test/cache/stores/redis_cache_store_test.rb4
5 files changed, 12 insertions, 22 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index a1b841ec3d..c266b432c0 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -497,9 +497,7 @@ module ActiveSupport
arg.halted || !@user_conditions.all? { |c| c.call(arg.target, arg.value) }
end
- def nested
- @nested
- end
+ attr_reader :nested
def final?
!@call_template
@@ -578,7 +576,7 @@ module ActiveSupport
end
protected
- def chain; @chain; end
+ attr_reader :chain
private
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb
index 8b73270894..404404cad1 100644
--- a/activesupport/lib/active_support/message_encryptor.rb
+++ b/activesupport/lib/active_support/message_encryptor.rb
@@ -210,9 +210,7 @@ module ActiveSupport
OpenSSL::Cipher.new(@cipher)
end
- def verifier
- @verifier
- end
+ attr_reader :verifier
def aead_mode?
@aead_mode ||= new_cipher.authenticated?
diff --git a/activesupport/lib/active_support/testing/parallelization.rb b/activesupport/lib/active_support/testing/parallelization.rb
index 59c8486f41..1caac1feb3 100644
--- a/activesupport/lib/active_support/testing/parallelization.rb
+++ b/activesupport/lib/active_support/testing/parallelization.rb
@@ -26,25 +26,21 @@ module ActiveSupport
def pop; @queue.pop; end
end
- @after_fork_hooks = []
+ @@after_fork_hooks = []
def self.after_fork_hook(&blk)
- @after_fork_hooks << blk
+ @@after_fork_hooks << blk
end
- def self.after_fork_hooks
- @after_fork_hooks
- end
+ cattr_reader :after_fork_hooks
- @run_cleanup_hooks = []
+ @@run_cleanup_hooks = []
def self.run_cleanup_hook(&blk)
- @run_cleanup_hooks << blk
+ @@run_cleanup_hooks << blk
end
- def self.run_cleanup_hooks
- @run_cleanup_hooks
- end
+ cattr_reader :run_cleanup_hooks
def initialize(queue_size)
@queue_size = queue_size
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 792c88415c..fd07a3a6a2 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -265,7 +265,7 @@ module ActiveSupport
private
def load_country_zones(code)
country = TZInfo::Country.get(code)
- country.zone_identifiers.map do |tz_id|
+ country.zone_identifiers.flat_map do |tz_id|
if MAPPING.value?(tz_id)
MAPPING.inject([]) do |memo, (key, value)|
memo << self[key] if value == tz_id
@@ -274,7 +274,7 @@ module ActiveSupport
else
create(tz_id, nil, TZInfo::Timezone.new(tz_id))
end
- end.flatten(1).sort!
+ end.sort!
end
def zones_map
diff --git a/activesupport/test/cache/stores/redis_cache_store_test.rb b/activesupport/test/cache/stores/redis_cache_store_test.rb
index 3b873de383..305a2c184d 100644
--- a/activesupport/test/cache/stores/redis_cache_store_test.rb
+++ b/activesupport/test/cache/stores/redis_cache_store_test.rb
@@ -103,9 +103,7 @@ module ActiveSupport::Cache::RedisCacheStoreTests
private
def build(**kwargs)
- ActiveSupport::Cache::RedisCacheStore.new(driver: DRIVER, **kwargs).tap do |cache|
- cache.redis
- end
+ ActiveSupport::Cache::RedisCacheStore.new(driver: DRIVER, **kwargs).tap(&:redis)
end
end