Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(577)

Unified Diff: components/ssl_errors/error_classification.cc

Issue 1690593002: Reduce memory use of GetLevenshteinDistance() by almost 50% (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ssl_errors/error_classification.cc
diff --git a/components/ssl_errors/error_classification.cc b/components/ssl_errors/error_classification.cc
index c2e4d8f96eea50440afbafa576be350d88996e63..dccacbc9bab99f49962910deae294713440ae664 100644
--- a/components/ssl_errors/error_classification.cc
+++ b/components/ssl_errors/error_classification.cc
@@ -296,23 +296,22 @@ size_t GetLevenshteinDistance(const std::string& str1,
return str2.size();
if (str2.size() == 0)
return str1.size();
- std::vector<size_t> kFirstRow(str2.size() + 1, 0);
- std::vector<size_t> kSecondRow(str2.size() + 1, 0);
- for (size_t i = 0; i < kFirstRow.size(); ++i)
- kFirstRow[i] = i;
+ std::vector<size_t> row(str2.size() + 1);
+ for (size_t i = 0; i < row.size(); ++i)
+ row[i] = i;
+
for (size_t i = 0; i < str1.size(); ++i) {
- kSecondRow[0] = i + 1;
+ row[0] = i + 1;
+ size_t previous = i;
for (size_t j = 0; j < str2.size(); ++j) {
+ size_t old_row = row[j + 1];
int cost = str1[i] == str2[j] ? 0 : 1;
- kSecondRow[j + 1] =
- std::min(std::min(kSecondRow[j] + 1, kFirstRow[j + 1] + 1),
- kFirstRow[j] + cost);
+ row[j + 1] = std::min(std::min(row[j], row[j + 1]) + 1, previous + cost);
+ previous = old_row;
}
- for (size_t j = 0; j < kFirstRow.size(); j++)
- kFirstRow[j] = kSecondRow[j];
}
- return kSecondRow[str2.size()];
+ return row[str2.size()];
}
bool IsSubDomainOutsideWildcard(const GURL& request_url,
@@ -380,11 +379,11 @@ bool IsCertLikelyFromMultiTenantHosting(const GURL& request_url,
// considered as a shared certificate. Include the host name in the URL also
// while comparing.
dns_names.push_back(host_name);
- static const size_t kMinimumEditDsitance = 5;
+ static const size_t kMinimumEditDistance = 5;
for (size_t i = 0; i < dns_names_size; ++i) {
for (size_t j = i + 1; j < dns_names_size; ++j) {
size_t edit_distance = GetLevenshteinDistance(dns_names[i], dns_names[j]);
- if (edit_distance < kMinimumEditDsitance)
+ if (edit_distance < kMinimumEditDistance)
return false;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698