summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Shea <connor.james.shea@gmail.com>2016-04-27 16:52:32 -0600
committerConnor Shea <connor.james.shea@gmail.com>2016-05-10 18:23:25 -0600
commit377583a361988d9884808a3c3f5375497a9d5b56 (patch)
tree0606e242db6a23bb7bc643eab841c9eb89f217e2
parent4a47470febe34bf67e84a2904422626caa64224e (diff)
downloadgitlab-ce-377583a361988d9884808a3c3f5375497a9d5b56.tar.gz
Enable Rubocop Casecmp Performance Cop.
Also fixes the errors caused by enabling the cop. casecmp is more performant than `.downcase` and `==`.
-rw-r--r--.rubocop.yml3
-rw-r--r--app/models/repository.rb2
-rw-r--r--lib/gitlab/database.rb4
-rw-r--r--lib/gitlab/markup_helper.rb2
4 files changed, 5 insertions, 6 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index 9f179efa3ce..f07d2184be4 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 7aebfe279fb..5f562750d1f 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)