ソースを参照

optimize by std::move

hewei.it 4 年 前
コミット
8ae57cab1b
5 ファイル変更9 行追加8 行削除
  1. 1 1
      evpp/Channel.h
  2. 2 2
      evpp/Event.h
  3. 3 2
      evpp/EventLoop.h
  4. 1 1
      http/client/AsyncHttpClient.h
  5. 2 2
      http/server/HttpService.h

+ 1 - 1
evpp/Channel.h

@@ -186,7 +186,7 @@ public:
 
     void setHeartbeat(int interval_ms, std::function<void()> fn) {
         if (io_ == NULL) return;
-        heartbeat = fn;
+        heartbeat = std::move(fn);
         hio_set_heartbeat(io_, interval_ms, send_heartbeat);
     }
 

+ 2 - 2
evpp/Event.h

@@ -23,7 +23,7 @@ struct Event {
 
     Event(EventCallback cb = NULL) {
         memset(&event, 0, sizeof(hevent_t));
-        this->cb = cb;
+        this->cb = std::move(cb);
     }
 };
 
@@ -34,7 +34,7 @@ struct Timer {
 
     Timer(htimer_t* timer = NULL, TimerCallback cb = NULL, int repeat = INFINITE) {
         this->timer = timer;
-        this->cb = cb;
+        this->cb = std::move(cb);
         this->repeat = repeat;
     }
 };

+ 3 - 2
evpp/EventLoop.h

@@ -125,6 +125,7 @@ public:
     }
 
     bool isInLoopThread() {
+        if (loop_ == NULL) return false;
         return hv_gettid() == hloop_tid(loop_);
     }
 
@@ -133,10 +134,10 @@ public:
     }
 
     void runInLoop(Functor fn) {
-        if (isInLoopThread()) {
+        if (isRunning() && isInLoopThread()) {
             if (fn) fn();
         } else {
-            queueInLoop(fn);
+            queueInLoop(std::move(fn));
         }
     }
 

+ 1 - 1
http/client/AsyncHttpClient.h

@@ -115,7 +115,7 @@ public:
     int send(const HttpRequestPtr& req, HttpResponseCallback resp_cb) {
         HttpClientTaskPtr task(new HttpClientTask);
         task->req = req;
-        task->cb = resp_cb;
+        task->cb = std::move(resp_cb);
         task->start_time = hloop_now_hrtime(loop_thread.hloop());
         task->retry_cnt = DEFAULT_FAIL_RETRY_COUNT;
         task->retry_delay = DEFAULT_FAIL_RETRY_DELAY;

+ 2 - 2
http/server/HttpService.h

@@ -34,8 +34,8 @@ struct http_method_handler {
                         http_async_handler a = NULL)
     {
         method = m;
-        sync_handler = s;
-        async_handler = a;
+        sync_handler = std::move(s);
+        async_handler = std::move(a);
     }
 };
 // method => http_sync_handler