Use reference type to reduce copy operation 91/295891/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 17 Jul 2023 01:20:40 +0000 (10:20 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Mon, 17 Jul 2023 01:20:40 +0000 (10:20 +0900)
- Issue:
When the code iterates the list, some code repeats the unnecessary copy
operation.

- Solution:
Normally, reference type is used when the list is iterated. However,
some code did not use reference type, so those code would repeat
unnecessary copy operation. So, this patch fixes those types to
reference. Through this patch, unnecessary copy operation will be
removed.

Change-Id: Ib64f990c0f33ba5eea2977a80db4765f539c5b04
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
plugins/wakeup-manager/src/heap_tracer.cpp
plugins/wakeup-manager/src/wakeup_engine_manager.cpp
src/service_main.cpp

index fc24d84..ad650fd 100644 (file)
@@ -185,7 +185,7 @@ std::string HeapTracer::Find(void *ptr)
 {
        std::lock_guard<std::mutex> lock(mManagedTableMutex);
 #ifdef RECORD_ALL_HISTORY
-       for (auto entry : mEntryHistory) {
+       for (auto& entry : mEntryHistory) {
                if (entry.entry.ptr == ptr) {
                        LOGD("Heap history record for %p : %s, %lld.%.9ld, %s",
                                ptr,
@@ -234,7 +234,7 @@ void HeapTracer::Trace()
        LOGD("Heap Trace Start");
 
        std::lock_guard<std::mutex> lock(mManagedTableMutex);
-       for (auto item : mManagedTable) {
+       for (auto& item : mManagedTable) {
                LOGD("No dealloc information exists for %p [size %d] : %s", item.first, item.second.size, item.second.description.c_str());
        }
        LOGD("Heap Trace End");
index 17e363a..cb0c0b7 100644 (file)
@@ -597,14 +597,14 @@ void CWakeupEngineManager::engine_add_target_assistant(string engine_name, strin
                        });
                if (mEngineInfo.end() != new_iter) {
                        new_iter->assistant_list.push_back(appid);
-                       for (const auto assistant : new_iter->assistant_list) {
+                       for (const auto& assistant : new_iter->assistant_list) {
                                MWR_LOGI("Assistant List : %s %s", assistant.c_str(), new_iter->engine_name.c_str());
                        }
                }
        } else {
                /* If the engine already exists, simply add the appid to the assistant list */
                iter->assistant_list.push_back(appid);
-               for (const auto assistant : iter->assistant_list) {
+               for (const auto& assistant : iter->assistant_list) {
                        MWR_LOGI("Assistant List : %s %s", assistant.c_str(), iter->engine_name.c_str());
                }
        }
index 7858a88..20854d0 100644 (file)
@@ -344,7 +344,7 @@ int CServiceMain::client_set_background_volume(pid_t pid, double ratio)
        if (history.size() > max_history_size) history.pop_back();
 
        std::stringstream ss;
-       for (auto item : history) {
+       for (auto& item : history) {
                std::time_t time_info = std::get<3>(item);
                char time_string[32];
                struct tm tm;
@@ -797,7 +797,7 @@ int CServiceMain::deinitialize_service_plugin(void)
                clients.push_back(mClientManager.find_client_pid_by_index(loop));
        }
 
-       for (auto pid : clients) {
+       for (auto& pid : clients) {
                on_deinitialize(pid, mClientManager.find_sender_info_by_pid(pid));
        }
        MAS_LOGI("[END]");