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

Unified Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1687053002: Consolidate strings in summary output. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/summary/flat_buffers.dart
diff --git a/pkg/analyzer/lib/src/summary/flat_buffers.dart b/pkg/analyzer/lib/src/summary/flat_buffers.dart
index c56b2986e287e28de1b60400f2e16e8efddffee9..00c2d0151912992aeaaddb817b18f351dd390247 100644
--- a/pkg/analyzer/lib/src/summary/flat_buffers.dart
+++ b/pkg/analyzer/lib/src/summary/flat_buffers.dart
@@ -110,6 +110,12 @@ class Builder {
_VTable _currentVTable;
+ /**
+ * Map containing all strings that have been written so far. This allows us
+ * to avoid duplicating strings.
+ */
+ Map<String, Offset<String>> _strings = <String, Offset<String>>{};
+
Builder({this.initialSize: 1024}) {
reset();
}
@@ -387,17 +393,19 @@ class Builder {
'Cannot write a non-scalar value while writing a table.');
}
if (value != def) {
- // TODO(scheglov) optimize for ASCII strings
- List<int> bytes = UTF8.encode(value);
- int length = bytes.length;
- _prepare(4, 1, additionalBytes: length);
- Offset<String> result = new Offset(_tail);
- _setUint32AtTail(_buf, _tail, length);
- int offset = _buf.lengthInBytes - _tail + 4;
- for (int i = 0; i < length; i++) {
- _buf.setUint8(offset++, bytes[i]);
- }
- return result;
+ return _strings.putIfAbsent(value, () {
+ // TODO(scheglov) optimize for ASCII strings
+ List<int> bytes = UTF8.encode(value);
+ int length = bytes.length;
+ _prepare(4, 1, additionalBytes: length);
+ Offset<String> result = new Offset(_tail);
+ _setUint32AtTail(_buf, _tail, length);
+ int offset = _buf.lengthInBytes - _tail + 4;
+ for (int i = 0; i < length; i++) {
+ _buf.setUint8(offset++, bytes[i]);
+ }
+ return result;
+ });
}
return null;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698