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

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

Issue 24251012: Improve the memory consumption and performance of our string buffer implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comment. Created 7 years, 3 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /// Enables debugging of fast/slow objects using V8-specific primitives. 7 /// Enables debugging of fast/slow objects using V8-specific primitives.
8 const DEBUG_FAST_OBJECTS = false; 8 const DEBUG_FAST_OBJECTS = false;
9 9
10 /** 10 /**
(...skipping 4041 matching lines...) Expand 10 before | Expand all | Expand 10 after
4052 '''); 4052 ''');
4053 } 4053 }
4054 } 4054 }
4055 4055
4056 emitMain(mainBuffer); 4056 emitMain(mainBuffer);
4057 emitInitFunction(mainBuffer); 4057 emitInitFunction(mainBuffer);
4058 if (!areAnyElementsDeferred) { 4058 if (!areAnyElementsDeferred) {
4059 mainBuffer.add('})()$n'); 4059 mainBuffer.add('})()$n');
4060 } 4060 }
4061 compiler.assembledCode = mainBuffer.getText(); 4061 compiler.assembledCode = mainBuffer.getText();
4062 outputSourceMap(mainBuffer, compiler.assembledCode, ''); 4062 outputSourceMap(compiler.assembledCode, '');
4063 4063
4064 emitDeferredCode(); 4064 emitDeferredCode();
4065 4065
4066 }); 4066 });
4067 return compiler.assembledCode; 4067 return compiler.assembledCode;
4068 } 4068 }
4069 4069
4070 CodeBuffer bufferForElement(Element element, CodeBuffer eagerBuffer) { 4070 CodeBuffer bufferForElement(Element element, CodeBuffer eagerBuffer) {
4071 Element owner = element.getLibrary(); 4071 Element owner = element.getLibrary();
4072 if (!element.isTopLevel() && !element.isNative()) { 4072 if (!element.isTopLevel() && !element.isNative()) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
4156 classesCollector = oldClassesCollector; 4156 classesCollector = oldClassesCollector;
4157 4157
4158 if (!deferredConstants.isEmpty) { 4158 if (!deferredConstants.isEmpty) {
4159 buffer.addBuffer(deferredConstants); 4159 buffer.addBuffer(deferredConstants);
4160 } 4160 }
4161 4161
4162 String code = buffer.getText(); 4162 String code = buffer.getText();
4163 compiler.outputProvider('part', 'js') 4163 compiler.outputProvider('part', 'js')
4164 ..add(code) 4164 ..add(code)
4165 ..close(); 4165 ..close();
4166 outputSourceMap(buffer, compiler.assembledCode, 'part'); 4166 outputSourceMap(compiler.assembledCode, 'part');
4167 } 4167 }
4168 4168
4169 String buildGeneratedBy() { 4169 String buildGeneratedBy() {
4170 var suffix = ''; 4170 var suffix = '';
4171 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}'; 4171 if (compiler.hasBuildId) suffix = ' version: ${compiler.buildId}';
4172 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n'; 4172 return '// Generated by dart2js, the Dart to JavaScript compiler$suffix.\n';
4173 } 4173 }
4174 4174
4175 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) { 4175 String buildSourceMap(CodeBuffer buffer, SourceFile compiledFile) {
4176 SourceMapBuilder sourceMapBuilder = 4176 SourceMapBuilder sourceMapBuilder =
4177 new SourceMapBuilder(compiler.sourceMapUri); 4177 new SourceMapBuilder(compiler.sourceMapUri);
4178 buffer.forEachSourceLocation(sourceMapBuilder.addMapping); 4178 buffer.forEachSourceLocation(sourceMapBuilder.addMapping);
4179 return sourceMapBuilder.build(compiledFile); 4179 return sourceMapBuilder.build(compiledFile);
4180 } 4180 }
4181 4181
4182 void outputSourceMap(CodeBuffer buffer, String code, String name) { 4182 void outputSourceMap(String code, String name) {
4183 if (!generateSourceMap) return; 4183 if (!generateSourceMap) return;
4184 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode); 4184 SourceFile compiledFile = new SourceFile(null, compiler.assembledCode);
4185 String sourceMap = buildSourceMap(mainBuffer, compiledFile); 4185 String sourceMap = buildSourceMap(mainBuffer, compiledFile);
4186 compiler.outputProvider(name, 'js.map') 4186 compiler.outputProvider(name, 'js.map')
4187 ..add(sourceMap) 4187 ..add(sourceMap)
4188 ..close(); 4188 ..close();
4189 } 4189 }
4190 4190
4191 bool isDeferred(Element element) { 4191 bool isDeferred(Element element) {
4192 return compiler.deferredLoadTask.isDeferred(element); 4192 return compiler.deferredLoadTask.isDeferred(element);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
4307 4307
4308 const String HOOKS_API_USAGE = """ 4308 const String HOOKS_API_USAGE = """
4309 // The code supports the following hooks: 4309 // The code supports the following hooks:
4310 // dartPrint(message) - if this function is defined it is called 4310 // dartPrint(message) - if this function is defined it is called
4311 // instead of the Dart [print] method. 4311 // instead of the Dart [print] method.
4312 // dartMainRunner(main) - if this function is defined, the Dart [main] 4312 // dartMainRunner(main) - if this function is defined, the Dart [main]
4313 // method will not be invoked directly. 4313 // method will not be invoked directly.
4314 // Instead, a closure that will invoke [main] is 4314 // Instead, a closure that will invoke [main] is
4315 // passed to [dartMainRunner]. 4315 // passed to [dartMainRunner].
4316 """; 4316 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698