[libcxx-commits] [libcxx] 7402ec8 - [libc++] Remove if-else to make branch predictor happy

Mark de Wever via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 24 07:10:44 PDT 2021


Author: Shu Tian
Date: 2021-04-24T16:09:52+02:00
New Revision: 7402ec8f3877e061a6559c44262ec4d951d12cc7

URL: https://github.com/llvm/llvm-project/commit/7402ec8f3877e061a6559c44262ec4d951d12cc7
DIFF: https://github.com/llvm/llvm-project/commit/7402ec8f3877e061a6559c44262ec4d951d12cc7.diff

LOG: [libc++] Remove if-else to make branch predictor happy

Reviewed By: #libc, ldionne, Quuxplusone, Mordante

Differential Revision: https://reviews.llvm.org/D100828

Added: 
    

Modified: 
    libcxx/include/bitset

Removed: 
    


################################################################################
diff  --git a/libcxx/include/bitset b/libcxx/include/bitset
index a40d76296219..1a7e5d1f563a 100644
--- a/libcxx/include/bitset
+++ b/libcxx/include/bitset
@@ -775,10 +775,7 @@ bitset<_Size>::bitset(const _CharT* __str,
     for (; __i < _Mp; ++__i)
     {
         _CharT __c = __str[_Mp - 1 - __i];
-        if (__c == __zero)
-            (*this)[__i] = false;
-        else
-            (*this)[__i] = true;
+        (*this)[__i] = (__c == __one);
     }
     _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
 }
@@ -803,10 +800,7 @@ bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
     for (; __i < _Mp; ++__i)
     {
         _CharT __c = __str[__pos + _Mp - 1 - __i];
-        if (_Traits::eq(__c, __zero))
-            (*this)[__i] = false;
-        else
-            (*this)[__i] = true;
+        (*this)[__i] = _Traits::eq(__c, __one);
     }
     _VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
 }


        


More information about the libcxx-commits mailing list