[libcxx-commits] [libcxx] c30d510 - [libc++] Optimize the number of assignments in std::exclusive_scan

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 1 09:49:56 PST 2020


Author: Louis Dionne
Date: 2020-12-01T12:49:45-05:00
New Revision: c30d5101f14f7e8a1c0f80c8663b54de2a7640fd

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

LOG: [libc++] Optimize the number of assignments in std::exclusive_scan

Reported in https://twitter.com/blelbach/status/1169807347142676480

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

Added: 
    

Modified: 
    libcxx/include/numeric

Removed: 
    


################################################################################
diff  --git a/libcxx/include/numeric b/libcxx/include/numeric
index 5c10dd3c1e67..ed06fcc49d5b 100644
--- a/libcxx/include/numeric
+++ b/libcxx/include/numeric
@@ -335,14 +335,17 @@ exclusive_scan(_InputIterator __first, _InputIterator __last,
 {
     if (__first != __last)
     {
-        _Tp __saved = __init;
-        do
+        _Tp __tmp(__b(__init, *__first));
+        while (true)
         {
-            __init = __b(__init, *__first);
-            *__result = __saved;
-            __saved = __init;
+            *__result = _VSTD::move(__init);
             ++__result;
-        } while (++__first != __last);
+            ++__first;
+            if (__first == __last)
+                break;
+            __init = _VSTD::move(__tmp);
+            __tmp = __b(__init, *__first);
+        }
     }
     return __result;
 }


        


More information about the libcxx-commits mailing list