ArrayRef: Put back std::equal for operator== with a check for the empty ArrayRefs
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Mar 2015 23:35:20 +0000 (23:35 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Mar 2015 23:35:20 +0000 (23:35 +0000)
commit24c79ab7cc6fb3538087b98bf3641f2075ecc63d
tree1c60d5c7be1acd87f25b555fc57f402314720493
parentd0856d6a34c04d1baaf1695191303899564bcb81
ArrayRef: Put back std::equal for operator== with a check for the empty ArrayRefs

This has the nice property of compiling down to memcmp when feasible. An empty
ArrayRef can have a nullptr in its Data field. I didn't find anything in the
standard speaking against std::equal(nullptr, nullptr, nullptr) begin valid but
MSVC asserts. The way libstdc++ lowers std::equal down to memcmp also makes
invoking std::equal with a nullptr undefined behavior so checking is the only
way to be safe.

The extra check doesn't cost us perf either because we're essentially peeling
the loop header away from the rotated loop.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230920 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/ArrayRef.h