OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library web_ui.src.utils_observe; | 5 library web_ui.src.utils_observe; |
6 | 6 |
| 7 import 'dart:async'; |
7 import 'dart:collection'; | 8 import 'dart:collection'; |
8 import 'dart:isolate'; | |
9 | 9 |
10 // TODO(jmesserly): helpers to combine hash codes. Reuse these from somewhere. | 10 // TODO(jmesserly): helpers to combine hash codes. Reuse these from somewhere. |
11 hash2(x, y) => x.hashCode * 31 + y.hashCode; | 11 hash2(x, y) => x.hashCode * 31 + y.hashCode; |
12 | 12 |
13 hash3(x, y, z) => hash2(hash2(x, y), z); | 13 hash3(x, y, z) => hash2(hash2(x, y), z); |
14 | 14 |
15 hash4(w, x, y, z) => hash2(hash2(w, x), hash2(y, z)); | 15 hash4(w, x, y, z) => hash2(hash2(w, x), hash2(y, z)); |
16 | 16 |
17 // TODO(jmesserly): replace with something in dart:async, as long as it is based | |
18 // on window.setImmediate/mutation observers/postMessage and not setTimeout(0) | |
19 // Maybe we can use Future.value? We need it to be fast (next microtask) | |
20 // like this though: http://dartbug.com/8757. | |
21 /** | |
22 * Adds an event to call [callback], so the event loop will call this after the | |
23 * current stack has unwound. | |
24 */ | |
25 void setImmediate(void callback()) { | |
26 var port = new ReceivePort(); | |
27 port.receive((msg, sendPort) { | |
28 port.close(); | |
29 callback(); | |
30 }); | |
31 port.toSendPort().send(null); | |
32 } | |
33 | |
34 class Arrays { | 17 class Arrays { |
35 static void copy(List src, int srcStart, | 18 static void copy(List src, int srcStart, |
36 List dst, int dstStart, int count) { | 19 List dst, int dstStart, int count) { |
37 if (srcStart == null) srcStart = 0; | 20 if (srcStart == null) srcStart = 0; |
38 if (dstStart == null) dstStart = 0; | 21 if (dstStart == null) dstStart = 0; |
39 | 22 |
40 if (srcStart < dstStart) { | 23 if (srcStart < dstStart) { |
41 for (int i = srcStart + count - 1, j = dstStart + count - 1; | 24 for (int i = srcStart + count - 1, j = dstStart + count - 1; |
42 i >= srcStart; i--, j--) { | 25 i >= srcStart; i--, j--) { |
43 dst[j] = src[i]; | 26 dst[j] = src[i]; |
(...skipping 17 matching lines...) Expand all Loading... |
61 String message = "$start + $length must be in the range [0..${a.length})"; | 44 String message = "$start + $length must be in the range [0..${a.length})"; |
62 throw new RangeError(message); | 45 throw new RangeError(message); |
63 } | 46 } |
64 } | 47 } |
65 } | 48 } |
66 | 49 |
67 // TODO(jmesserly): bogus type to workaround spurious VM bug with generic base | 50 // TODO(jmesserly): bogus type to workaround spurious VM bug with generic base |
68 // class and mixins. | 51 // class and mixins. |
69 abstract class IterableWorkaround extends IterableBase<dynamic> {} | 52 abstract class IterableWorkaround extends IterableBase<dynamic> {} |
70 abstract class ListMixinWorkaround extends ListMixin<dynamic> {} | 53 abstract class ListMixinWorkaround extends ListMixin<dynamic> {} |
OLD | NEW |