Skip to content

Commit 0b7129e

Browse files
authored
Merge pull request #1839 from etcwilde/ewilde/variant-triple-to-variant-module-job
Add `contains(subsequence:)` on any bidirectional sequence instead of just arrays
2 parents 8cbf26f + 9fa4be8 commit 0b7129e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,7 +4182,7 @@ final class SwiftDriverTests: XCTestCase {
41824182
"-emit-module-path", "target.swiftmodule",
41834183
"-emit-variant-module-path", "variant.swiftmodule",
41844184
"-Xfrontend", "-emit-module-doc-path", "-Xfrontend", "target.swiftdoc",
4185-
"-Xfrontend", "-emit-variant-module-doc-path", "variant.swiftdoc",
4185+
"-Xfrontend", "-emit-variant-module-doc-path", "-Xfrontend", "variant.swiftdoc",
41864186
"-emit-module-source-info-path", "target.sourceinfo",
41874187
"-emit-variant-module-source-info-path", "variant.sourceinfo",
41884188
"-emit-package-module-interface-path", "target.package.swiftinterface",
@@ -8323,7 +8323,7 @@ func assertString(
83238323
""", file: file, line: line)
83248324
}
83258325

8326-
extension Array where Element: Equatable {
8326+
extension BidirectionalCollection where Element: Equatable, Index: Strideable, Index.Stride: SignedInteger {
83278327
/// Returns true if the receiver contains the given elements as a subsequence
83288328
/// (i.e., all elements are present, contiguous, and in the same order).
83298329
///
@@ -8337,10 +8337,15 @@ extension Array where Element: Equatable {
83378337
{
83388338
precondition(!subsequence.isEmpty, "Subsequence may not be empty")
83398339

8340-
let subsequenceCount = subsequence.count
8341-
for index in 0...(self.count - subsequence.count) {
8342-
let subsequenceEnd = index + subsequenceCount
8343-
if self[index..<subsequenceEnd].elementsEqual(subsequence) {
8340+
guard self.count >= subsequence.count else {
8341+
return false
8342+
}
8343+
8344+
for index in self.startIndex...self.index(self.endIndex,
8345+
offsetBy: -subsequence.count) {
8346+
if self[index..<self.index(index,
8347+
offsetBy: subsequence.count)]
8348+
.elementsEqual(subsequence) {
83448349
return true
83458350
}
83468351
}

0 commit comments

Comments
 (0)