Skip to content

Commit

Permalink
Reduce allocations (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins authored Dec 7, 2023
1 parent 066456a commit 682f81d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compact_index/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module CompactIndex
Dependency = Struct.new(:gem, :version, :platform, :checksum) do # rubocop:disable Lint/StructNewOverride
def version_and_platform
if platform.nil? || platform == "ruby"
version.dup
version
else
"#{version}-#{platform}"
end
Expand Down
8 changes: 5 additions & 3 deletions lib/compact_index/gem_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module CompactIndex
:dependencies, :ruby_version, :rubygems_version) do
def number_and_platform
if platform.nil? || platform == "ruby"
number.dup
number
else
"#{number}-#{platform}"
end
Expand All @@ -22,7 +22,7 @@ def <=>(other)
end

def to_line
line = number_and_platform.dup << " " << deps_line << "|checksum:#{checksum}"
line = "#{number_and_platform} #{deps_line}|checksum:#{checksum}"
line << ",ruby:#{ruby_version_line}" if ruby_version && ruby_version != ">= 0"
line << ",rubygems:#{rubygems_version_line}" if rubygems_version && rubygems_version != ">= 0"
line
Expand All @@ -47,7 +47,9 @@ def deps_line
end

def join_multiple(requirements)
requirements.split(", ").sort.join("&")
requirements = requirements.split(", ")
requirements.sort!
requirements.join("&")
end
end
end
2 changes: 1 addition & 1 deletion lib/compact_index/versions_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create(gems, timestamp = Time.now.iso8601)
private

def gem_lines(gems)
gems.reduce("".dup) do |lines, gem|
gems.reduce(+"") do |lines, gem|
version_numbers = gem.versions.map(&:number_and_platform).join(",")
lines << gem.name <<
" " << version_numbers <<
Expand Down

0 comments on commit 682f81d

Please sign in to comment.