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

Unified Diff: net/base/registry_controlled_domains/registry_controlled_domain.cc

Issue 2612313003: Optimize SameDomainOrHost via a fast-fail path
Patch Set: Created 3 years, 11 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: net/base/registry_controlled_domains/registry_controlled_domain.cc
diff --git a/net/base/registry_controlled_domains/registry_controlled_domain.cc b/net/base/registry_controlled_domains/registry_controlled_domain.cc
index 5f29f89f27cacdd71154db87177dd39ab6a224da..73d5cc1134fe4e864b4b727e146d15784e7476ff 100644
--- a/net/base/registry_controlled_domains/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domains/registry_controlled_domain.cc
@@ -321,11 +321,28 @@ bool SameDomainOrHost(base::StringPiece host1,
if (host1 == host2)
return true;
- // Check for a domain and registry match.
- const base::StringPiece& domain1 =
+ const base::StringPiece domain1 =
GetDomainAndRegistryAsStringPiece(host1, filter);
- return !domain1.empty() &&
- (domain1 == GetDomainAndRegistryAsStringPiece(host2, filter));
+
+ // If |domain1| is empty, |host1| either matched no rules in the registry,
+ // or is an IP literal. Since |host2| and |host1| are known to differ,
+ // they can't possibly be same-origin.
+ if (domain1.empty())
+ return false;
+
+ // Fail fast before computing |domain2|, if possible, by checking to see if
+ // |domain1| is a suffix of |host2|. This is a necessary but not sufficient
+ // condition for |domain1| and |domain2| to be equal.
+ if (!base::EndsWith(host2, domain1, base::CompareCase::SENSITIVE))
Ryan Sleevi 2017/01/06 00:38:16 Unclear if you're doing sensitive as an optimizati
+ return false;
+
+ const base::StringPiece domain2 =
+ GetDomainAndRegistryAsStringPiece(host2, filter);
+
+ // We already verified that |domain1| is a suffix of |host2|. And |domain2| is
+ // also a suffix of |host2|, by construction. So if their lengths are equal,
+ // they are identical.
+ return domain2.length() == domain1.length();
}
} // namespace
« 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