diff options
author | Rémy Coutable <remy@rymai.me> | 2016-05-11 08:59:44 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-05-11 08:59:44 +0000 |
commit | e77a9a342e175c7274350ef6d655bde496eca778 (patch) | |
tree | 0eb8e88db37a165b9098960caa32d0cf09ba52f1 | |
parent | de5ae1bf0604c9d250145e2c6aeaa0adfdc760bf (diff) | |
parent | 377583a361988d9884808a3c3f5375497a9d5b56 (diff) | |
download | gitlab-ce-e77a9a342e175c7274350ef6d655bde496eca778.tar.gz |
Merge branch 'casecmp-cop' into 'master'
Enable Rubocop Casecmp Performance Cop.
Also fixes the errors caused by enabling the cop.
`casecmp` is more performant than `.downcase` and `==`.
See also: https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/performance/casecmp.rb
See merge request !3957
-rw-r--r-- | .rubocop.yml | 3 | ||||
-rw-r--r-- | app/models/repository.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/database.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/markup_helper.rb | 2 |
4 files changed, 5 insertions, 6 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index c96c7123c16..ccceea45963 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -937,10 +937,9 @@ Lint/Void: ##################### Performance ############################ -# TODO: Enable Casecmp Cop. # Use `casecmp` rather than `downcase ==`. Performance/Casecmp: - Enabled: false + Enabled: true # TODO: Enable DoubleStartEndWith Cop. # Use `str.{start,end}_with?(x, ..., y, ...)` instead of diff --git a/app/models/repository.rb b/app/models/repository.rb index a4b42d7226d..de7e163078d 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -453,7 +453,7 @@ class Repository def version cache.fetch(:version) do tree(:head).blobs.find do |file| - file.name.downcase == 'version' + file.name.casecmp('version').zero? end end end diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index 6f9da69983a..42bec913a45 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -5,11 +5,11 @@ module Gitlab end def self.mysql? - adapter_name.downcase == 'mysql2' + adapter_name.casecmp('mysql2').zero? end def self.postgresql? - adapter_name.downcase == 'postgresql' + adapter_name.casecmp('postgresql').zero? end def self.version diff --git a/lib/gitlab/markup_helper.rb b/lib/gitlab/markup_helper.rb index a5f767b134d..dda371e6554 100644 --- a/lib/gitlab/markup_helper.rb +++ b/lib/gitlab/markup_helper.rb @@ -40,7 +40,7 @@ module Gitlab # Returns boolean def plain?(filename) filename.downcase.end_with?('.txt') || - filename.downcase == 'readme' + filename.casecmp('readme').zero? end def previewable?(filename) |