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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart

Issue 1212613009: dart2js: Implement frequency based naming. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 months 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 class NsmEmitter extends CodeEmitterHelper { 7 class NsmEmitter extends CodeEmitterHelper {
8 final List<Selector> trivialNsmHandlers = <Selector>[]; 8 final List<Selector> trivialNsmHandlers = <Selector>[];
9 9
10 /// If this is true then we can generate the noSuchMethod handlers at startup 10 /// If this is true then we can generate the noSuchMethod handlers at startup
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 return statements; 285 return statements;
286 } 286 }
287 } 287 }
288 288
289 /// When pretty printed, this node computes a diff-encoded string for the list 289 /// When pretty printed, this node computes a diff-encoded string for the list
290 /// of given names. 290 /// of given names.
291 /// 291 ///
292 /// See [buildTrivialNsmHandlers]. 292 /// See [buildTrivialNsmHandlers].
293 class _DiffEncodedListOfNames extends jsAst.DeferredString 293 class _DiffEncodedListOfNames extends jsAst.DeferredString
294 implements AstContainer { 294 implements jsAst.AstContainer {
295 String _cachedValue; 295 String _cachedValue;
296 jsAst.ArrayInitializer ast; 296 List<jsAst.ArrayInitializer> ast;
297
298 Iterable<jsAst.Node> get containedNodes => ast;
297 299
298 _DiffEncodedListOfNames(Iterable<Iterable<jsAst.Name>> names) { 300 _DiffEncodedListOfNames(Iterable<Iterable<jsAst.Name>> names) {
299 // Store the names in ArrayInitializer nodes to make them discoverable 301 // Store the names in ArrayInitializer nodes to make them discoverable
300 // by traversals of the ast. 302 // by traversals of the ast.
301 ast = new jsAst.ArrayInitializer( 303 ast = names.map((Iterable i) => new jsAst.ArrayInitializer(i.toList()))
302 names.map((Iterable i) => new jsAst.ArrayInitializer(i.toList())) 304 .toList();
303 .toList());
304 } 305 }
305 306
306 void _computeDiffEncodingForList(Iterable<jsAst.Name> names, 307 void _computeDiffEncodingForList(Iterable<jsAst.Name> names,
307 StringBuffer diffEncoding) { 308 StringBuffer diffEncoding) {
308 // Treat string as a number in base 88 with digits in ASCII order from # to 309 // Treat string as a number in base 88 with digits in ASCII order from # to
309 // z. The short name sorting is based on length, and uses ASCII order for 310 // z. The short name sorting is based on length, and uses ASCII order for
310 // equal length strings so this means that names are ascending. The hash 311 // equal length strings so this means that names are ascending. The hash
311 // character, #, is never given as input, but we need it because it's the 312 // character, #, is never given as input, but we need it because it's the
312 // implicit leading zero (otherwise we could not code names with leading 313 // implicit leading zero (otherwise we could not code names with leading
313 // dollar signs). 314 // dollar signs).
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 if (diffEncoding.length != 0) { 361 if (diffEncoding.length != 0) {
361 diffEncoding.write(','); 362 diffEncoding.write(',');
362 } 363 }
363 diffEncoding.write(short); 364 diffEncoding.write(short);
364 } 365 }
365 } 366 }
366 } 367 }
367 368
368 String _computeDiffEncoding() { 369 String _computeDiffEncoding() {
369 StringBuffer buffer = new StringBuffer(); 370 StringBuffer buffer = new StringBuffer();
370 for (jsAst.ArrayInitializer list in ast.elements) { 371 for (jsAst.ArrayInitializer list in ast) {
371 if (buffer.isNotEmpty) { 372 if (buffer.isNotEmpty) {
372 // Emit period that resets the diff base to zero when we switch to 373 // Emit period that resets the diff base to zero when we switch to
373 // normal calling convention (this avoids the need to code negative 374 // normal calling convention (this avoids the need to code negative
374 // diffs). 375 // diffs).
375 buffer.write("."); 376 buffer.write(".");
376 } 377 }
377 List<jsAst.Name> names = list.elements; 378 List<jsAst.Name> names = list.elements;
378 _computeDiffEncodingForList(names, buffer); 379 _computeDiffEncodingForList(names, buffer);
379 } 380 }
380 return '"${buffer.toString()}"'; 381 return '"${buffer.toString()}"';
381 } 382 }
382 383
383 String get value { 384 String get value {
384 if (_cachedValue == null) { 385 if (_cachedValue == null) {
385 _cachedValue = _computeDiffEncoding(); 386 _cachedValue = _computeDiffEncoding();
386 } 387 }
387 388
388 return _cachedValue; 389 return _cachedValue;
389 } 390 }
390 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698