Commit 0dec011a956eeb8328d710dad18a442397ba4732
1 parent
3d4890c5
remove inefficient duplicate removal and check for duplicates in serch loop to i…
…mprove overal performance
Showing
1 changed file
with
8 additions
and
6 deletions
hueplusplus/UPnP.cpp
| ... | ... | @@ -34,15 +34,17 @@ std::vector<std::pair<std::string, std::string>> UPnP::getDevices() |
| 34 | 34 | { |
| 35 | 35 | std::pair<std::string, std::string> device; |
| 36 | 36 | int start = s.find("LOCATION:") + 10; |
| 37 | - std::cout << "Found \"LOCATION:\" at " << start << std::endl; | |
| 38 | 37 | device.first = s.substr(start, s.find("\r\n", start)-start); |
| 39 | 38 | start = s.find("SERVER:") + 8; |
| 40 | 39 | device.second = s.substr(start, s.find("\r\n", start) - start); |
| 41 | - devices.push_back(device); | |
| 42 | - } | |
| 43 | - | |
| 44 | - // remove duplicates -> maybe include this in device filtering without the need of unique and stuff? | |
| 45 | - devices.erase(std::unique(devices.begin(), devices.end()), devices.end()); | |
| 40 | + if(std::find_if(devices.begin(), devices.end(), [&](const std::pair<std::string, std::string> &item){return item.first == device.first;}) == devices.end()) | |
| 41 | + { | |
| 42 | + devices.push_back(device); | |
| 46 | 43 | |
| 44 | + //std::cout << "Device: \t" << device.first << std::endl; | |
| 45 | + //std::cout << " \t" << device.second << std::endl; | |
| 46 | + } | |
| 47 | + } | |
| 47 | 48 | return devices; |
| 48 | 49 | } |
| 50 | + | ... | ... |