Skip to content

Commit 924f3a3

Browse files
scheglovCommit Queue
authored andcommitted
CQ. Make BufferedSink addByteX methods private.
These are low-level internal methods, and `writeXyz` should be used instead. Change-Id: Ib68e30527a28b6282ebf56c8fd7e92c689ccd612 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417107 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent de339e1 commit 924f3a3

File tree

3 files changed

+67
-68
lines changed

3 files changed

+67
-68
lines changed

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,15 +955,15 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
955955

956956
void _writeByte(int byte) {
957957
assert((byte & 0xFF) == byte);
958-
_sink.addByte(byte);
958+
_sink.writeByte(byte);
959959
}
960960

961961
void _writeDeclarationName(Token token) {
962962
_writeStringReference(token.lexeme);
963963
}
964964

965965
void _writeDouble(double value) {
966-
_sink.addDouble(value);
966+
_sink.writeDouble(value);
967967
}
968968

969969
void _writeNode(AstNode node) {
@@ -997,8 +997,7 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
997997
}
998998

999999
void _writeUInt32(int value) {
1000-
_sink.addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF,
1001-
(value >> 8) & 0xFF, value & 0xFF);
1000+
_sink.writeUInt32(value);
10021001
}
10031002

10041003
/// Return `true` if the expression might be successfully serialized.

pkg/analyzer/lib/src/summary2/bundle_writer.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class BundleWriter {
6868

6969
BundleWriterResult finish() {
7070
var baseResolutionOffset = _sink.offset;
71-
_sink.addBytes(_resolutionSink.takeBytes());
71+
_sink.writeBytes(_resolutionSink.takeBytes());
7272

7373
var librariesOffset = _sink.offset;
7474
_sink.writeList<_Library>(_libraries, (library) {
@@ -1072,28 +1072,28 @@ class StringIndexer {
10721072
var codeUnit = source.codeUnitAt(i++);
10731073
if (codeUnit < 128) {
10741074
// ASCII.
1075-
sink.addByte(codeUnit);
1075+
sink.writeByte(codeUnit);
10761076
} else if (codeUnit < 0x800) {
10771077
// Two-byte sequence (11-bit unicode value).
1078-
sink.addByte(0xC0 | (codeUnit >> 6));
1079-
sink.addByte(0x80 | (codeUnit & 0x3f));
1078+
sink.writeByte(0xC0 | (codeUnit >> 6));
1079+
sink.writeByte(0x80 | (codeUnit & 0x3f));
10801080
} else if ((codeUnit & 0xFC00) == 0xD800 &&
10811081
i < end &&
10821082
(source.codeUnitAt(i) & 0xFC00) == 0xDC00) {
10831083
// Surrogate pair -> four-byte sequence (non-BMP unicode value).
10841084
int codeUnit2 = source.codeUnitAt(i++);
10851085
int unicode =
10861086
0x10000 + ((codeUnit & 0x3FF) << 10) + (codeUnit2 & 0x3FF);
1087-
sink.addByte(0xF0 | (unicode >> 18));
1088-
sink.addByte(0x80 | ((unicode >> 12) & 0x3F));
1089-
sink.addByte(0x80 | ((unicode >> 6) & 0x3F));
1090-
sink.addByte(0x80 | (unicode & 0x3F));
1087+
sink.writeByte(0xF0 | (unicode >> 18));
1088+
sink.writeByte(0x80 | ((unicode >> 12) & 0x3F));
1089+
sink.writeByte(0x80 | ((unicode >> 6) & 0x3F));
1090+
sink.writeByte(0x80 | (unicode & 0x3F));
10911091
} else {
10921092
// Three-byte sequence (16-bit unicode value), including lone
10931093
// surrogates.
1094-
sink.addByte(0xE0 | (codeUnit >> 12));
1095-
sink.addByte(0x80 | ((codeUnit >> 6) & 0x3f));
1096-
sink.addByte(0x80 | (codeUnit & 0x3f));
1094+
sink.writeByte(0xE0 | (codeUnit >> 12));
1095+
sink.writeByte(0x80 | ((codeUnit >> 6) & 0x3f));
1096+
sink.writeByte(0x80 | (codeUnit & 0x3f));
10971097
}
10981098
} while (i < end);
10991099
}

pkg/analyzer/lib/src/summary2/data_writer.dart

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,23 @@ class BufferedSink {
2222

2323
int get offset => _builder.length + _length;
2424

25-
@pragma("vm:prefer-inline")
26-
void addByte(int byte) {
27-
_buffer[_length++] = byte;
28-
if (_length == _SIZE) {
29-
_builder.add(_buffer);
30-
_buffer = Uint8List(_SIZE);
31-
_length = 0;
32-
}
25+
Uint8List takeBytes() {
26+
_builder.add(_buffer.sublist(0, _length));
27+
return _builder.takeBytes();
3328
}
3429

3530
@pragma("vm:prefer-inline")
36-
void addByte2(int byte1, int byte2) {
37-
if (_length < _SAFE_LENGTH) {
38-
_buffer[_length++] = byte1;
39-
_buffer[_length++] = byte2;
40-
} else {
41-
addByte(byte1);
42-
addByte(byte2);
43-
}
31+
void writeBool(bool value) {
32+
writeByte(value ? 1 : 0);
4433
}
4534

4635
@pragma("vm:prefer-inline")
47-
void addByte4(int byte1, int byte2, int byte3, int byte4) {
48-
if (_length < _SAFE_LENGTH) {
49-
_buffer[_length++] = byte1;
50-
_buffer[_length++] = byte2;
51-
_buffer[_length++] = byte3;
52-
_buffer[_length++] = byte4;
53-
} else {
54-
addByte(byte1);
55-
addByte(byte2);
56-
addByte(byte3);
57-
addByte(byte4);
58-
}
36+
void writeByte(int byte) {
37+
assert((byte & 0xFF) == byte);
38+
_addByte(byte);
5939
}
6040

61-
void addBytes(Uint8List bytes) {
41+
void writeBytes(Uint8List bytes) {
6242
if (bytes.isEmpty) {
6343
return;
6444
}
@@ -92,38 +72,22 @@ class BufferedSink {
9272
_length = remainder;
9373
}
9474

95-
void addDouble(double value) {
75+
void writeDouble(double value) {
9676
_doubleBuffer[0] = value;
97-
addByte4(
77+
_addByte4(
9878
_doubleBufferUint8[0],
9979
_doubleBufferUint8[1],
10080
_doubleBufferUint8[2],
10181
_doubleBufferUint8[3],
10282
);
103-
addByte4(
83+
_addByte4(
10484
_doubleBufferUint8[4],
10585
_doubleBufferUint8[5],
10686
_doubleBufferUint8[6],
10787
_doubleBufferUint8[7],
10888
);
10989
}
11090

111-
Uint8List takeBytes() {
112-
_builder.add(_buffer.sublist(0, _length));
113-
return _builder.takeBytes();
114-
}
115-
116-
@pragma("vm:prefer-inline")
117-
void writeBool(bool value) {
118-
writeByte(value ? 1 : 0);
119-
}
120-
121-
@pragma("vm:prefer-inline")
122-
void writeByte(int byte) {
123-
assert((byte & 0xFF) == byte);
124-
addByte(byte);
125-
}
126-
12791
void writeEnum(Enum e) {
12892
writeByte(e.index);
12993
}
@@ -229,11 +193,11 @@ class BufferedSink {
229193
void writeUInt30(int value) {
230194
assert(value >= 0 && value >> 30 == 0);
231195
if (value < 0x80) {
232-
addByte(value);
196+
_addByte(value);
233197
} else if (value < 0x4000) {
234-
addByte2((value >> 8) | 0x80, value & 0xFF);
198+
_addByte2((value >> 8) | 0x80, value & 0xFF);
235199
} else {
236-
addByte4((value >> 24) | 0xC0, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
200+
_addByte4((value >> 24) | 0xC0, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
237201
value & 0xFF);
238202
}
239203
}
@@ -247,17 +211,53 @@ class BufferedSink {
247211
}
248212

249213
void writeUInt32(int value) {
250-
addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
214+
_addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
251215
value & 0xFF);
252216
}
253217

254218
void writeUint8List(Uint8List bytes) {
255219
writeUInt30(bytes.length);
256-
addBytes(bytes);
220+
writeBytes(bytes);
257221
}
258222

259223
void writeUri(Uri uri) {
260224
var uriStr = uri.toString();
261225
writeStringUtf8(uriStr);
262226
}
227+
228+
@pragma("vm:prefer-inline")
229+
void _addByte(int byte) {
230+
_buffer[_length++] = byte;
231+
if (_length == _SIZE) {
232+
_builder.add(_buffer);
233+
_buffer = Uint8List(_SIZE);
234+
_length = 0;
235+
}
236+
}
237+
238+
@pragma("vm:prefer-inline")
239+
void _addByte2(int byte1, int byte2) {
240+
if (_length < _SAFE_LENGTH) {
241+
_buffer[_length++] = byte1;
242+
_buffer[_length++] = byte2;
243+
} else {
244+
_addByte(byte1);
245+
_addByte(byte2);
246+
}
247+
}
248+
249+
@pragma("vm:prefer-inline")
250+
void _addByte4(int byte1, int byte2, int byte3, int byte4) {
251+
if (_length < _SAFE_LENGTH) {
252+
_buffer[_length++] = byte1;
253+
_buffer[_length++] = byte2;
254+
_buffer[_length++] = byte3;
255+
_buffer[_length++] = byte4;
256+
} else {
257+
_addByte(byte1);
258+
_addByte(byte2);
259+
_addByte(byte3);
260+
_addByte(byte4);
261+
}
262+
}
263263
}

0 commit comments

Comments
 (0)