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

Unified Diff: sdk/lib/async/timer.dart

Issue 12316103: Introduce optimized Timer.run queue for immediate runs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | tests/isolate/timer_cancel_test.dart » ('j') | tests/standalone/standalone.status » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/async/timer.dart
diff --git a/sdk/lib/async/timer.dart b/sdk/lib/async/timer.dart
index 39fe4c2df6202e1500940372e47d2583085f16b8..7df5e6cbdc1840825a121196643d1e7bc448e019 100644
--- a/sdk/lib/async/timer.dart
+++ b/sdk/lib/async/timer.dart
@@ -5,6 +5,9 @@
part of dart.async;
abstract class Timer {
+ // Internal queue used to group Timer.run callbacks.
+ static Queue _queue = new Queue();
floitsch 2013/02/25 16:07:13 A list is good enough.
Anders Johnsen 2013/02/25 16:25:18 Done.
+
/**
* Creates a new timer.
*
@@ -51,8 +54,19 @@ abstract class Timer {
* Returns a [Timer] that can be cancelled if the callback is not necessary
floitsch 2013/02/25 16:07:13 Update comment.
Anders Johnsen 2013/06/11 12:14:31 Done.
* anymore.
*/
- static Timer run(void callback()) {
- return new Timer(const Duration(), callback);
+ static void run(void callback()) {
Søren Gjesse 2013/02/25 16:00:38 I don't see any problem with this not having any o
Anders Johnsen 2013/02/25 16:25:18 Done.
+ bool run = _queue.isEmpty;
+ _queue.addLast(callback);
+ if (run) {
+ new Timer(const Duration(), () {
floitsch 2013/02/25 16:07:13 Duration(milliseconds: 0)
Anders Johnsen 2013/02/25 16:25:18 Done.
+ var queue = _queue;
floitsch 2013/02/25 16:07:13 Use type.
Anders Johnsen 2013/02/25 16:25:18 Done.
+ _queue = new Queue();
Søren Gjesse 2013/02/25 16:00:38 Please make a comment to why you create a new queu
Anders Johnsen 2013/02/25 16:25:18 Done.
+ while (!queue.isEmpty) {
floitsch 2013/02/25 16:07:13 With the list: function runQueued(List queued, int
Anders Johnsen 2013/02/25 16:25:18 Didn't do exactly this, but close.
+ // Let it fall-through, as we already are at the top of the stack.
+ queue.removeFirst()();
+ }
+ });
+ }
}
/**
« no previous file with comments | « no previous file | tests/isolate/timer_cancel_test.dart » ('j') | tests/standalone/standalone.status » ('J')

Powered by Google App Engine
This is Rietveld 408576698