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


##########
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),算是一点小优化吧。



-- 
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