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

Side by Side Diff: pkg/kernel/lib/binary/ast_to_binary.dart

Issue 2729913005: [Fasta] include source code in dill (Closed)
Patch Set: Use Uint8List.view when possible Created 3 years, 9 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library kernel.ast_to_binary; 4 library kernel.ast_to_binary;
5 5
6 import '../ast.dart'; 6 import '../ast.dart';
7 import '../import_table.dart'; 7 import '../import_table.dart';
8 import 'tag.dart'; 8 import 'tag.dart';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 } 63 }
64 64
65 void writeMagicWord(int value) { 65 void writeMagicWord(int value) {
66 writeByte((value >> 24) & 0xFF); 66 writeByte((value >> 24) & 0xFF);
67 writeByte((value >> 16) & 0xFF); 67 writeByte((value >> 16) & 0xFF);
68 writeByte((value >> 8) & 0xFF); 68 writeByte((value >> 8) & 0xFF);
69 writeByte(value & 0xFF); 69 writeByte(value & 0xFF);
70 } 70 }
71 71
72 void writeUtf8Bytes(List<int> utf8Bytes) {
73 writeUInt30(utf8Bytes.length);
74 writeBytes(utf8Bytes);
75 }
76
72 void writeStringTableEntry(String string) { 77 void writeStringTableEntry(String string) {
73 List<int> utf8Bytes = const Utf8Encoder().convert(string); 78 List<int> utf8Bytes = const Utf8Encoder().convert(string);
74 writeUInt30(utf8Bytes.length); 79 writeUInt30(utf8Bytes.length);
75 writeBytes(utf8Bytes); 80 writeBytes(utf8Bytes);
76 } 81 }
77 82
78 void writeStringTable(StringIndexer indexer) { 83 void writeStringTable(StringIndexer indexer) {
79 writeUInt30(indexer.numberOfStrings); 84 writeUInt30(indexer.numberOfStrings);
80 for (var entry in indexer.entries) { 85 for (var entry in indexer.entries) {
81 writeStringTableEntry(entry.value); 86 writeStringTableEntry(entry.value);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 _flush(); 169 _flush();
165 } 170 }
166 171
167 void writeUriToSource(Program program) { 172 void writeUriToSource(Program program) {
168 program.uriToSource.keys.forEach((uri) { 173 program.uriToSource.keys.forEach((uri) {
169 _sourceUriIndexer.put(uri); 174 _sourceUriIndexer.put(uri);
170 }); 175 });
171 writeStringTable(_sourceUriIndexer); 176 writeStringTable(_sourceUriIndexer);
172 for (int i = 0; i < _sourceUriIndexer.entries.length; i++) { 177 for (int i = 0; i < _sourceUriIndexer.entries.length; i++) {
173 String uri = _sourceUriIndexer.entries[i].value; 178 String uri = _sourceUriIndexer.entries[i].value;
174 Source source = program.uriToSource[uri] ?? new Source([], ''); 179 Source source =
175 String sourceCode = source.source; 180 program.uriToSource[uri] ?? new Source(<int>[], const <int>[]);
176 writeStringTableEntry(sourceCode); 181 writeUtf8Bytes(source.source);
177 List<int> lineStarts = source.lineStarts; 182 List<int> lineStarts = source.lineStarts;
178 writeUInt30(lineStarts.length); 183 writeUInt30(lineStarts.length);
179 int previousLineStart = 0; 184 int previousLineStart = 0;
180 lineStarts.forEach((lineStart) { 185 lineStarts.forEach((lineStart) {
181 writeUInt30(lineStart - previousLineStart); 186 writeUInt30(lineStart - previousLineStart);
182 previousLineStart = lineStart; 187 previousLineStart = lineStart;
183 }); 188 });
184 } 189 }
185 } 190 }
186 191
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 void flush() { 1280 void flush() {
1276 _sink.add(_buffer.sublist(0, length)); 1281 _sink.add(_buffer.sublist(0, length));
1277 _buffer = new Uint8List(SIZE); 1282 _buffer = new Uint8List(SIZE);
1278 length = 0; 1283 length = 0;
1279 } 1284 }
1280 1285
1281 void flushAndDestroy() { 1286 void flushAndDestroy() {
1282 _sink.add(_buffer.sublist(0, length)); 1287 _sink.add(_buffer.sublist(0, length));
1283 } 1288 }
1284 } 1289 }
OLDNEW
« no previous file with comments | « pkg/kernel/lib/binary/ast_from_binary.dart ('k') | pkg/kernel/lib/transformations/closure/mock.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698