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

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

Issue 851473002: Use prototype inheritance to reduce number of is check properties. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Comments. Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 7
8 class OldEmitter implements Emitter { 8 class OldEmitter implements Emitter {
9 final Compiler compiler; 9 final Compiler compiler;
10 final CodeEmitterTask task; 10 final CodeEmitterTask task;
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // print(this.x + y); 317 // print(this.x + y);
318 // }, 318 // },
319 // bar$2: function(t, v) { 319 // bar$2: function(t, v) {
320 // this.x = t - v; 320 // this.x = t - v;
321 // }, 321 // },
322 // }); 322 // });
323 323
324 bool hasIsolateSupport = compiler.hasIsolateSupport; 324 bool hasIsolateSupport = compiler.hasIsolateSupport;
325 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME; 325 String fieldNamesProperty = FIELD_NAMES_PROPERTY_NAME;
326 326
327 jsAst.Expression defineClass = js(''' 327 jsAst.Expression defineClass = js(r'''
328 function(name, fields) { 328 function(name, fields) {
329 var accessors = []; 329 var accessors = [];
330 330
331 var str = "function " + name + "("; 331 var str = "function " + name + "(";
332 var body = ""; 332 var body = "";
333 if (#hasIsolateSupport) { var fieldNames = ""; } 333 if (#hasIsolateSupport) { var fieldNames = ""; }
334 334
335 for (var i = 0; i < fields.length; i++) { 335 for (var i = 0; i < fields.length; i++) {
336 if(i != 0) str += ", "; 336 if(i != 0) str += ", ";
337 337
338 var field = generateAccessor(fields[i], accessors, name); 338 var field = generateAccessor(fields[i], accessors, name);
339 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; } 339 if (#hasIsolateSupport) { fieldNames += "'" + field + "',"; }
340 var parameter = "parameter_" + field; 340 var parameter = "parameter_" + field;
341 str += parameter; 341 str += parameter;
342 body += ("this." + field + " = " + parameter + ";\\n"); 342 body += ("this." + field + " = " + parameter + ";\n");
343 } 343 }
344 str += ") {\\n" + body + "}\\n"; 344 str += ") {\n" + body + "}\n";
345 str += name + ".builtin\$cls=\\"" + name + "\\";\\n"; 345 str += name + ".builtin$cls=\"" + name + "\";\n";
346 str += "\$desc=\$collectedClasses." + name + ";\\n"; 346 str += "$desc=$collectedClasses." + name + ";\n";
347 str += "if(\$desc instanceof Array) \$desc = \$desc[1];\\n"; 347 str += "if($desc instanceof Array) $desc = \$desc[1];\n";
348 str += name + ".prototype = \$desc;\\n"; 348 str += name + ".prototype = $desc;\n";
349 if (typeof defineClass.name != "string") { 349 if (typeof defineClass.name != "string") {
350 str += name + ".name=\\"" + name + "\\";\\n"; 350 str += name + ".name=\"" + name + "\";\n";
351 } 351 }
352 if (#hasIsolateSupport) { 352 if (#hasIsolateSupport) {
353 str += name + ".$fieldNamesProperty=[" + fieldNames + "];\\n"; 353 str += name + "." + #fieldNamesProperty + "=[" + fieldNames
354 + "];\n";
354 } 355 }
355 str += accessors.join(""); 356 str += accessors.join("");
356 357
357 return str; 358 return str;
358 }''', { 'hasIsolateSupport': hasIsolateSupport }); 359 }''', { 'hasIsolateSupport': hasIsolateSupport,
360 'fieldNamesProperty': js.string(fieldNamesProperty)});
359 361
360 // Declare a function called "generateAccessor". This is used in 362 // Declare a function called "generateAccessor". This is used in
361 // defineClassFunction. 363 // defineClassFunction.
362 List result = <jsAst.Node>[ 364 List result = <jsAst.Node>[
363 generateAccessorFunction, 365 generateAccessorFunction,
364 new jsAst.FunctionDeclaration( 366 new jsAst.FunctionDeclaration(
365 new jsAst.VariableDeclaration('defineClass'), defineClass) ]; 367 new jsAst.VariableDeclaration('defineClass'), defineClass) ];
366 368
367 if (compiler.hasIncrementalSupport) { 369 if (compiler.hasIncrementalSupport) {
368 result.add( 370 result.add(
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 jsAst.Expression buildInheritFrom() { 421 jsAst.Expression buildInheritFrom() {
420 jsAst.Expression result = js(r''' 422 jsAst.Expression result = js(r'''
421 function() { 423 function() {
422 function tmp() {} 424 function tmp() {}
423 var hasOwnProperty = Object.prototype.hasOwnProperty; 425 var hasOwnProperty = Object.prototype.hasOwnProperty;
424 return function (constructor, superConstructor) { 426 return function (constructor, superConstructor) {
425 if (superConstructor == null) { 427 if (superConstructor == null) {
426 // Fix up the the Dart Object class' prototype. 428 // Fix up the the Dart Object class' prototype.
427 var prototype = constructor.prototype; 429 var prototype = constructor.prototype;
428 prototype.constructor = constructor; 430 prototype.constructor = constructor;
431 prototype.#isObject = constructor;
429 return prototype; 432 return prototype;
430 } 433 }
431 tmp.prototype = superConstructor.prototype; 434 tmp.prototype = superConstructor.prototype;
432 var object = new tmp(); 435 var object = new tmp();
433 var properties = constructor.prototype; 436 var properties = constructor.prototype;
434 for (var member in properties) { 437 for (var member in properties) {
435 if (hasOwnProperty.call(properties, member)) { 438 if (hasOwnProperty.call(properties, member)) {
436 object[member] = properties[member]; 439 object[member] = properties[member];
437 } 440 }
438 } 441 }
442 // Use a function for `true` here, as functions are stored in the
443 // hidden class and not as properties in the object.
444 object[#operatorIsPrefix + constructor.name] = constructor;
439 object.constructor = constructor; 445 object.constructor = constructor;
440 constructor.prototype = object; 446 constructor.prototype = object;
441 return object; 447 return object;
442 }; 448 };
443 }() 449 }()
444 '''); 450 ''', { 'operatorIsPrefix' : js.string(namer.operatorIsPrefix),
451 'isObject' : namer.operatorIs(compiler.objectClass) });
445 if (compiler.hasIncrementalSupport) { 452 if (compiler.hasIncrementalSupport) {
446 result = js( 453 result = js(
447 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]); 454 r'#.inheritFrom = #', [namer.accessIncrementalHelper, result]);
448 } 455 }
449 return js(r'var inheritFrom = #', [result]); 456 return js(r'var inheritFrom = #', [result]);
450 } 457 }
451 458
452 jsAst.Statement buildFinishClass() { 459 jsAst.Statement buildFinishClass() {
453 String specProperty = '"${namer.nativeSpecProperty}"'; // "%" 460 String specProperty = '"${namer.nativeSpecProperty}"'; // "%"
454 461
(...skipping 1644 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 2106 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
2100 if (element.isInstanceMember) { 2107 if (element.isInstanceMember) {
2101 cachedClassBuilders.remove(element.enclosingClass); 2108 cachedClassBuilders.remove(element.enclosingClass);
2102 2109
2103 nativeEmitter.cachedBuilders.remove(element.enclosingClass); 2110 nativeEmitter.cachedBuilders.remove(element.enclosingClass);
2104 2111
2105 } 2112 }
2106 } 2113 }
2107 } 2114 }
2108 } 2115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698