Skip to content

Commit 9a720bb

Browse files
scheglovCommit Queue
authored andcommitted
Fine. Rename binary I/O types to BinaryReader/Writer
Replace the generic names `SummaryDataReader` and `BufferedSink` with clearer `BinaryReader` and `BinaryWriter`. The new names reflect their actual roles (reading/writing the analyzer’s binary formats), reduce confusion with “summary” artifacts, and make call sites easier to scan. No encoding or behavioral changes are intended. Key changes - Introduce `BinaryReader` and `BinaryWriter` and update class docs. - Rename constructor, method, and factory signatures across the codebase to use the new types (e.g., `read(...)`, `write(...)`, `fork(...)`). - Update extensions to match the new names (`BinaryReaderExtension`, `BinaryWriterExtension`) and migrate helper methods accordingly. - Adjust `string_table.dart` to take `BinaryWriter` and update `_writeWtf8`. - Update readers/writers throughout analyzer components: - library context/diagnostics, unlinked data, manifests, IDs, items, types, requirements, and informative data. - utilities for `EnumSet.read`/`write`. - summary2 bundle reader/writer and package bundle format. - Keep `_SummaryDataWriter` as an internal adapter now extending `BinaryWriter`. Compatibility - Binary format is unchanged; this is a pure rename refactor. - Endianness, variable-length encodings, and offsets remain identical. Change-Id: I97c07a708c1bd649084fc78a7c60c583964109ca Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450950 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 16d7b8f commit 9a720bb

22 files changed

+770
-776
lines changed

pkg/analyzer/lib/src/binary/binary_reader.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import 'dart:typed_data';
88
import 'package:_fe_analyzer_shared/src/scanner/string_canonicalizer.dart';
99
import 'package:analyzer/src/binary/string_table.dart';
1010

11-
/// Helper for reading primitive types from bytes.
12-
class SummaryDataReader {
11+
/// Reader for binary formats.
12+
class BinaryReader {
1313
final Uint8List bytes;
1414
int offset = 0;
1515

@@ -21,16 +21,16 @@ class SummaryDataReader {
2121
final Float64List _doubleBuffer = Float64List(1);
2222
late final Uint8List _doubleBufferUint8 = _doubleBuffer.buffer.asUint8List();
2323

24-
SummaryDataReader(this.bytes);
24+
BinaryReader(this.bytes);
2525

2626
void createStringTable(int offset) {
2727
_stringTable = StringTable(bytes: bytes, startOffset: offset);
2828
}
2929

3030
/// Create a new instance with the given [offset].
3131
/// It shares the same bytes and string reader.
32-
SummaryDataReader fork(int offset) {
33-
var result = SummaryDataReader(bytes);
32+
BinaryReader fork(int offset) {
33+
var result = BinaryReader(bytes);
3434
result.offset = offset;
3535
result._stringTable = _stringTable;
3636
return result;

pkg/analyzer/lib/src/binary/binary_writer.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import 'dart:convert';
66
import 'dart:typed_data';
77

8-
/// Puts a buffer in front of a [Sink<List<int>>].
9-
class BufferedSink {
8+
/// Buffered writer for binary formats.
9+
class BinaryWriter {
1010
static const int _SIZE = 128 * 1024;
1111
static const int _SAFE_LENGTH = _SIZE - 5;
1212

@@ -21,7 +21,7 @@ class BufferedSink {
2121
final Float64List _doubleBuffer = Float64List(1);
2222
late final Uint8List _doubleBufferUint8 = _doubleBuffer.buffer.asUint8List();
2323

24-
BufferedSink();
24+
BinaryWriter();
2525

2626
int get offset => _builder.length + _length;
2727

pkg/analyzer/lib/src/binary/string_table.dart

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ class StringIndexer {
2121
return result;
2222
}
2323

24-
int write(BufferedSink sink) {
25-
var bytesOffset = sink.offset;
24+
int write(BinaryWriter writer) {
25+
var bytesOffset = writer.offset;
2626

2727
var length = _index.length;
2828
var lengths = Uint32List(length);
2929
var lengthsIndex = 0;
3030
for (var key in _index.keys) {
31-
var stringStart = sink.offset;
32-
_writeWtf8(sink, key);
33-
lengths[lengthsIndex++] = sink.offset - stringStart;
31+
var stringStart = writer.offset;
32+
_writeWtf8(writer, key);
33+
lengths[lengthsIndex++] = writer.offset - stringStart;
3434
}
3535

36-
var resultOffset = sink.offset;
36+
var resultOffset = writer.offset;
3737

38-
var lengthOfBytes = sink.offset - bytesOffset;
39-
sink.writeUint30(lengthOfBytes);
40-
sink.writeUint30List(lengths);
38+
var lengthOfBytes = writer.offset - bytesOffset;
39+
writer.writeUint30(lengthOfBytes);
40+
writer.writeUint30List(lengths);
4141

4242
return resultOffset;
4343
}
4444

45-
/// Write [source] string into [sink].
46-
static void _writeWtf8(BufferedSink sink, String source) {
45+
/// Write [source] string into [writer].
46+
static void _writeWtf8(BinaryWriter writer, String source) {
4747
var end = source.length;
4848
if (end == 0) {
4949
return;
@@ -54,28 +54,28 @@ class StringIndexer {
5454
var codeUnit = source.codeUnitAt(i++);
5555
if (codeUnit < 128) {
5656
// ASCII.
57-
sink.writeByte(codeUnit);
57+
writer.writeByte(codeUnit);
5858
} else if (codeUnit < 0x800) {
5959
// Two-byte sequence (11-bit unicode value).
60-
sink.writeByte(0xC0 | (codeUnit >> 6));
61-
sink.writeByte(0x80 | (codeUnit & 0x3f));
60+
writer.writeByte(0xC0 | (codeUnit >> 6));
61+
writer.writeByte(0x80 | (codeUnit & 0x3f));
6262
} else if ((codeUnit & 0xFC00) == 0xD800 &&
6363
i < end &&
6464
(source.codeUnitAt(i) & 0xFC00) == 0xDC00) {
6565
// Surrogate pair -> four-byte sequence (non-BMP unicode value).
6666
int codeUnit2 = source.codeUnitAt(i++);
6767
int unicode =
6868
0x10000 + ((codeUnit & 0x3FF) << 10) + (codeUnit2 & 0x3FF);
69-
sink.writeByte(0xF0 | (unicode >> 18));
70-
sink.writeByte(0x80 | ((unicode >> 12) & 0x3F));
71-
sink.writeByte(0x80 | ((unicode >> 6) & 0x3F));
72-
sink.writeByte(0x80 | (unicode & 0x3F));
69+
writer.writeByte(0xF0 | (unicode >> 18));
70+
writer.writeByte(0x80 | ((unicode >> 12) & 0x3F));
71+
writer.writeByte(0x80 | ((unicode >> 6) & 0x3F));
72+
writer.writeByte(0x80 | (unicode & 0x3F));
7373
} else {
7474
// Three-byte sequence (16-bit unicode value), including lone
7575
// surrogates.
76-
sink.writeByte(0xE0 | (codeUnit >> 12));
77-
sink.writeByte(0x80 | ((codeUnit >> 6) & 0x3f));
78-
sink.writeByte(0x80 | (codeUnit & 0x3f));
76+
writer.writeByte(0xE0 | (codeUnit >> 12));
77+
writer.writeByte(0x80 | ((codeUnit >> 6) & 0x3f));
78+
writer.writeByte(0x80 | (codeUnit & 0x3f));
7979
}
8080
} while (i < end);
8181
}

pkg/analyzer/lib/src/dart/analysis/library_context.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ class LinkedBundleProvider {
551551
}
552552

553553
performance.getDataInt('bytesLength').add(bytes.length);
554-
var reader = SummaryDataReader(bytes);
554+
var reader = BinaryReader(bytes);
555555
var nonTransitiveApiSignature = reader.readStringUtf8();
556556
var libraryManifests = reader.readMap(
557557
readKey: () => reader.readUri(),
@@ -582,18 +582,18 @@ class LinkedBundleProvider {
582582
required LinkedBundleEntry entry,
583583
required OperationPerformanceImpl performance,
584584
}) {
585-
var sink = BufferedSink();
585+
var writer = BinaryWriter();
586586

587-
sink.writeStringUtf8(entry.nonTransitiveApiSignature);
588-
sink.writeMap(
587+
writer.writeStringUtf8(entry.nonTransitiveApiSignature);
588+
writer.writeMap(
589589
entry.libraryManifests,
590-
writeKey: (uri) => sink.writeUri(uri),
591-
writeValue: (manifest) => manifest.write(sink),
590+
writeKey: (uri) => writer.writeUri(uri),
591+
writeValue: (manifest) => manifest.write(writer),
592592
);
593-
entry.requirements.write(sink);
594-
sink.writeUint8List(entry.linkedBytes);
593+
entry.requirements.write(writer);
594+
writer.writeUint8List(entry.linkedBytes);
595595

596-
var bytes = sink.takeBytes();
596+
var bytes = writer.takeBytes();
597597
byteStore.putGet(key, bytes);
598598
performance.getDataInt('bytes').add(bytes.length);
599599

pkg/analyzer/lib/src/dart/analysis/library_diagnostics.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class LibraryDiagnosticsBundle {
3232
});
3333

3434
factory LibraryDiagnosticsBundle.fromBytes(Uint8List bytes) {
35-
var reader = SummaryDataReader(bytes);
35+
var reader = BinaryReader(bytes);
3636
return LibraryDiagnosticsBundle(
3737
requirements: RequirementsManifest.read(reader),
3838
serializedFileResults: reader.readMap(
@@ -51,13 +51,13 @@ class LibraryDiagnosticsBundle {
5151
}
5252

5353
Uint8List toBytes() {
54-
var sink = BufferedSink();
55-
requirements.write(sink);
56-
sink.writeMap(
54+
var writer = BinaryWriter();
55+
requirements.write(writer);
56+
writer.writeMap(
5757
serializedFileResults,
58-
writeKey: (uri) => sink.writeUri(uri),
59-
writeValue: (bytes) => sink.writeUint8List(bytes),
58+
writeKey: (uri) => writer.writeUri(uri),
59+
writeValue: (bytes) => writer.writeUint8List(bytes),
6060
);
61-
return sink.takeBytes();
61+
return writer.takeBytes();
6262
}
6363
}

0 commit comments

Comments
 (0)