[libcxx-commits] [PATCH] D67273: [libc++] Remove unnecessary assignment in exclusive_scan

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 25 12:16:23 PST 2020


ldionne added inline comments.


================
Comment at: libcxx/include/numeric:311
     {
-        _Tp __saved = __init;
-        do
+        _Tp __tmp(__b(__init, *__first));
+        while (true)
----------------
curdeius wrote:
> Wouldn't you want to move this line into the loop, and so remove the assignment to `__tmp` at the end of the loop?
> It will remove code duplication and should be the same performance-wise.
As Billy mentioned in an earlier comment, this would trade 1 construction, N assignments and 1 destruction for N constructions, and N destructions.

If we think about a string, for example, I believe this version with N assignments would be faster. WDYT?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67273/new/

https://reviews.llvm.org/D67273



More information about the libcxx-commits mailing list