Replace Get* methods returning unique_ptr with reference alternative
Existing code created temporarily objects and returned them to the
client. It was not efficient and error-prone as client code could
retrieve pointers to internal objects without keeping unique_ptr alive.
Change-Id: I9e17c8d9f66dfc9f52ce9ffc9a31992b16b00461
Reviewed-on: https://weave-review.googlesource.com/1672
Reviewed-by: Alex Vakulenko <avakulenko@google.com>
diff --git a/examples/daemon/ledflasher/ledflasher.cc b/examples/daemon/ledflasher/ledflasher.cc
index 4733f18..9e4a9e1 100644
--- a/examples/daemon/ledflasher/ledflasher.cc
+++ b/examples/daemon/ledflasher/ledflasher.cc
@@ -66,10 +66,10 @@
return;
LOG(INFO) << "received command: " << cmd->GetName();
int32_t led_index = 0;
- auto params = cmd->GetParameters();
+ const auto& params = cmd->GetParameters();
bool cmd_value = false;
- if (params->GetInteger("_led", &led_index) &&
- params->GetBoolean("_on", &cmd_value)) {
+ if (params.GetInteger("_led", &led_index) &&
+ params.GetBoolean("_on", &cmd_value)) {
// Display this command in terminal
LOG(INFO) << cmd->GetName() << " _led: " << led_index
<< ", _on: " << (cmd_value ? "true" : "false");
@@ -96,9 +96,9 @@
if (!cmd)
return;
LOG(INFO) << "received command: " << cmd->GetName();
- auto params = cmd->GetParameters();
+ const auto& params = cmd->GetParameters();
int32_t led_index = 0;
- if (params->GetInteger("_led", &led_index)) {
+ if (params.GetInteger("_led", &led_index)) {
LOG(INFO) << cmd->GetName() << " _led: " << led_index;
led_index--;
led_status_[led_index] = ~led_status_[led_index];