Skip to content

Commit 9fc6eb7

Browse files
adopt Swift Collection's OrderedSet and OrderedDictionary
They're better optimised and tested.
1 parent 21a7918 commit 9fc6eb7

File tree

7 files changed

+33
-350
lines changed

7 files changed

+33
-350
lines changed

Package.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ let package = Package(
3939
name: "TSCTestSupport",
4040
targets: ["TSCTestSupport"]),
4141
],
42-
dependencies: [],
4342
targets: [
4443

4544
// MARK: Tools support core targets
@@ -55,11 +54,21 @@ let package = Package(
5554
.target(
5655
/** TSCBasic support library */
5756
name: "TSCBasic",
58-
dependencies: ["TSCLibc", "TSCclibc"]),
57+
dependencies: [
58+
"TSCLibc",
59+
"TSCclibc",
60+
.product(name: "OrderedCollections", package: "swift-collections"),
61+
]
62+
),
5963
.target(
6064
/** Abstractions for common operations, should migrate to TSCBasic */
6165
name: "TSCUtility",
62-
dependencies: ["TSCBasic", "TSCclibc"]),
66+
dependencies: [
67+
"TSCBasic",
68+
"TSCclibc",
69+
.product(name: "OrderedCollections", package: "swift-collections"),
70+
]
71+
),
6372

6473
// MARK: Additional Test Dependencies
6574

@@ -86,6 +95,19 @@ let package = Package(
8695
]
8796
)
8897

98+
/// When not using local dependencies, the branch to use for llbuild and TSC repositories.
99+
let relatedDependenciesBranch = "main"
100+
101+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
102+
package.dependencies += [
103+
.package(url: "https://github.com/apple/swift-collections.git", .branch("main")),
104+
]
105+
} else {
106+
package.dependencies += [
107+
.package(path: "../swift-collections"),
108+
]
109+
}
110+
89111
// FIXME: conditionalise these flags since SwiftPM 5.3 and earlier will crash
90112
// for platforms they don't know about.
91113
#if os(Windows)

Sources/TSCBasic/GraphAlgorithms.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
import OrderedCollections
12+
1113
public enum GraphError: Error {
1214
/// A cycle was detected in the input.
1315
case unexpectedCycle
@@ -69,7 +71,7 @@ public func topologicalSort<T: Hashable>(
6971

7072
// Otherwise, visit each adjacent node.
7173
for succ in try successors(node) {
72-
guard stack.append(succ) else {
74+
guard stack.append(succ).inserted else {
7375
// If the successor is already in this current stack, we have found a cycle.
7476
//
7577
// FIXME: We could easily include information on the cycle we found here.
@@ -120,7 +122,7 @@ public func findCycle<T: Hashable>(
120122
// FIXME: Convert to stack.
121123
func visit(_ node: T, _ successors: (T) throws -> [T]) rethrows -> (path: [T], cycle: [T])? {
122124
// If this node is already in the current path then we have found a cycle.
123-
if !path.append(node) {
125+
if !path.append(node).inserted {
124126
let index = path.firstIndex(of: node)!
125127
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
126128
}

Sources/TSCBasic/OrderedDictionary.swift

Lines changed: 0 additions & 125 deletions
This file was deleted.

Sources/TSCBasic/OrderedSet.swift

Lines changed: 0 additions & 130 deletions
This file was deleted.

Sources/TSCUtility/PkgConfig.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCBasic
1211
import Foundation
12+
import OrderedCollections
13+
import TSCBasic
1314

1415
public enum PkgConfigError: Swift.Error, CustomStringConvertible {
1516
case couldNotFindConfigFile(name: String)

Tests/TSCBasicTests/OrderedDictionaryTests.swift

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)