Skip to content

Commit

Permalink
Optimize list append
Browse files Browse the repository at this point in the history
  • Loading branch information
lkpworkspace committed May 24, 2024
1 parent e8cf2f6 commit c272690
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
7 changes: 0 additions & 7 deletions myframe/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ class MYFRAME_EXPORT Common final {
static stdfs::path GetAbsolutePath(const std::string& flag_path);
static bool IsAbsolutePath(const std::string& path);

template <typename T>
static void ListAppend(
std::list<std::shared_ptr<T>>* dst,
std::list<std::shared_ptr<T>>* src) {
dst->insert(dst->end(), src->begin(), src->end());
src->clear();
}
static std::vector<std::string> SplitMsgName(const std::string& name);
};

Expand Down
5 changes: 2 additions & 3 deletions myframe/mailbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ All rights reserved.
Author: 李柯鹏 <[email protected]>
****************************************************************************/
#include "myframe/mailbox.h"
#include "myframe/common.h"
#include "myframe/msg.h"

namespace myframe {
Expand Down Expand Up @@ -51,7 +50,7 @@ void Mailbox::Send(
}

void Mailbox::Send(std::list<std::shared_ptr<Msg>>* msg_list) {
Common::ListAppend(&send_, msg_list);
send_.splice(send_.end(), *msg_list);
}

std::list<std::shared_ptr<Msg>>* Mailbox::GetSendList() {
Expand All @@ -75,7 +74,7 @@ void Mailbox::Recv(std::shared_ptr<Msg> msg) {
}

void Mailbox::Recv(std::list<std::shared_ptr<Msg>>* msg_list) {
Common::ListAppend(&recv_, msg_list);
recv_.splice(recv_.end(), *msg_list);
}

const std::shared_ptr<const Msg> Mailbox::PopRecv() {
Expand Down
3 changes: 1 addition & 2 deletions myframe/worker_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Author: 李柯鹏 <[email protected]>
#include <functional>

#include "myframe/log.h"
#include "myframe/common.h"
#include "myframe/msg.h"
#include "myframe/worker.h"
#include "myframe/app.h"
Expand Down Expand Up @@ -90,7 +89,7 @@ void WorkerContext::Cache(std::shared_ptr<Msg> msg) {
}

void WorkerContext::Cache(std::list<std::shared_ptr<Msg>>* msg_list) {
Common::ListAppend(&cache_, msg_list);
cache_.splice(cache_.end(), *msg_list);
}

Mailbox* WorkerContext::GetMailbox() {
Expand Down

0 comments on commit c272690

Please sign in to comment.