summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2025-09-17 18:10:27 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2025-09-19 19:30:10 +0900
commit3bf695a767b0f03e39a93e27296499eca1bec64f (patch)
tree23111f27806a70e0562b22c456227428e9b14784
parentda130d25e39d37185d7627b0d202a5c69d488c14 (diff)
[rubygems/rubygems] Pull `Gem.win_platform?` out of a hot path
`normalize_path` is a pretty hot path, it's called many times per file in each gem. Since the platform isn't going to change from call to call, we can conditionally define `normalize_path` based on the value of `Gem.win_platform?`. https://github.com/rubygems/rubygems/commit/d5e61411f2
-rw-r--r--lib/rubygems.rb27
-rw-r--r--lib/rubygems/package.rb9
-rw-r--r--lib/rubygems/win_platform.rb31
3 files changed, 38 insertions, 29 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index f8f1451ee6..8bb8cdfc04 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -16,6 +16,7 @@ require_relative "rubygems/defaults"
require_relative "rubygems/deprecate"
require_relative "rubygems/errors"
require_relative "rubygems/target_rbconfig"
+require_relative "rubygems/win_platform"
##
# RubyGems is the Ruby standard for publishing and managing third party
@@ -113,18 +114,6 @@ require_relative "rubygems/target_rbconfig"
module Gem
RUBYGEMS_DIR = __dir__
- ##
- # An Array of Regexps that match windows Ruby platforms.
-
- WIN_PATTERNS = [
- /bccwin/i,
- /cygwin/i,
- /djgpp/i,
- /mingw/i,
- /mswin/i,
- /wince/i,
- ].freeze
-
GEM_DEP_FILES = %w[
gem.deps.rb
gems.rb
@@ -160,8 +149,6 @@ module Gem
DEFAULT_SOURCE_DATE_EPOCH = 315_619_200
- @@win_platform = nil
-
@configuration = nil
@gemdeps = nil
@loaded_specs = {}
@@ -1092,18 +1079,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
end
##
- # Is this a windows platform?
-
- def self.win_platform?
- if @@win_platform.nil?
- ruby_platform = RbConfig::CONFIG["host_os"]
- @@win_platform = !WIN_PATTERNS.find {|r| ruby_platform =~ r }.nil?
- end
-
- @@win_platform
- end
-
- ##
# Is this a java platform?
def self.java_platform?
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index cd8dfdf37d..b56d68cc45 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -7,6 +7,7 @@
# rubocop:enable Style/AsciiComments
+require_relative "win_platform"
require_relative "security"
require_relative "user_interaction"
@@ -518,10 +519,12 @@ EOM
destination
end
- def normalize_path(pathname)
- if Gem.win_platform?
+ if Gem.win_platform?
+ def normalize_path(pathname) # :nodoc:
pathname.downcase
- else
+ end
+ else
+ def normalize_path(pathname) # :nodoc:
pathname
end
end
diff --git a/lib/rubygems/win_platform.rb b/lib/rubygems/win_platform.rb
new file mode 100644
index 0000000000..78e968fe49
--- /dev/null
+++ b/lib/rubygems/win_platform.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+require "rbconfig"
+
+module Gem
+ ##
+ # An Array of Regexps that match windows Ruby platforms.
+
+ WIN_PATTERNS = [
+ /bccwin/i,
+ /cygwin/i,
+ /djgpp/i,
+ /mingw/i,
+ /mswin/i,
+ /wince/i,
+ ].freeze
+
+ @@win_platform = nil
+
+ ##
+ # Is this a windows platform?
+
+ def self.win_platform?
+ if @@win_platform.nil?
+ ruby_platform = RbConfig::CONFIG["host_os"]
+ @@win_platform = !WIN_PATTERNS.find {|r| ruby_platform =~ r }.nil?
+ end
+
+ @@win_platform
+ end
+end