OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.utilities.general; | 5 library engine.utilities.general; |
6 | 6 |
7 import 'dart:profiler'; | 7 import 'dart:developer' show UserTag; |
8 | 8 |
9 /** | 9 /** |
10 * Jenkins hash function, optimized for small integers. | 10 * Jenkins hash function, optimized for small integers. |
11 * Borrowed from sdk/lib/math/jenkins_smi_hash.dart. | 11 * Borrowed from sdk/lib/math/jenkins_smi_hash.dart. |
12 */ | 12 */ |
13 class JenkinsSmiHash { | 13 class JenkinsSmiHash { |
14 static int combine(int hash, int value) { | 14 static int combine(int hash, int value) { |
15 hash = 0x1fffffff & (hash + value); | 15 hash = 0x1fffffff & (hash + value); |
16 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); | 16 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); |
17 return hash ^ (hash >> 6); | 17 return hash ^ (hash >> 6); |
18 } | 18 } |
19 | 19 |
20 static int finish(int hash) { | 20 static int finish(int hash) { |
21 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 21 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
22 hash = hash ^ (hash >> 11); | 22 hash = hash ^ (hash >> 11); |
23 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 23 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
24 } | 24 } |
25 | 25 |
26 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 26 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
27 | 27 |
28 static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c)); | 28 static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c)); |
29 | 29 |
30 static int hash4(a, b, c, d) => | 30 static int hash4(a, b, c, d) => |
31 finish(combine(combine(combine(combine(0, a), b), c), d)); | 31 finish(combine(combine(combine(combine(0, a), b), c), d)); |
32 } | 32 } |
33 | 33 |
34 /** | 34 /** |
35 * Helper class for gathering performance statistics. This class is modeled on | 35 * Helper class for gathering performance statistics. This class is modeled on |
36 * the UserTag class in dart:profiler so that it can interoperate easily with | 36 * the UserTag class in dart:developer so that it can interoperate easily with |
37 * it. | 37 * it. |
38 */ | 38 */ |
39 abstract class PerformanceTag { | 39 abstract class PerformanceTag { |
40 /** | 40 /** |
41 * Return a list of all [PerformanceTag]s which have been created. | 41 * Return a list of all [PerformanceTag]s which have been created. |
42 */ | 42 */ |
43 static List<PerformanceTag> get all => _PerformanceTagImpl.all.toList(); | 43 static List<PerformanceTag> get all => _PerformanceTagImpl.all.toList(); |
44 | 44 |
45 /** | 45 /** |
46 * Return the current [PerformanceTag] for the isolate. | 46 * Return the current [PerformanceTag] for the isolate. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 makeCurrentWhile(f()) { | 146 makeCurrentWhile(f()) { |
147 PerformanceTag prevTag = makeCurrent(); | 147 PerformanceTag prevTag = makeCurrent(); |
148 try { | 148 try { |
149 return f(); | 149 return f(); |
150 } finally { | 150 } finally { |
151 prevTag.makeCurrent(); | 151 prevTag.makeCurrent(); |
152 } | 152 } |
153 } | 153 } |
154 } | 154 } |
OLD | NEW |