Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart

Issue 102833009: Redo "Dummy receiver optimization" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 DartType type = constant.representedType; 1174 DartType type = constant.representedType;
1175 JavaScriptBackend backend = compiler.backend; 1175 JavaScriptBackend backend = compiler.backend;
1176 String name = backend.rti.getRawTypeRepresentation(type); 1176 String name = backend.rti.getRawTypeRepresentation(type);
1177 addIdentifier(name); 1177 addIdentifier(name);
1178 } 1178 }
1179 1179
1180 visitInterceptor(InterceptorConstant constant) { 1180 visitInterceptor(InterceptorConstant constant) {
1181 addRoot(constant.dispatchedType.element.name); 1181 addRoot(constant.dispatchedType.element.name);
1182 add('methods'); 1182 add('methods');
1183 } 1183 }
1184
1185 visitDummyReceiver(DummyReceiverConstant constant) {
1186 add('dummy_receiver');
1187 }
1184 } 1188 }
1185 1189
1186 /** 1190 /**
1187 * Generates canonical hash values for [Constant]s. 1191 * Generates canonical hash values for [Constant]s.
1188 * 1192 *
1189 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations, 1193 * Unfortunately, [Constant.hashCode] is not stable under minor perturbations,
1190 * so it can't be used for generating names. This hasher keeps consistency 1194 * so it can't be used for generating names. This hasher keeps consistency
1191 * between runs by basing hash values of the names of elements, rather than 1195 * between runs by basing hash values of the names of elements, rather than
1192 * their hashCodes. 1196 * their hashCodes.
1193 */ 1197 */
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 JavaScriptBackend backend = compiler.backend; 1255 JavaScriptBackend backend = compiler.backend;
1252 String name = backend.rti.getRawTypeRepresentation(type); 1256 String name = backend.rti.getRawTypeRepresentation(type);
1253 return _hashString(4, name); 1257 return _hashString(4, name);
1254 } 1258 }
1255 1259
1256 visitInterceptor(InterceptorConstant constant) { 1260 visitInterceptor(InterceptorConstant constant) {
1257 String typeName = constant.dispatchedType.element.name; 1261 String typeName = constant.dispatchedType.element.name;
1258 return _hashString(5, typeName); 1262 return _hashString(5, typeName);
1259 } 1263 }
1260 1264
1265 visitDummyReceiver(DummyReceiverConstant constant) {
1266 compiler.internalError(
1267 'DummyReceiverConstant should never be named and never be subconstant');
1268 }
1269
1261 int _hashString(int hash, String s) { 1270 int _hashString(int hash, String s) {
1262 int length = s.length; 1271 int length = s.length;
1263 hash = _combine(hash, length); 1272 hash = _combine(hash, length);
1264 // Increasing stride is O(log N) on large strings which are unlikely to have 1273 // Increasing stride is O(log N) on large strings which are unlikely to have
1265 // many collisions. 1274 // many collisions.
1266 for (int i = 0; i < length; i += 1 + (i >> 2)) { 1275 for (int i = 0; i < length; i += 1 + (i >> 2)) {
1267 hash = _combine(hash, s.codeUnitAt(i)); 1276 hash = _combine(hash, s.codeUnitAt(i));
1268 } 1277 }
1269 return hash; 1278 return hash;
1270 } 1279 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 if (!first) { 1391 if (!first) {
1383 sb.write('_'); 1392 sb.write('_');
1384 } 1393 }
1385 sb.write('_'); 1394 sb.write('_');
1386 visit(link.head); 1395 visit(link.head);
1387 first = true; 1396 first = true;
1388 } 1397 }
1389 } 1398 }
1390 } 1399 }
1391 } 1400 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698