Skip to content

Commit 0ba2278

Browse files
Use 'elementsEqual' for Slice equality operator
1 parent 84f9934 commit 0ba2278

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

stdlib/public/core/Slice.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,20 +262,11 @@ extension Slice: MutableCollection where Base: MutableCollection {
262262

263263
extension Slice : Equatable where Base.Element : Equatable {
264264
public static func == (lhs: Slice<Base>, rhs: Slice<Base>) -> Bool {
265-
let lhsCount = lhs.count
266-
if lhsCount != rhs.count {
265+
if lhs.count != rhs.count {
267266
return false
268267
}
269268
// We know that lhs.count == rhs.count, compare element wise.
270-
271-
for idx in 0..<lhsCount {
272-
let lidx = lhs._base.index(lhs._base.startIndex, offsetBy: idx)
273-
let ridx = rhs._base.index(rhs._base.startIndex, offsetBy: idx)
274-
if lhs[lidx] != rhs[ridx] {
275-
return false
276-
}
277-
}
278-
return true
269+
return lhs.elementsEqual(rhs)
279270
}
280271
}
281272

0 commit comments

Comments
 (0)