Skip to content

Commit

Permalink
Improve performance of Pod::Source#search
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Oct 9, 2017
1 parent d8ef8fa commit 1cf1cc0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

##### Bug Fixes

* None.

* Improve performance of `Pod::Source#search`
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#416](https://github.com/CocoaPods/Core/pull/416)

## 1.4.0.beta.1 (2017-09-24)

Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods-core/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def search(query)
found = Pathname.glob(pod_path(query)).map { |path| path.basename.to_s }
if [query] == found
set = set(query)
set if set.specification.name == query
set if set.specification_name == query
end
end

Expand Down
20 changes: 15 additions & 5 deletions lib/cocoapods-core/specification/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Set
# the sources that contain a Pod.
#
def initialize(name, sources = [])
@name = name
@name = name
@sources = Array(sources)
end

Expand All @@ -50,6 +50,12 @@ def specification
Specification.from_file(highest_version_spec_path)
end

# @return [Specification] the top level specification for this set for any version.
#
def specification_name
Specification.from_file(specification_paths_for_version(any_version).first).name
end

# @return [Array<String>] the paths to specifications for the given
# version
#
Expand All @@ -71,25 +77,29 @@ def highest_version
versions.first
end

# @return [Version] A version known for this specification.
#
def any_version
versions_by_source.values.flatten.uniq.first
end

# @return [Pathname] The path of the highest version.
#
# @note If multiple sources have a specification for the
# {#required_version}, the order in which they are provided
# is used to disambiguate.
#
def highest_version_spec_path
specification_paths_for_version(highest_version).first
@highest_version_spec_path ||= specification_paths_for_version(highest_version).first
end

# @return [Hash{Source => Version}] all the available versions for the
# Pod grouped by source.
#
def versions_by_source
result = {}
sources.each do |source|
@versions_by_source ||= sources.each_with_object({}) do |source, result|
result[source] = source.versions(name)
end
result
end

def ==(other)
Expand Down
4 changes: 4 additions & 0 deletions spec/specification/set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module Pod
@set.highest_version.should == Version.new('1.6.2')
end

it 'returns a version available for the pod' do
@set.any_version.should == Version.new('1.6.2')
end

it 'returns the path of the spec with the highest version' do
@set.highest_version_spec_path.should == @source.repo + 'CocoaLumberjack/1.6.2/CocoaLumberjack.podspec'
end
Expand Down

0 comments on commit 1cf1cc0

Please sign in to comment.