Fix incorrect log message in FilterNetworks function.

This log should print removed elements in 'networks' which pointer to
vector<Network*> really. But it was printing just tailing elements of
the vector. For example, assume that there are 4 elements in 'networks',
and 1st and 3rd elements are removed. Then 'networks' will be changed
like this.

<Before>
[0] id = 1
[1] id = 2
[2] id = 3
[3] id = 4

<After>
[0] id = 2
[1] id = 4

Then this log should print the elements with id=1, id=3 which removed.
But currently it is printing the elements with id=3 and id=4 which
tailing 2 elements of the vector. It's related with how std::remove_if
works. So I replaced it with std::partition.

Bug: none
Change-Id: Idfdae04f2d321212310bddb4d8742ba2dccc4db9
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159060
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30082}
This commit is contained in:
Sungwoo 2019-12-05 11:24:50 +09:00 committed by Commit Bot
parent 9338bbcd90
commit d77c829d37

View file

@ -95,15 +95,16 @@ int ComparePort(const cricket::Port* a, const cricket::Port* b) {
struct NetworkFilter {
using Predicate = std::function<bool(rtc::Network*)>;
NetworkFilter(Predicate pred, const std::string& description)
: pred(pred), description(description) {}
Predicate pred;
: predRemain([pred](rtc::Network* network) { return !pred(network); }),
description(description) {}
Predicate predRemain;
const std::string description;
};
using NetworkList = rtc::NetworkManager::NetworkList;
void FilterNetworks(NetworkList* networks, NetworkFilter filter) {
auto start_to_remove =
std::remove_if(networks->begin(), networks->end(), filter.pred);
std::partition(networks->begin(), networks->end(), filter.predRemain);
if (start_to_remove == networks->end()) {
return;
}