From 49f6b10093d0c9474308a7dcda32d70f8916029e Mon Sep 17 00:00:00 2001 From: Dimitris Couchell-Koutsogiorgas Date: Fri, 9 Sep 2016 18:51:25 -0700 Subject: [PATCH] Cache result of uses_swift and should_build --- CHANGELOG.md | 5 ++++- lib/cocoapods/target/pod_target.rb | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcf73e0fa4..129bdf34d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ##### Enhancements -* None. +* Cache result of uses_swift and should_build to speed up pod install. + [Dimitris Koutsogiorgas](https://github.com/dnkoutso) + [#5837](https://github.com/CocoaPods/CocoaPods/pull/5837) + ##### Bug Fixes diff --git a/lib/cocoapods/target/pod_target.rb b/lib/cocoapods/target/pod_target.rb index 90f8a1a74e..3ae962c343 100644 --- a/lib/cocoapods/target/pod_target.rb +++ b/lib/cocoapods/target/pod_target.rb @@ -141,9 +141,12 @@ def product_module_name # A target should not be build if it has no source files. # def should_build? - source_files = file_accessors.flat_map(&:source_files) - source_files -= file_accessors.flat_map(&:headers) - !source_files.empty? + return @should_build if defined? @should_build + @should_build = begin + source_files = file_accessors.flat_map(&:source_files) + source_files -= file_accessors.flat_map(&:headers) + !source_files.empty? + end end # @return [Array] the specification consumers for @@ -156,8 +159,11 @@ def spec_consumers # @return [Boolean] Whether the target uses Swift code # def uses_swift? - file_accessors.any? do |file_accessor| - file_accessor.source_files.any? { |sf| sf.extname == '.swift' } + return @uses_swift if defined? @uses_swift + @uses_swift = begin + file_accessors.any? do |file_accessor| + file_accessor.source_files.any? { |sf| sf.extname == '.swift' } + end end end