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

Unified Diff: content/child/webcrypto/test/test_helpers.cc

Issue 510583002: Improve a poor implementation of "find duplicates". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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 | « content/child/webcrypto/test/test_helpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/test/test_helpers.cc
diff --git a/content/child/webcrypto/test/test_helpers.cc b/content/child/webcrypto/test/test_helpers.cc
index 07462d637730ec0afcc167b6e59401ad89759911..64f27166d80afbb8f70623792afda1473658dc97 100644
--- a/content/child/webcrypto/test/test_helpers.cc
+++ b/content/child/webcrypto/test/test_helpers.cc
@@ -4,6 +4,8 @@
#include "content/child/webcrypto/test/test_helpers.h"
+#include <set>
+
#include "base/file_util.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
@@ -239,14 +241,11 @@ blink::WebCryptoAlgorithm GetDigestAlgorithm(base::DictionaryValue* dict,
return blink::WebCryptoAlgorithm::createNull();
}
-// Returns true if any of the vectors in the input list have identical content.
-// Dumb O(n^2) implementation but should be fast enough for the input sizes that
-// are used.
bool CopiesExist(const std::vector<std::vector<uint8_t> >& bufs) {
+ std::set<std::vector<uint8_t> > values;
for (size_t i = 0; i < bufs.size(); ++i) {
- for (size_t j = i + 1; j < bufs.size(); ++j) {
- if (CryptoData(bufs[i]) == CryptoData(bufs[j]))
- return true;
+ if (!values.insert(bufs[i]).second) {
+ return true;
}
Ryan Sleevi 2014/08/27 17:15:58 This seems to be memory intensive. Why not just s
eroman 2014/08/27 18:47:06 Done. I also modified it to sort a vector of indic
}
return false;
« no previous file with comments | « content/child/webcrypto/test/test_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698