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

Unified Diff: pkg/kernel/lib/binary/ast_to_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/lib/binary/ast_from_binary.dart ('k') | runtime/vm/kernel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/kernel/lib/binary/ast_to_binary.dart
diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart
index 5092e69294be5f81bc22c0af49e849557176e5f6..cfc65fffe9b4a7063ccb11c6161f4bffa892750d 100644
--- a/pkg/kernel/lib/binary/ast_to_binary.dart
+++ b/pkg/kernel/lib/binary/ast_to_binary.dart
@@ -74,16 +74,17 @@ class BinaryPrinter extends Visitor {
writeBytes(utf8Bytes);
}
- void writeStringTableEntry(String string) {
- List<int> utf8Bytes = const Utf8Encoder().convert(string);
- writeUInt30(utf8Bytes.length);
- writeBytes(utf8Bytes);
- }
-
void writeStringTable(StringIndexer indexer) {
+ // Write the end offsets.
writeUInt30(indexer.numberOfStrings);
+ int endOffset = 0;
+ for (var entry in indexer.entries) {
+ endOffset += entry.utf8Bytes.length;
+ writeUInt30(endOffset);
+ }
+ // Write the UTF-8 encoded strings.
for (var entry in indexer.entries) {
- writeStringTableEntry(entry.value);
+ writeBytes(entry.utf8Bytes);
}
}
@@ -1096,9 +1097,12 @@ class TypeParameterIndexer {
class StringTableEntry implements Comparable<StringTableEntry> {
final String value;
+ final List<int> utf8Bytes;
int frequency = 0;
- StringTableEntry(this.value);
+ StringTableEntry(String value)
+ : value = value,
+ utf8Bytes = const Utf8Encoder().convert(value);
int compareTo(StringTableEntry other) => other.frequency - frequency;
}
« no previous file with comments | « pkg/kernel/lib/binary/ast_from_binary.dart ('k') | runtime/vm/kernel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698