diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b940aafc..4e3e64d57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index 35a35814e..b8fc9e11a 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -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 diff --git a/lib/cocoapods-core/specification/set.rb b/lib/cocoapods-core/specification/set.rb index 1ab7a21e1..f0bd49e56 100644 --- a/lib/cocoapods-core/specification/set.rb +++ b/lib/cocoapods-core/specification/set.rb @@ -30,7 +30,7 @@ class Set # the sources that contain a Pod. # def initialize(name, sources = []) - @name = name + @name = name @sources = Array(sources) end @@ -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] the paths to specifications for the given # version # @@ -71,6 +77,12 @@ 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 @@ -78,18 +90,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) diff --git a/spec/specification/set_spec.rb b/spec/specification/set_spec.rb index 62166b6bf..5a36a8857 100644 --- a/spec/specification/set_spec.rb +++ b/spec/specification/set_spec.rb @@ -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