diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:05:21 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 20:05:21 +0000 |
commit | b2f0ea1a109f6406d6633f51adb4621090b9032d (patch) | |
tree | 8e55db87473c159a3b33ab71091938298e9d1d52 /base | |
parent | ed157a21f003e2dd212d84fa81663c8fc95c8965 (diff) | |
download | chromium_src-b2f0ea1a109f6406d6633f51adb4621090b9032d.zip chromium_src-b2f0ea1a109f6406d6633f51adb4621090b9032d.tar.gz chromium_src-b2f0ea1a109f6406d6633f51adb4621090b9032d.tar.bz2 |
Make swapping the incoming queue with the work queue constant time.
This is an alternative to the fix proposed here:
http://codereview.chromium.org/172101
Credit goes to Dean McNamee for discovering this performance issue!
R=deanm
BUG=20204
TEST=none
Review URL: http://codereview.chromium.org/190006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25223 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/message_loop.cc | 2 | ||||
-rw-r--r-- | base/message_loop.h | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index 5464670..bf5256a 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -354,7 +354,7 @@ void MessageLoop::ReloadWorkQueue() { AutoLock lock(incoming_queue_lock_); if (incoming_queue_.empty()) return; - std::swap(incoming_queue_, work_queue_); + incoming_queue_.Swap(&work_queue_); // Constant time DCHECK(incoming_queue_.empty()); } } diff --git a/base/message_loop.h b/base/message_loop.h index 395ce6e..d2fcc12 100644 --- a/base/message_loop.h +++ b/base/message_loop.h @@ -281,7 +281,13 @@ class MessageLoop : public base::MessagePump::Delegate { bool operator<(const PendingTask& other) const; }; - typedef std::queue<PendingTask> TaskQueue; + class TaskQueue : public std::queue<PendingTask> { + public: + void Swap(TaskQueue* queue) { + c.swap(queue->c); // Calls std::deque::swap + } + }; + typedef std::priority_queue<PendingTask> DelayedTaskQueue; #if defined(OS_WIN) |