Skip to content

Commit

Permalink
Use 'elementsEqual' for Slice equality operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenbekditlevsen committed Feb 6, 2018
1 parent 84f9934 commit 0ba2278
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions stdlib/public/core/Slice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,11 @@ extension Slice: MutableCollection where Base: MutableCollection {

extension Slice : Equatable where Base.Element : Equatable {
public static func == (lhs: Slice<Base>, rhs: Slice<Base>) -> Bool {
let lhsCount = lhs.count
if lhsCount != rhs.count {
if lhs.count != rhs.count {
return false
}
// We know that lhs.count == rhs.count, compare element wise.

for idx in 0..<lhsCount {
let lidx = lhs._base.index(lhs._base.startIndex, offsetBy: idx)
let ridx = rhs._base.index(rhs._base.startIndex, offsetBy: idx)
if lhs[lidx] != rhs[ridx] {
return false
}
}
return true
return lhs.elementsEqual(rhs)
}
}

Expand Down

0 comments on commit 0ba2278

Please sign in to comment.