Use four-iterator std::equal for bssl::Span::operator==
At one point we targetted C++11 and had to use the unsafe three-iterator
std::equal. Then we had to write the loop by hand because the pragma to
suppress an MSVC warning did not work:
https://boringssl-review.googlesource.com/c/boringssl/+/18384
We now target C++14, so just use the four-iterator version. libc++
will then be able to specialize it into a memcmp call.
Also replace a three-iterator std::equal in pki/input.cc.
Change-Id: I0a7d6a2330594e383c5c884632de9a21a137054c
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65647
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
diff --git a/include/openssl/span.h b/include/openssl/span.h
index aa8f801..044ada1 100644
--- a/include/openssl/span.h
+++ b/include/openssl/span.h
@@ -40,20 +40,7 @@
"Span<T> must be derived from SpanBase<const T>");
friend bool operator==(Span<T> lhs, Span<T> rhs) {
- // MSVC issues warning C4996 because std::equal is unsafe. The pragma to
- // suppress the warning mysteriously has no effect, hence this
- // implementation. See
- // https://msdn.microsoft.com/en-us/library/aa985974.aspx.
- if (lhs.size() != rhs.size()) {
- return false;
- }
- for (T *l = lhs.begin(), *r = rhs.begin(); l != lhs.end() && r != rhs.end();
- ++l, ++r) {
- if (*l != *r) {
- return false;
- }
- }
- return true;
+ return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
friend bool operator!=(Span<T> lhs, Span<T> rhs) { return !(lhs == rhs); }
diff --git a/pki/input.cc b/pki/input.cc
index a0d8af6..12ee450 100644
--- a/pki/input.cc
+++ b/pki/input.cc
@@ -23,9 +23,7 @@
bssl::Span<const uint8_t> Input::AsSpan() const { return data_; }
bool operator==(const Input &lhs, const Input &rhs) {
- return lhs.Length() == rhs.Length() &&
- std::equal(lhs.UnsafeData(), lhs.UnsafeData() + lhs.Length(),
- rhs.UnsafeData());
+ return lhs.AsSpan() == rhs.AsSpan();
}
bool operator!=(const Input &lhs, const Input &rhs) { return !(lhs == rhs); }