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

Rui Ueyama ruiu at google.com
Tue Jun 3 02:11:36 PDT 2014


Because their scopes are only a few lines, and it's obvious that constness
of these variables doesn't matter. It feels even a little bit odd, because
as far as I can tell we don't usually add const to such variable in other
places.


On Tue, Jun 3, 2014 at 2:06 AM, Daniil Troshkov <troshkovdanil at gmail.com>
wrote:

> why are you choosing "bool maskBit" instead of "const bool maskBit"?
>
>
> 2014-06-03 11:39 GMT+04:00 Rui Ueyama <ruiu at google.com>:
>
> 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;
>>      }
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140603/9ff39d5b/attachment.html>


More information about the llvm-commits mailing list