aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-03 22:45:46 -0500
committerDave Reisner <dreisner@archlinux.org>2013-01-03 22:45:46 -0500
commit9262293e2e00ac15578bc10954cec18a5f435084 (patch)
tree4b675738de302c15d025b46c39a2776c280ced19
parent81d7ece0122dd853f18b9c041ac3cf0c52ad5847 (diff)
downloadmirror-ponymix-9262293e2e00ac15578bc10954cec18a5f435084.tar.gz
mirror-ponymix-9262293e2e00ac15578bc10954cec18a5f435084.tar.bz2
mirror-ponymix-9262293e2e00ac15578bc10954cec18a5f435084.zip
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).
-rw-r--r--pulse.cc17
1 files changed, 9 insertions, 8 deletions
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<Card> res;
+ vector<Card*> 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<Device>& devices,
Device* PulseClient::get_device(vector<Device>& devices, const string& name) {
long val;
- vector<Device> res;
+ vector<Device*> 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<Device>& 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) {