| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class Namer implements ClosureNamer { | 10 class Namer implements ClosureNamer { |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 } | 1183 } |
| 1184 | 1184 |
| 1185 visitInterceptor(InterceptorConstant constant) { | 1185 visitInterceptor(InterceptorConstant constant) { |
| 1186 addRoot(constant.dispatchedType.element.name); | 1186 addRoot(constant.dispatchedType.element.name); |
| 1187 add('methods'); | 1187 add('methods'); |
| 1188 } | 1188 } |
| 1189 | 1189 |
| 1190 visitDummy(DummyConstant constant) { | 1190 visitDummy(DummyConstant constant) { |
| 1191 add('dummy_receiver'); | 1191 add('dummy_receiver'); |
| 1192 } | 1192 } |
| 1193 |
| 1194 visitDeferred(DeferredConstant constant) { |
| 1195 addRoot('Deferred'); |
| 1196 } |
| 1193 } | 1197 } |
| 1194 | 1198 |
| 1195 /** | 1199 /** |
| 1196 * Generates canonical hash values for [Constant]s. | 1200 * Generates canonical hash values for [Constant]s. |
| 1197 * | 1201 * |
| 1198 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, | 1202 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, |
| 1199 * so it can't be used for generating names. This hasher keeps consistency | 1203 * so it can't be used for generating names. This hasher keeps consistency |
| 1200 * between runs by basing hash values of the names of elements, rather than | 1204 * between runs by basing hash values of the names of elements, rather than |
| 1201 * their hashCodes. | 1205 * their hashCodes. |
| 1202 */ | 1206 */ |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 visitInterceptor(InterceptorConstant constant) { | 1269 visitInterceptor(InterceptorConstant constant) { |
| 1266 String typeName = constant.dispatchedType.element.name; | 1270 String typeName = constant.dispatchedType.element.name; |
| 1267 return _hashString(5, typeName); | 1271 return _hashString(5, typeName); |
| 1268 } | 1272 } |
| 1269 | 1273 |
| 1270 visitDummy(DummyConstant constant) { | 1274 visitDummy(DummyConstant constant) { |
| 1271 compiler.internalError(NO_LOCATION_SPANNABLE, | 1275 compiler.internalError(NO_LOCATION_SPANNABLE, |
| 1272 'DummyReceiverConstant should never be named and never be subconstant'); | 1276 'DummyReceiverConstant should never be named and never be subconstant'); |
| 1273 } | 1277 } |
| 1274 | 1278 |
| 1279 visitDeferred(DeferredConstant constant) { |
| 1280 int hash = constant.prefix.hashCode; |
| 1281 return _combine(hash, constant.referenced.accept(this)); |
| 1282 } |
| 1283 |
| 1275 int _hashString(int hash, String s) { | 1284 int _hashString(int hash, String s) { |
| 1276 int length = s.length; | 1285 int length = s.length; |
| 1277 hash = _combine(hash, length); | 1286 hash = _combine(hash, length); |
| 1278 // Increasing stride is O(log N) on large strings which are unlikely to have | 1287 // Increasing stride is O(log N) on large strings which are unlikely to have |
| 1279 // many collisions. | 1288 // many collisions. |
| 1280 for (int i = 0; i < length; i += 1 + (i >> 2)) { | 1289 for (int i = 0; i < length; i += 1 + (i >> 2)) { |
| 1281 hash = _combine(hash, s.codeUnitAt(i)); | 1290 hash = _combine(hash, s.codeUnitAt(i)); |
| 1282 } | 1291 } |
| 1283 return hash; | 1292 return hash; |
| 1284 } | 1293 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1396 if (!first) { | 1405 if (!first) { |
| 1397 sb.write('_'); | 1406 sb.write('_'); |
| 1398 } | 1407 } |
| 1399 sb.write('_'); | 1408 sb.write('_'); |
| 1400 visit(link.head); | 1409 visit(link.head); |
| 1401 first = true; | 1410 first = true; |
| 1402 } | 1411 } |
| 1403 } | 1412 } |
| 1404 } | 1413 } |
| 1405 } | 1414 } |
| OLD | NEW |