summaryrefslogtreecommitdiff
path: root/lib/rubygems/stub_specification.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/stub_specification.rb')
-rw-r--r--lib/rubygems/stub_specification.rb52
1 files changed, 28 insertions, 24 deletions
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index b1dd7397ae..58748df5d6 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
##
# Gem::StubSpecification reads the stub: line from the gemspec. This prevents
# us having to eval the entire gemspec in order to find out certain
@@ -6,10 +7,10 @@
class Gem::StubSpecification < Gem::BasicSpecification
# :nodoc:
- PREFIX = "# stub: ".freeze
+ PREFIX = "# stub: "
# :nodoc:
- OPEN_MODE = 'r:UTF-8:-'.freeze
+ OPEN_MODE = "r:UTF-8:-"
class StubLine # :nodoc: all
attr_reader :name, :version, :platform, :require_paths, :extensions,
@@ -19,9 +20,9 @@ class Gem::StubSpecification < Gem::BasicSpecification
# These are common require paths.
REQUIRE_PATHS = { # :nodoc:
- 'lib' => 'lib'.freeze,
- 'test' => 'test'.freeze,
- 'ext' => 'ext'.freeze,
+ "lib" => "lib",
+ "test" => "test",
+ "ext" => "ext",
}.freeze
# These are common require path lists. This hash is used to optimize
@@ -29,12 +30,12 @@ class Gem::StubSpecification < Gem::BasicSpecification
# in their require paths, so lets take advantage of that by pre-allocating
# a require path list for that case.
REQUIRE_PATH_LIST = { # :nodoc:
- 'lib' => ['lib'].freeze,
+ "lib" => ["lib"].freeze,
}.freeze
def initialize(data, extensions)
- parts = data[PREFIX.length..-1].split(" ".freeze, 4)
- @name = parts[0].freeze
+ parts = data[PREFIX.length..-1].split(" ", 4)
+ @name = -parts[0]
@version = if Gem::Version.correct?(parts[1])
Gem::Version.new(parts[1])
else
@@ -50,7 +51,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
end
path_list = parts.last
- @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0".freeze).map! do |x|
+ @require_paths = REQUIRE_PATH_LIST[path_list] || path_list.split("\0").map! do |x|
REQUIRE_PATHS[x] || x
end
end
@@ -68,7 +69,6 @@ class Gem::StubSpecification < Gem::BasicSpecification
def initialize(filename, base_dir, gems_dir, default_gem)
super()
- filename.tap(&Gem::UNTAINT)
self.loaded_from = filename
@data = nil
@@ -84,10 +84,10 @@ class Gem::StubSpecification < Gem::BasicSpecification
def activated?
@activated ||=
- begin
- loaded = Gem.loaded_specs[name]
- loaded && loaded.version == version
- end
+ begin
+ loaded = Gem.loaded_specs[name]
+ loaded && loaded.version == version
+ end
end
def default_gem?
@@ -111,20 +111,23 @@ class Gem::StubSpecification < Gem::BasicSpecification
saved_lineno = $.
Gem.open_file loaded_from, OPEN_MODE do |file|
- begin
- file.readline # discard encoding line
- stubline = file.readline.chomp
- if stubline.start_with?(PREFIX)
- extensions = if /\A#{PREFIX}/ =~ file.readline.chomp
- $'.split "\0"
+ file.readline # discard encoding line
+ stubline = file.readline
+ if stubline.start_with?(PREFIX)
+ extline = file.readline
+
+ extensions =
+ if extline.delete_prefix!(PREFIX)
+ extline.chomp!
+ extline.split "\0"
else
StubLine::NO_EXTENSIONS
end
- @data = StubLine.new stubline, extensions
- end
- rescue EOFError
+ stubline.chomp! # readline(chomp: true) allocates 3x as much as .readline.chomp!
+ @data = StubLine.new stubline, extensions
end
+ rescue EOFError
end
ensure
$. = saved_lineno
@@ -183,7 +186,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
##
# The full Gem::Specification for this gem, loaded from evalling its gemspec
- def to_spec
+ def spec
@spec ||= if @data
loaded = Gem.loaded_specs[name]
loaded if loaded && loaded.version == version
@@ -191,6 +194,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
@spec ||= Gem::Specification.load(loaded_from)
end
+ alias_method :to_spec, :spec
##
# Is this StubSpecification valid? i.e. have we found a stub line, OR does