Convert to boolean in C code
casecmp?(str) is 1.5x faster than casecmp(str).zero? It's 1 less method call in Ruby, and the C code can convert to boolean, rather than returning a number and determining if it's zero.
This commit is contained in:
parent
0c7019f1e8
commit
a623252c59
|
@ -53,7 +53,7 @@ module JsonLdHelper
|
||||||
needle = Addressable::URI.parse(url).host
|
needle = Addressable::URI.parse(url).host
|
||||||
haystack = Addressable::URI.parse(@account.uri).host
|
haystack = Addressable::URI.parse(@account.uri).host
|
||||||
|
|
||||||
!haystack.casecmp(needle).zero?
|
!haystack.casecmp?(needle)
|
||||||
end
|
end
|
||||||
|
|
||||||
def canonicalize(json)
|
def canonicalize(json)
|
||||||
|
|
|
@ -7,11 +7,11 @@ class TagManager
|
||||||
include RoutingHelper
|
include RoutingHelper
|
||||||
|
|
||||||
def web_domain?(domain)
|
def web_domain?(domain)
|
||||||
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.web_domain).zero?
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp?(Rails.configuration.x.web_domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_domain?(domain)
|
def local_domain?(domain)
|
||||||
domain.nil? || domain.gsub(/[\/]/, '').casecmp(Rails.configuration.x.local_domain).zero?
|
domain.nil? || domain.gsub(/[\/]/, '').casecmp?(Rails.configuration.x.local_domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_domain(domain)
|
def normalize_domain(domain)
|
||||||
|
@ -35,9 +35,9 @@ class TagManager
|
||||||
end
|
end
|
||||||
|
|
||||||
def same_acct?(canonical, needle)
|
def same_acct?(canonical, needle)
|
||||||
return true if canonical.casecmp(needle).zero?
|
return true if canonical.casecmp?(needle)
|
||||||
username, domain = needle.split('@')
|
username, domain = needle.split('@')
|
||||||
local_domain?(domain) && canonical.casecmp(username).zero?
|
local_domain?(domain) && canonical.casecmp?(username)
|
||||||
end
|
end
|
||||||
|
|
||||||
def local_url?(url)
|
def local_url?(url)
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'open-uri'
|
||||||
|
|
||||||
module OpenURI
|
module OpenURI
|
||||||
def self.redirectable?(uri1, uri2) # :nodoc:
|
def self.redirectable?(uri1, uri2) # :nodoc:
|
||||||
uri1.scheme.casecmp(uri2.scheme).zero? ||
|
uri1.scheme.casecmp?(uri2.scheme) ||
|
||||||
(/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme)
|
(/\A(?:http|https|ftp)\z/i =~ uri1.scheme && /\A(?:http|https|ftp)\z/i =~ uri2.scheme)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,13 +44,13 @@ module GabSocial
|
||||||
# Stub for Database.postgresql? from GitLab
|
# Stub for Database.postgresql? from GitLab
|
||||||
def self.postgresql?
|
def self.postgresql?
|
||||||
%w[postgresql postgresql_makara].any? do |adapter|
|
%w[postgresql postgresql_makara].any? do |adapter|
|
||||||
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp(adapter).zero?
|
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp?(adapter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Stub for Database.mysql? from GitLab
|
# Stub for Database.mysql? from GitLab
|
||||||
def self.mysql?
|
def self.mysql?
|
||||||
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp('mysql2').zero?
|
ActiveRecord::Base.configurations[Rails.env]['adapter'].casecmp?('mysql2')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Model that can be used for querying permissions of a SQL user.
|
# Model that can be used for querying permissions of a SQL user.
|
||||||
|
|
Loading…
Reference in New Issue