wasphin commented on code in PR #2632:
URL: https://github.com/apache/brpc/pull/2632#discussion_r1597647990


##########
src/butil/thread_key.h:
##########
@@ -187,9 +205,9 @@ void ThreadLocal<T>::reset(T* ptr) {
         }
         // Remove and delete old_ptr.
         if (old_ptr) {
-            auto iter = std::find(ptrs.begin(), ptrs.end(), old_ptr);
-            if (iter!=ptrs.end()) {
-                ptrs.erase(iter);
+            auto iter = std::remove(ptrs.begin(), ptrs.end(), old_ptr);
+            if (iter != ptrs.end()) {
+                ptrs.erase(iter, ptrs.end());

Review Comment:
   > remove后erase的时间复杂度是O(1),find后erase的时间复杂度是O(n),算是一点小优化吧。
   
   这个提升是因为 remove 的时候的移动带来的吗?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to