summaryrefslogtreecommitdiffstats
path: root/net/base
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 16:59:05 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-06 16:59:05 +0000
commite32306c541215cf71e9464abc2f786f064dfff9a (patch)
tree317f56258ee444634faa472fc5337688f2f66f3b /net/base
parent1b82fd71be85bc66b0d893e085b5430ebf22bc43 (diff)
downloadchromium_src-e32306c541215cf71e9464abc2f786f064dfff9a.zip
chromium_src-e32306c541215cf71e9464abc2f786f064dfff9a.tar.gz
chromium_src-e32306c541215cf71e9464abc2f786f064dfff9a.tar.bz2
Preserve the output vector for cookie loading. This prevents a few unneeded vector growth / copies for the typical cookie database.
Review URL: http://codereview.chromium.org/9437 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4889 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r--net/base/cookie_monster.cc23
1 files changed, 13 insertions, 10 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index 987bfb8..adfd19b 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -68,6 +68,16 @@ using base::TimeDelta;
namespace net {
+// Cookie garbage collection thresholds. Based off of the Mozilla defaults.
+// It might seem scary to have a high purge value, but really it's not. You
+// just make sure that you increase the max to cover the increase in purge,
+// and we would have been purging the same amount of cookies. We're just
+// going through the garbage collection process less often.
+static const size_t kNumCookiesPerHost = 70; // ~50 cookies
+static const size_t kNumCookiesPerHostPurge = 20;
+static const size_t kNumCookiesTotal = 1100; // ~1000 cookies
+static const size_t kNumCookiesTotalPurge = 100;
+
// Default minimum delay after updating a cookie's LastAccessDate before we
// will update it again.
static const int kDefaultAccessUpdateThresholdSeconds = 60;
@@ -105,6 +115,9 @@ void CookieMonster::InitStore() {
// care if it's expired, insert it so it can be garbage collected, removed,
// and sync'd.
std::vector<KeyedCanonicalCookie> cookies;
+ // Reserve space for the maximum amount of cookies a database should have.
+ // This prevents multiple vector growth / copies as we append cookies.
+ cookies.reserve(kNumCookiesTotal);
store_->Load(&cookies);
for (std::vector<KeyedCanonicalCookie>::const_iterator it = cookies.begin();
it != cookies.end(); ++it) {
@@ -499,16 +512,6 @@ void CookieMonster::DeleteAnyEquivalentCookie(const std::string& key,
int CookieMonster::GarbageCollect(const Time& current,
const std::string& key) {
- // Based off of the Mozilla defaults.
- // It might seem scary to have a high purge value, but really it's not. You
- // just make sure that you increase the max to cover the increase in purge,
- // and we would have been purging the same amount of cookies. We're just
- // going through the garbage collection process less often.
- static const size_t kNumCookiesPerHost = 70; // ~50 cookies
- static const size_t kNumCookiesPerHostPurge = 20;
- static const size_t kNumCookiesTotal = 1100; // ~1000 cookies
- static const size_t kNumCookiesTotalPurge = 100;
-
int num_deleted = 0;
// Collect garbage for this key.