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

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

Issue 1153243003: dart2js: Use frequency of occurence to sort metadata indices. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 /** 7 /**
8 * A data structure for collecting fragments of a class definition. 8 * A data structure for collecting fragments of a class definition.
9 */ 9 */
10 class ClassBuilder { 10 class ClassBuilder {
11 final List<jsAst.Property> properties = <jsAst.Property>[]; 11 final List<jsAst.Property> properties = <jsAst.Property>[];
12 final List<String> fields = <String>[]; 12 final List<jsAst.Literal> fields = <jsAst.Literal>[];
13 13
14 String superName; 14 String superName;
15 String functionType; 15 jsAst.Node functionType;
16 List<jsAst.Node> fieldMetadata; 16 List<jsAst.Node> fieldMetadata;
17 17
18 final Element element; 18 final Element element;
19 final Namer namer; 19 final Namer namer;
20 20
21 ClassBuilder(this.element, this.namer); 21 ClassBuilder(this.element, this.namer);
22 22
23 jsAst.Property addProperty(String name, jsAst.Expression value) { 23 jsAst.Property addProperty(String name, jsAst.Expression value) {
24 jsAst.Property property = new jsAst.Property(js.string(name), value); 24 jsAst.Property property = new jsAst.Property(js.string(name), value);
25 properties.add(property); 25 properties.add(property);
26 return property; 26 return property;
27 } 27 }
28 28
29 void addField(String field) { 29 void addField(jsAst.Literal field) {
30 fields.add(field); 30 fields.add(field);
31 } 31 }
32 32
33 static String functionTypeEncodingDescription = 33 static String functionTypeEncodingDescription =
34 'For simple function types the function type is stored in the metadata ' 34 'For simple function types the function type is stored in the metadata '
35 'and the index is encoded into the superclass field.'; 35 'and the index is encoded into the superclass field.';
36 36
37 static String fieldEncodingDescription = 37 static String fieldEncodingDescription =
38 'Fields are encoded as a comma separated list. If there is a superclass ' 38 'Fields are encoded as a comma separated list. If there is a superclass '
39 '(and possibly a function type encoding) the fields are separated from ' 39 '(and possibly a function type encoding) the fields are separated from '
40 'the superclass by a semicolon.'; 40 'the superclass by a semicolon.';
41 41
42 jsAst.ObjectInitializer toObjectInitializer( 42 jsAst.ObjectInitializer toObjectInitializer(Compiler compiler,
karlklose 2015/05/28 09:39:53 The parameter 'compiler' seems to be unsued.
herhut 2015/06/01 12:09:42 True. Removed.
43 {bool emitClassDescriptor: true}) { 43 {bool emitClassDescriptor: true}) {
44 StringBuffer buffer = new StringBuffer(); 44 List<jsAst.Literal> parts = <jsAst.Literal>[];
45 if (superName != null) { 45 if (superName != null) {
46 buffer.write(superName); 46 parts.add(js.stringPart(superName));
47 if (functionType != null) { 47 if (functionType != null) {
48 // See [functionTypeEncodingDescription] above. 48 // See [functionTypeEncodingDescription] above.
49 buffer.write(':$functionType'); 49 parts.add(js.stringPart(':'));
50 parts.add(functionType);
50 } 51 }
51 buffer.write(';'); 52 parts.add(js.stringPart(';'));
52 } 53 }
53 // See [fieldEncodingDescription] above. 54 // See [fieldEncodingDescription] above.
54 buffer.writeAll(fields, ','); 55 parts.addAll(js.joinLiterals(fields, js.stringPart(',')));
55 var classData = js.string('$buffer'); 56 var classData = js.concatenateStrings(parts, addQuotes: true);
56 if (fieldMetadata != null) { 57 if (fieldMetadata != null) {
57 // If we need to store fieldMetadata, classData is turned into an array, 58 // If we need to store fieldMetadata, classData is turned into an array,
58 // and the field metadata is appended. So if classData is just a string, 59 // and the field metadata is appended. So if classData is just a string,
59 // there is no field metadata. 60 // there is no field metadata.
60 classData = 61 classData =
61 new jsAst.ArrayInitializer([classData]..addAll(fieldMetadata)); 62 new jsAst.ArrayInitializer([classData]..addAll(fieldMetadata));
62 } 63 }
63 List<jsAst.Property> fieldsAndProperties; 64 List<jsAst.Property> fieldsAndProperties;
64 if (emitClassDescriptor) { 65 if (emitClassDescriptor) {
65 fieldsAndProperties = <jsAst.Property>[]; 66 fieldsAndProperties = <jsAst.Property>[];
66 fieldsAndProperties.add( 67 fieldsAndProperties.add(
67 new jsAst.Property( 68 new jsAst.Property(
68 js.string(namer.classDescriptorProperty), classData)); 69 js.string(namer.classDescriptorProperty), classData));
69 fieldsAndProperties.addAll(properties); 70 fieldsAndProperties.addAll(properties);
70 } else { 71 } else {
71 fieldsAndProperties = properties; 72 fieldsAndProperties = properties;
72 } 73 }
73 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false); 74 return new jsAst.ObjectInitializer(fieldsAndProperties, isOneLiner: false);
74 } 75 }
75 } 76 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698