[llvm-commits] [llvm] r156768 - in /llvm/trunk: include/llvm/ADT/BitVector.h unittests/ADT/BitVectorTest.cpp
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon May 14 08:46:27 PDT 2012
Author: stoklund
Date: Mon May 14 10:46:27 2012
New Revision: 156768
URL: http://llvm.org/viewvc/llvm-project?rev=156768&view=rev
Log:
Remove the expensive BitVector::operator~().
Returning a temporary BitVector is very expensive. If you must, create
the temporary explicitly: Use BitVector(A).flip() instead of ~A.
Modified:
llvm/trunk/include/llvm/ADT/BitVector.h
llvm/trunk/unittests/ADT/BitVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/BitVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/BitVector.h?rev=156768&r1=156767&r2=156768&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/BitVector.h (original)
+++ llvm/trunk/include/llvm/ADT/BitVector.h Mon May 14 10:46:27 2012
@@ -251,11 +251,6 @@
return *this;
}
- // No argument flip.
- BitVector operator~() const {
- return BitVector(*this).flip();
- }
-
// Indexing.
reference operator[](unsigned Idx) {
assert (Idx < Size && "Out-of-bounds Bit access.");
Modified: llvm/trunk/unittests/ADT/BitVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/BitVectorTest.cpp?rev=156768&r1=156767&r2=156768&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/BitVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/BitVectorTest.cpp Mon May 14 10:46:27 2012
@@ -42,7 +42,8 @@
EXPECT_FALSE(Vec.none());
EXPECT_FALSE(Vec.empty());
- BitVector Inv = ~Vec;
+ BitVector Inv = Vec;
+ Inv.flip();
EXPECT_EQ(6U, Inv.count());
EXPECT_EQ(11U, Inv.size());
EXPECT_TRUE(Inv.any());
@@ -52,7 +53,7 @@
EXPECT_FALSE(Inv == Vec);
EXPECT_TRUE(Inv != Vec);
- Vec = ~Vec;
+ Vec.flip();
EXPECT_TRUE(Inv == Vec);
EXPECT_FALSE(Inv != Vec);
@@ -131,7 +132,7 @@
EXPECT_TRUE(Vec.none());
EXPECT_FALSE(Vec.empty());
- Inv = ~BitVector();
+ Inv = BitVector().flip();
EXPECT_EQ(0U, Inv.count());
EXPECT_EQ(0U, Inv.size());
EXPECT_FALSE(Inv.any());
More information about the llvm-commits
mailing list