From 2ed9a81d810e4e90ee66a0bef7f2df02d9ddd22d Mon Sep 17 00:00:00 2001 From: Akio Yasui <1528813+akkyie@users.noreply.github.com> Date: Wed, 13 May 2020 00:28:49 +0900 Subject: [PATCH] Optimize simplifying paths for faster project generation (#857) --- CHANGELOG.md | 1 + Sources/Core/PathExtensions.swift | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9741bde9..d74f51d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Fix linking of multiple products from the same Swift Package [#830](https://github.com/yonaskolb/XcodeGen/pull/830) @toshi0383 - Don't deduplicate files in `include` with different path but same name. [#849](https://github.com/yonaskolb/XcodeGen/pull/849) @akkyie - Don't link transitive static carthage libraries. [#853](https://github.com/yonaskolb/XcodeGen/pull/853) @akkyie +- Optimize simplifying paths for faster project generation. [#857](https://github.com/yonaskolb/XcodeGen/pull/857) @akkyie ## 2.15.1 diff --git a/Sources/Core/PathExtensions.swift b/Sources/Core/PathExtensions.swift index 0d996dd8..5e72c958 100644 --- a/Sources/Core/PathExtensions.swift +++ b/Sources/Core/PathExtensions.swift @@ -11,7 +11,14 @@ extension Path { /// - `../a/b` simplifies to `../a/b` /// - `a/../../c` simplifies to `../c` public func simplifyingParentDirectoryReferences() -> Path { - normalize().components.reduce(Path(), +) + if !string.contains("..") { // Skip simplifying if its already simple + var string = self.string + while string.hasSuffix(Path.separator) { // Remove all trailing path separators + string.removeLast() + } + return Path(String(string)) + } + return normalize().components.reduce(Path(), +) } /// Returns the relative path necessary to go from `base` to `self`.