From d77c829d37808f53692196b92fb838c15df1e4ea Mon Sep 17 00:00:00 2001 From: Sungwoo Date: Thu, 5 Dec 2019 11:24:50 +0900 Subject: [PATCH] Fix incorrect log message in FilterNetworks function. This log should print removed elements in 'networks' which pointer to vector 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. [0] id = 1 [1] id = 2 [2] id = 3 [3] id = 4 [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 Reviewed-by: Niels Moller Commit-Queue: Niels Moller Cr-Commit-Position: refs/heads/master@{#30082} --- p2p/client/basic_port_allocator.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc index 216e737ffb..527410a0f0 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc @@ -95,15 +95,16 @@ int ComparePort(const cricket::Port* a, const cricket::Port* b) { struct NetworkFilter { using Predicate = std::function; 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; }