Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of Pod::Source#search #416

Merged
merged 1 commit into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 17 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 Down Expand Up @@ -78,18 +84,16 @@ def highest_version
# 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 Expand Up @@ -127,6 +131,14 @@ def to_hash
}
end

private

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

#-----------------------------------------------------------------------#

# The Set::External class handles Pods from external sources. Pods from
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.send(: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