[llvm-commits] [llvm] r151523 - /llvm/trunk/include/llvm/ADT/Hashing.h
Jay Foad
jay.foad at gmail.com
Mon Feb 27 03:00:17 PST 2012
Author: foad
Date: Mon Feb 27 05:00:17 2012
New Revision: 151523
URL: http://llvm.org/viewvc/llvm-project?rev=151523&view=rev
Log:
Help the compiler to eliminate some dead code when hashing an array of T
where sizeof (T) is a multiple of 4.
Modified:
llvm/trunk/include/llvm/ADT/Hashing.h
Modified: llvm/trunk/include/llvm/ADT/Hashing.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/Hashing.h?rev=151523&r1=151522&r2=151523&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/Hashing.h (original)
+++ llvm/trunk/include/llvm/ADT/Hashing.h Mon Feb 27 05:00:17 2012
@@ -142,6 +142,7 @@
}
// Add a range of bytes from I to E.
+ template<bool ElementsHaveEvenLength>
void addBytes(const char *I, const char *E) {
uint32_t Data;
// Note that aliasing rules forbid us from dereferencing
@@ -154,7 +155,7 @@
std::memcpy(&Data, I, sizeof Data);
mix(Data);
}
- if (I != E) {
+ if (!ElementsHaveEvenLength && I != E) {
Data = 0;
std::memcpy(&Data, I, E - I);
mix(Data);
@@ -164,8 +165,9 @@
// Add a range of bits from I to E.
template<typename T>
void addBits(const T *I, const T *E) {
- addBytes(reinterpret_cast<const char *>(I),
- reinterpret_cast<const char *>(E));
+ addBytes<sizeof (T) % sizeof (uint32_t) == 0>(
+ reinterpret_cast<const char *>(I),
+ reinterpret_cast<const char *>(E));
}
};
More information about the llvm-commits
mailing list