Chromium Code Reviews| Index: net/dns/dns_util.cc |
| diff --git a/net/dns/dns_util.cc b/net/dns/dns_util.cc |
| index 5f10ad2365ff07be8ea85172bcb96497bb4fc46f..48be035c0e3380d37f5aa0d29e3406760b97db6d 100644 |
| --- a/net/dns/dns_util.cc |
| +++ b/net/dns/dns_util.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| #include "build/build_config.h" |
| +#include "net/base/address_list.h" |
| #if defined(OS_POSIX) |
| #include <netinet/in.h> |
| @@ -192,4 +193,35 @@ base::TimeDelta GetTimeDeltaForConnectionTypeFromFieldTrialOrDefault( |
| } |
| #endif // !defined(OS_NACL) |
| +AddressListDeltaType FindAddressListDeltaType(const AddressList& a, |
| + const AddressList& b) { |
| + bool pairwise_mismatch = false; |
| + bool any_match = false; |
| + bool any_missing = false; |
|
Randy Smith (Not in Mondays)
2016/05/04 18:15:25
Suggestion: I apologize for the persnicketyness, b
|
| + bool same_size = a.size() == b.size(); |
| + |
| + for (size_t i = 0; i < a.size(); ++i) { |
| + bool this_match = false; |
| + for (size_t j = 0; j < b.size(); ++j) { |
| + if (a[i] == b[j]) { |
| + any_match = true; |
| + this_match = true; |
| + } else if (i == j) { |
| + pairwise_mismatch = true; |
| + } |
| + } |
| + if (!this_match) |
| + any_missing = true; |
| + } |
| + |
| + if (same_size && !pairwise_mismatch) |
| + return DELTA_IDENTICAL; |
| + else if (same_size && !any_missing) |
| + return DELTA_REORDERED; |
|
Randy Smith (Not in Mondays)
2016/05/04 18:15:25
Can the address lists ever have duplicates? Does
|
| + else if (any_match) |
| + return DELTA_OVERLAP; |
| + else |
| + return DELTA_DISJOINT; |
| +} |
| + |
| } // namespace net |