ruby/lib/rubygems/win_platform.rb
Aaron Patterson 3bf695a767 [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
2025-09-19 19:30:10 +09:00

32 lines
519 B
Ruby

# 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