| 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 | |
| 38 /** | 21 /** |
| 39 * Tagging interface for classes from which source spans can be generated. | 22 * Tagging interface for classes from which source spans can be generated. |
| 40 */ | 23 */ |
| 41 // TODO(johnniwinther): Find a better name. | 24 // TODO(johnniwinther): Find a better name. |
| 42 // TODO(ahe): How about "Bolt"? | 25 // TODO(ahe): How about "Bolt"? |
| 43 abstract class Spannable {} | 26 abstract class Spannable {} |
| 44 | 27 |
| 45 class _SpannableSentinel implements Spannable { | 28 class _SpannableSentinel implements Spannable { |
| 46 final String name; | 29 final String name; |
| 47 | 30 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 if (usedNames.contains(suggestedName)) { | 208 if (usedNames.contains(suggestedName)) { |
| 226 int counter = 0; | 209 int counter = 0; |
| 227 while (usedNames.contains(result)) { | 210 while (usedNames.contains(result)) { |
| 228 counter++; | 211 counter++; |
| 229 result = "$suggestedName$counter"; | 212 result = "$suggestedName$counter"; |
| 230 } | 213 } |
| 231 } | 214 } |
| 232 usedNames.add(result); | 215 usedNames.add(result); |
| 233 return result; | 216 return result; |
| 234 } | 217 } |
| OLD | NEW |