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

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

Issue 2790073004: Restructure the Kernel string table. (Closed)
Patch Set: 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
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..39b9f0dead77e21c472bd2cab18ddc794c483519 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];
}
}
@@ -120,7 +127,8 @@ class BinaryBuilder {
int length = readUInt();
_sourceUriTable = new List<String>(length);
for (int i = 0; i < length; ++i) {
- _sourceUriTable[i] = readStringEntry();
+ int numBytes = readUInt();
+ _sourceUriTable[i] = readStringEntry(numBytes);
}
}
@@ -250,7 +258,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 +272,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) {

Powered by Google App Engine
This is Rietveld 408576698