Skip to content

Commit

Permalink
Cache version result for each pod and segments
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jun 17, 2017
1 parent dae60a3 commit db12586
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,10 @@

##### Enhancements

* Cache version result for each pod and segments
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#385](https://github.com/CocoaPods/Core/pull/385)

* Introduce `test_specification` DSL
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[Kyle Fuller](https://github.com/kylef)
Expand Down
4 changes: 3 additions & 1 deletion lib/cocoapods-core/source.rb
Expand Up @@ -24,6 +24,7 @@ class Source
#
def initialize(repo)
@repo = Pathname(repo).expand_path
@name_to_versions_cache = {}
refresh_metadata
end

Expand Down Expand Up @@ -160,7 +161,8 @@ def versions(name)
raise ArgumentError, 'No name' unless name
pod_dir = pod_path(name)
return unless pod_dir.exist?
pod_dir.children.map do |v|
return @name_to_versions_cache[name] if @name_to_versions_cache.key?(name)
@name_to_versions_cache[name] = pod_dir.children.map do |v|
basename = v.basename.to_s
begin
Version.new(basename) if v.directory? && basename[0, 1] != '.'
Expand Down
4 changes: 2 additions & 2 deletions lib/cocoapods-core/version.rb
Expand Up @@ -198,11 +198,11 @@ def _segments
end

def numeric_segments
segments.take_while { |s| s.is_a?(Numeric) }.reverse_each.drop_while { |s| s == 0 }.reverse
@numeric_segments ||= segments.take_while { |s| s.is_a?(Numeric) }.reverse_each.drop_while { |s| s == 0 }.reverse
end

def prerelease_segments
segments.drop_while { |s| s.is_a?(Numeric) }
@prerelease_segments ||= segments.drop_while { |s| s.is_a?(Numeric) }
end

def compare_segments(other)
Expand Down

0 comments on commit db12586

Please sign in to comment.