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

Unified Diff: pkg/kernel/lib/binary/ast_from_binary.dart

Issue 2790073004: Restructure the Kernel string table. (Closed)
Patch Set: Incorporate review comments. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_to_binary.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/binary/ast_from_binary.dart
diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart
index 762e8ab563837c60b4d61675501852e49a136ba8..f18e53e4e1fc141f953e23218349d2c0721a8e1b 100644
--- a/pkg/kernel/lib/binary/ast_from_binary.dart
+++ b/pkg/kernel/lib/binary/ast_from_binary.dart
@@ -30,8 +30,8 @@ class BinaryBuilder {
final String filename;
final List<int> _bytes;
int _byteIndex = 0;
- List<String> _stringTable;
- List<String> _sourceUriTable;
+ final List<String> _stringTable = <String>[];
+ final List<String> _sourceUriTable = <String>[];
List<CanonicalName> _linkTable;
int _transformerFlags = 0;
Library _currentLibrary;
@@ -82,8 +82,7 @@ class BinaryBuilder {
return bytes;
}
- String readStringEntry() {
- int numBytes = readUInt();
+ String readStringEntry(int numBytes) {
// Utf8Decoder will skip leading BOM characters, but we must preserve them.
// Collect leading BOMs before passing the bytes onto Utf8Decoder.
int numByteOrderMarks = 0;
@@ -104,11 +103,19 @@ class BinaryBuilder {
return string;
}
- void readStringTable() {
+ void readStringTable(List<String> table) {
+ // Read the table of end offsets.
int length = readUInt();
- _stringTable = new List<String>(length);
+ List<int> endOffsets = new List<int>(length);
for (int i = 0; i < length; ++i) {
- _stringTable[i] = readStringEntry();
+ endOffsets[i] = readUInt();
+ }
+ // Read the UTF-8 encoded strings.
+ table.length = length;
+ int startOffset = 0;
+ for (int i = 0; i < length; ++i) {
+ table[i] = readStringEntry(endOffsets[i] - startOffset);
+ startOffset = endOffsets[i];
}
}
@@ -116,14 +123,6 @@ class BinaryBuilder {
return _sourceUriTable[readUInt()];
}
- void readSourceUriTable() {
- int length = readUInt();
- _sourceUriTable = new List<String>(length);
- for (int i = 0; i < length; ++i) {
- _sourceUriTable[i] = readStringEntry();
- }
- }
-
String readStringReference() {
return _stringTable[readUInt()];
}
@@ -250,7 +249,7 @@ class BinaryBuilder {
throw fail('This is not a binary dart file. '
'Magic number was: ${magic.toRadixString(16)}');
}
- readStringTable();
+ readStringTable(_stringTable);
Map<String, Source> uriToSource = readUriToSource();
program.uriToSource.addAll(uriToSource);
readLinkTable(program.root);
@@ -264,7 +263,7 @@ class BinaryBuilder {
}
Map<String, Source> readUriToSource() {
- readSourceUriTable();
+ readStringTable(_sourceUriTable);
int length = _sourceUriTable.length;
Map<String, Source> uriToSource = <String, Source>{};
for (int i = 0; i < length; ++i) {
« no previous file with comments | « pkg/kernel/binary.md ('k') | pkg/kernel/lib/binary/ast_to_binary.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698