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 fc24d8416ef8b1285b4cf1f22b6f80d0f7e4cec2..ad650fd9032e8f691a527f4554e6d76eee252b75 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 17e363aebd218384aa72de9e8b093e09d51bfde4..cb0c0b77d93bc07641a25a3371c1a22f32b3b3f1 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 7858a8889521aa98fd7813c23f43c6d10eb80785..20854d09003e38b951bc78d637e0f48c904a686c 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]");