| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 dart2js.util; | 5 library dart2js.util; |
| 6 | 6 |
| 7 import 'util_implementation.dart'; | 7 import 'util_implementation.dart'; |
| 8 import 'characters.dart'; | 8 import 'characters.dart'; |
| 9 | 9 |
| 10 export 'setlet.dart'; | 10 export 'setlet.dart'; |
| 11 export 'maplet.dart'; | 11 export 'maplet.dart'; |
| 12 export 'emptyset.dart'; | 12 export 'emptyset.dart'; |
| 13 | 13 |
| 14 part 'indentation.dart'; | 14 part 'indentation.dart'; |
| 15 part 'link.dart'; | 15 part 'link.dart'; |
| 16 | 16 |
| 17 /// If an integer is masked by this constant, the result is guaranteed to be in | 17 /// If an integer is masked by this constant, the result is guaranteed to be in |
| 18 /// Smi range. | 18 /// Smi range. |
| 19 const int SMI_MASK = 0x3fffffff; | 19 const int SMI_MASK = 0x3fffffff; |
| 20 | 20 |
| 21 /// Mix the bits of [value] and merge them with [existing]. |
| 22 int mixHashCodeBits(int existing, int value) { |
| 23 // Spread the bits of value. Try to stay in the 30-bit range to |
| 24 // avoid overflowing into a more expensive integer representation. |
| 25 int h = value & 0x1fffffff; |
| 26 h += ((h & 0x3fff) << 15) ^ 0x1fffcd7d; |
| 27 h ^= (h >> 10); |
| 28 h += ((h & 0x3ffffff) << 3); |
| 29 h ^= (h >> 6); |
| 30 h += ((h & 0x7ffffff) << 2) + ((h & 0x7fff) << 14); |
| 31 h ^= (h >> 16); |
| 32 // Combine the two hash values. |
| 33 int high = existing >> 15; |
| 34 int low = existing & 0x7fff; |
| 35 return ((high * 13) ^ (low * 997) ^ h) & SMI_MASK; |
| 36 } |
| 37 |
| 21 /** | 38 /** |
| 22 * Tagging interface for classes from which source spans can be generated. | 39 * Tagging interface for classes from which source spans can be generated. |
| 23 */ | 40 */ |
| 24 // TODO(johnniwinther): Find a better name. | 41 // TODO(johnniwinther): Find a better name. |
| 25 // TODO(ahe): How about "Bolt"? | 42 // TODO(ahe): How about "Bolt"? |
| 26 abstract class Spannable {} | 43 abstract class Spannable {} |
| 27 | 44 |
| 28 class _SpannableSentinel implements Spannable { | 45 class _SpannableSentinel implements Spannable { |
| 29 final String name; | 46 final String name; |
| 30 | 47 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (usedNames.contains(suggestedName)) { | 225 if (usedNames.contains(suggestedName)) { |
| 209 int counter = 0; | 226 int counter = 0; |
| 210 while (usedNames.contains(result)) { | 227 while (usedNames.contains(result)) { |
| 211 counter++; | 228 counter++; |
| 212 result = "$suggestedName$counter"; | 229 result = "$suggestedName$counter"; |
| 213 } | 230 } |
| 214 } | 231 } |
| 215 usedNames.add(result); | 232 usedNames.add(result); |
| 216 return result; | 233 return result; |
| 217 } | 234 } |
| OLD | NEW |