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)
commit7f360ce5c2d8659fd6672471e03a7dec99a17461
treeed758c28fd51a74eb980aad3f7a54fb30ccfe75c
parentbc477ddee00aa9cad25c4cdf0fac89d72f6c21a0
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.

llvm-svn: 230920
llvm/include/llvm/ADT/ArrayRef.h