[libcxx-commits] [PATCH] D58332: Erase-Like Algorithms Should Return size_type (P0646R1)

Marshall Clow via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Apr 2 22:23:20 PDT 2019


mclow.lists requested changes to this revision.
mclow.lists added a comment.
This revision now requires changes to proceed.

You're going to have to find a different approach here.
Traversing the list to see how the size has changed is not acceptable.



================
Comment at: include/forward_list:1535
     iterator __e = end();
+    auto __start_count = _VSTD::distance(begin(), end());
     for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
----------------
This is an expensive operation, it requires traversing the list.
And you're doing it twice - once at the beginning, and once at the end.


================
Comment at: include/list:2158
+    
+    return _VSTD::distance(__deleted_nodes.begin(), __deleted_nodes.end());
 }
----------------
Just call `__deleted_notes.size()` It has constant complexity.


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D58332





More information about the libcxx-commits mailing list