Using reference to avoid copy
With this commit a reference will be used during some structure
binding to avoid copies.
Tested:
CPUSensors and PSUSensors launched on physical machine, no
regression detected.
Signed-off-by: Zbigniew Kurzynski <zbigniew.kurzynski@intel.com>
Change-Id: I7aa270e440e9aadeca151acc6d9b73d7c4c4f40c
diff --git a/src/CPUSensor.cpp b/src/CPUSensor.cpp
index 684c430..2356821 100644
--- a/src/CPUSensor.cpp
+++ b/src/CPUSensor.cpp
@@ -56,7 +56,7 @@
{
if (auto fileParts = splitFileName(path))
{
- auto [type, nr, item] = *fileParts;
+ auto& [type, nr, item] = *fileParts;
std::string interfacePath;
if (type.compare("power") == 0)
{
@@ -162,13 +162,13 @@
if (auto fileParts = splitFileName(path))
{
- auto [fileType, fileNr, fileItem] = *fileParts;
+ auto& [fileType, fileNr, fileItem] = *fileParts;
const auto mapIt = map.find(fileItem);
if (mapIt != map.cend())
{
for (const auto& vectorItem : mapIt->second)
{
- auto [suffix, oldValue, dbusName] = vectorItem;
+ auto& [suffix, oldValue, dbusName] = vectorItem;
auto attrPath = boost::replace_all_copy(path, fileItem, suffix);
if (auto newVal =
readFile(attrPath, CPUSensor::sensorScaleFactor))
diff --git a/src/CPUSensorMain.cpp b/src/CPUSensorMain.cpp
index 2261af7..dfc942f 100644
--- a/src/CPUSensorMain.cpp
+++ b/src/CPUSensorMain.cpp
@@ -312,7 +312,7 @@
{
continue;
}
- auto [type, nr, item] = *fileParts;
+ auto& [type, nr, item] = *fileParts;
auto inputPathStr = inputPath.string();
auto labelPath =
boost::replace_all_copy(inputPathStr, item, "label");
diff --git a/src/PSUSensor.cpp b/src/PSUSensor.cpp
index 5a3ecc2..25cc5ad 100644
--- a/src/PSUSensor.cpp
+++ b/src/PSUSensor.cpp
@@ -103,7 +103,7 @@
if (auto fileParts = splitFileName(path))
{
- auto [type, nr, item] = *fileParts;
+ auto& [type, nr, item] = *fileParts;
if (item.compare("input") == 0)
{
pathRatedMax = boost::replace_all_copy(path, item, "rated_max");
diff --git a/src/Thresholds.cpp b/src/Thresholds.cpp
index 6aa077c..f4d4ed0 100644
--- a/src/Thresholds.cpp
+++ b/src/Thresholds.cpp
@@ -480,12 +480,12 @@
if (auto fileParts = splitFileName(inputPath))
{
- auto [type, nr, item] = *fileParts;
+ auto& [type, nr, item] = *fileParts;
if (map.count(item) != 0)
{
for (const auto& t : map.at(item))
{
- auto [suffix, level, direction, offset] = t;
+ auto& [suffix, level, direction, offset] = t;
auto attrPath =
boost::replace_all_copy(inputPath, item, suffix);
if (auto val = readFile(attrPath, scaleFactor))