From 9262293e2e00ac15578bc10954cec18a5f435084 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Thu, 3 Jan 2013 22:45:46 -0500 Subject: store possible device/card matches as pointers Avoid invoking the copy constructors and storing new objects which can't be returned (as they're local variables). --- pulse.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'pulse.cc') diff --git a/pulse.cc b/pulse.cc index f6b633b..d1d9359 100644 --- a/pulse.cc +++ b/pulse.cc @@ -151,11 +151,11 @@ Card* PulseClient::GetCard(const uint32_t& index) { Card* PulseClient::GetCard(const string& name) { long val; - vector res; + vector res; if (xstrtol(name.c_str(), &val) == 0) return GetCard(val); for (Card& card : cards_) { - if (card.name_.find(name) != string::npos) res.push_back(card); + if (card.name_.find(name) != string::npos) res.push_back(&card); } switch (res.size()) { @@ -165,9 +165,10 @@ Card* PulseClient::GetCard(const string& name) { break; default: warnx("warning: ambiguous result for '%s', using '%s'", - name.c_str(), res[0].name_.c_str()); + name.c_str(), res[0]->name_.c_str()); } - return &res[0]; + + return res[0]; } Card* PulseClient::GetCard(const Device& device) { @@ -187,11 +188,11 @@ Device* PulseClient::get_device(vector& devices, Device* PulseClient::get_device(vector& devices, const string& name) { long val; - vector res; + vector res; if (xstrtol(name.c_str(), &val) == 0) return get_device(devices, val); for (Device& device : devices) { - if (device.name_.find(name) != string::npos) res.push_back(device); + if (device.name_.find(name) != string::npos) res.push_back(&device); } switch (res.size()) { @@ -201,10 +202,10 @@ Device* PulseClient::get_device(vector& devices, const string& name) { break; default: warnx("warning: ambiguous result for '%s', using '%s'", - name.c_str(), res[0].name_.c_str()); + name.c_str(), res[0]->name_.c_str()); } - return &res[0]; + return res[0]; } Device* PulseClient::GetDevice(const uint32_t& index, enum DeviceType type) { -- cgit v1.2.3