зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] update cache checksums to decrease string allocations
https://github.com/rubygems/rubygems/commit/85371a961a
This commit is contained in:
Родитель
c7281e2d67
Коммит
4d0c5486a2
|
@ -55,14 +55,9 @@ module Bundler
|
|||
end
|
||||
|
||||
def checksums
|
||||
checksums = {}
|
||||
|
||||
lines(versions_path).each do |line|
|
||||
name, _, checksum = line.split(" ", 3)
|
||||
checksums[name] = checksum
|
||||
lines(versions_path).each_with_object({}) do |line, checksums|
|
||||
parse_version_checksum(line, checksums)
|
||||
end
|
||||
|
||||
checksums
|
||||
end
|
||||
|
||||
def dependencies(name)
|
||||
|
@ -106,6 +101,20 @@ module Bundler
|
|||
@dependency_parser.parse(line)
|
||||
end
|
||||
|
||||
# This is mostly the same as `split(" ", 3)` but it avoids allocating extra objects.
|
||||
# This method gets called at least once for every gem when parsing versions.
|
||||
def parse_version_checksum(line, checksums)
|
||||
line.freeze # allows slicing into the string to not allocate a copy of the line
|
||||
name_end = line.index(" ")
|
||||
checksum_start = line.index(" ", name_end + 1) + 1
|
||||
checksum_end = line.size - checksum_start
|
||||
# freeze name since it is used as a hash key
|
||||
# pre-freezing means a frozen copy isn't created
|
||||
name = line[0, name_end].freeze
|
||||
checksum = line[checksum_start, checksum_end]
|
||||
checksums[name] = checksum
|
||||
end
|
||||
|
||||
def info_roots
|
||||
[
|
||||
directory.join("info"),
|
||||
|
|
Загрузка…
Ссылка в новой задаче