[lld] r210084 - No need to compute valBit until mask bit is 1.

Rui Ueyama ruiu at google.com
Tue Jun 3 00:39:33 PDT 2014


Author: ruiu
Date: Tue Jun  3 02:39:32 2014
New Revision: 210084

URL: http://llvm.org/viewvc/llvm-project?rev=210084&view=rev
Log:
No need to compute valBit until mask bit is 1.

Modified:
    lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h

Modified: lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h?rev=210084&r1=210083&r2=210084&view=diff
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h (original)
+++ lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h Tue Jun  3 02:39:32 2014
@@ -21,10 +21,10 @@ template <typename T> T gatherBits(T val
   T result = 0;
   size_t off = 0;
 
-  for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) {
-    const bool valBit = (val >> bit) & 1;
-    const bool maskBit = (mask >> bit) & 1;
+  for (size_t bit = 0; bit < sizeof(T) * 8; ++bit) {
+    bool maskBit = (mask >> bit) & 1;
     if (maskBit) {
+      bool valBit = (val >> bit) & 1;
       result |= static_cast<T>(valBit) << off;
       ++off;
     }
@@ -41,10 +41,10 @@ template <typename T> T scatterBits(T va
   T result = 0;
   size_t off = 0;
 
-  for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) {
-    const bool valBit = (val >> off) & 1;
-    const bool maskBit = (mask >> bit) & 1;
+  for (size_t bit = 0; bit < sizeof(T) * 8; ++bit) {
+    bool maskBit = (mask >> bit) & 1;
     if (maskBit) {
+      bool valBit = (val >> off) & 1;
       result |= static_cast<T>(valBit) << bit;
       ++off;
     }





More information about the llvm-commits mailing list