| 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 // This code was auto-generated, is not intended to be edited, and is subject to | |
| 6 // significant change. Please see the README file for more information. | |
| 7 | |
| 8 library engine.utilities.general; | 5 library engine.utilities.general; |
| 9 | 6 |
| 10 import 'dart:profiler'; | 7 import 'dart:developer' show UserTag; |
| 11 | 8 |
| 12 /** | 9 /** |
| 13 * Jenkins hash function, optimized for small integers. | 10 * Jenkins hash function, optimized for small integers. |
| 14 * Borrowed from sdk/lib/math/jenkins_smi_hash.dart. | 11 * Borrowed from sdk/lib/math/jenkins_smi_hash.dart. |
| 15 */ | 12 */ |
| 16 class JenkinsSmiHash { | 13 class JenkinsSmiHash { |
| 17 static int combine(int hash, int value) { | 14 static int combine(int hash, int value) { |
| 18 hash = 0x1fffffff & (hash + value); | 15 hash = 0x1fffffff & (hash + value); |
| 19 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); | 16 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); |
| 20 return hash ^ (hash >> 6); | 17 return hash ^ (hash >> 6); |
| 21 } | 18 } |
| 22 | 19 |
| 23 static int finish(int hash) { | 20 static int finish(int hash) { |
| 24 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 21 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 25 hash = hash ^ (hash >> 11); | 22 hash = hash ^ (hash >> 11); |
| 26 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 23 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 27 } | 24 } |
| 28 | 25 |
| 29 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 26 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 30 | 27 |
| 31 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)); |
| 32 | 29 |
| 33 static int hash4(a, b, c, d) => | 30 static int hash4(a, b, c, d) => |
| 34 finish(combine(combine(combine(combine(0, a), b), c), d)); | 31 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 35 } | 32 } |
| 36 | 33 |
| 37 /** | 34 /** |
| 38 * Helper class for gathering performance statistics. This class is modeled on | 35 * Helper class for gathering performance statistics. This class is modeled on |
| 39 * 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 |
| 40 * it. | 37 * it. |
| 41 */ | 38 */ |
| 42 abstract class PerformanceTag { | 39 abstract class PerformanceTag { |
| 43 /** | 40 /** |
| 44 * Return a list of all [PerformanceTag]s which have been created. | 41 * Return a list of all [PerformanceTag]s which have been created. |
| 45 */ | 42 */ |
| 46 static List<PerformanceTag> get all => _PerformanceTagImpl.all.toList(); | 43 static List<PerformanceTag> get all => _PerformanceTagImpl.all.toList(); |
| 47 | 44 |
| 48 /** | 45 /** |
| 49 * 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... |
| 148 | 145 |
| 149 makeCurrentWhile(f()) { | 146 makeCurrentWhile(f()) { |
| 150 PerformanceTag prevTag = makeCurrent(); | 147 PerformanceTag prevTag = makeCurrent(); |
| 151 try { | 148 try { |
| 152 return f(); | 149 return f(); |
| 153 } finally { | 150 } finally { |
| 154 prevTag.makeCurrent(); | 151 prevTag.makeCurrent(); |
| 155 } | 152 } |
| 156 } | 153 } |
| 157 } | 154 } |
| OLD | NEW |