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 <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
index 2e7d447..61260c0 100644
--- a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
@@ -955,7 +955,7 @@
 
   void _writeByte(int byte) {
     assert((byte & 0xFF) == byte);
-    _sink.addByte(byte);
+    _sink.writeByte(byte);
   }
 
   void _writeDeclarationName(Token token) {
@@ -963,7 +963,7 @@
   }
 
   void _writeDouble(double value) {
-    _sink.addDouble(value);
+    _sink.writeDouble(value);
   }
 
   void _writeNode(AstNode node) {
@@ -997,8 +997,7 @@
   }
 
   void _writeUInt32(int value) {
-    _sink.addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF,
-        (value >> 8) & 0xFF, value & 0xFF);
+    _sink.writeUInt32(value);
   }
 
   /// Return `true` if the expression might be successfully serialized.
diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
index d62d5d4..331e5a3 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart
@@ -68,7 +68,7 @@
 
   BundleWriterResult finish() {
     var baseResolutionOffset = _sink.offset;
-    _sink.addBytes(_resolutionSink.takeBytes());
+    _sink.writeBytes(_resolutionSink.takeBytes());
 
     var librariesOffset = _sink.offset;
     _sink.writeList<_Library>(_libraries, (library) {
@@ -1072,11 +1072,11 @@
       var codeUnit = source.codeUnitAt(i++);
       if (codeUnit < 128) {
         // ASCII.
-        sink.addByte(codeUnit);
+        sink.writeByte(codeUnit);
       } else if (codeUnit < 0x800) {
         // Two-byte sequence (11-bit unicode value).
-        sink.addByte(0xC0 | (codeUnit >> 6));
-        sink.addByte(0x80 | (codeUnit & 0x3f));
+        sink.writeByte(0xC0 | (codeUnit >> 6));
+        sink.writeByte(0x80 | (codeUnit & 0x3f));
       } else if ((codeUnit & 0xFC00) == 0xD800 &&
           i < end &&
           (source.codeUnitAt(i) & 0xFC00) == 0xDC00) {
@@ -1084,16 +1084,16 @@
         int codeUnit2 = source.codeUnitAt(i++);
         int unicode =
             0x10000 + ((codeUnit & 0x3FF) << 10) + (codeUnit2 & 0x3FF);
-        sink.addByte(0xF0 | (unicode >> 18));
-        sink.addByte(0x80 | ((unicode >> 12) & 0x3F));
-        sink.addByte(0x80 | ((unicode >> 6) & 0x3F));
-        sink.addByte(0x80 | (unicode & 0x3F));
+        sink.writeByte(0xF0 | (unicode >> 18));
+        sink.writeByte(0x80 | ((unicode >> 12) & 0x3F));
+        sink.writeByte(0x80 | ((unicode >> 6) & 0x3F));
+        sink.writeByte(0x80 | (unicode & 0x3F));
       } else {
         // Three-byte sequence (16-bit unicode value), including lone
         // surrogates.
-        sink.addByte(0xE0 | (codeUnit >> 12));
-        sink.addByte(0x80 | ((codeUnit >> 6) & 0x3f));
-        sink.addByte(0x80 | (codeUnit & 0x3f));
+        sink.writeByte(0xE0 | (codeUnit >> 12));
+        sink.writeByte(0x80 | ((codeUnit >> 6) & 0x3f));
+        sink.writeByte(0x80 | (codeUnit & 0x3f));
       }
     } while (i < end);
   }
diff --git a/pkg/analyzer/lib/src/summary2/data_writer.dart b/pkg/analyzer/lib/src/summary2/data_writer.dart
index 7691cdb..099cfcc 100644
--- a/pkg/analyzer/lib/src/summary2/data_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/data_writer.dart
@@ -22,43 +22,23 @@
 
   int get offset => _builder.length + _length;
 
-  @pragma("vm:prefer-inline")
-  void addByte(int byte) {
-    _buffer[_length++] = byte;
-    if (_length == _SIZE) {
-      _builder.add(_buffer);
-      _buffer = Uint8List(_SIZE);
-      _length = 0;
-    }
+  Uint8List takeBytes() {
+    _builder.add(_buffer.sublist(0, _length));
+    return _builder.takeBytes();
   }
 
   @pragma("vm:prefer-inline")
-  void addByte2(int byte1, int byte2) {
-    if (_length < _SAFE_LENGTH) {
-      _buffer[_length++] = byte1;
-      _buffer[_length++] = byte2;
-    } else {
-      addByte(byte1);
-      addByte(byte2);
-    }
+  void writeBool(bool value) {
+    writeByte(value ? 1 : 0);
   }
 
   @pragma("vm:prefer-inline")
-  void addByte4(int byte1, int byte2, int byte3, int byte4) {
-    if (_length < _SAFE_LENGTH) {
-      _buffer[_length++] = byte1;
-      _buffer[_length++] = byte2;
-      _buffer[_length++] = byte3;
-      _buffer[_length++] = byte4;
-    } else {
-      addByte(byte1);
-      addByte(byte2);
-      addByte(byte3);
-      addByte(byte4);
-    }
+  void writeByte(int byte) {
+    assert((byte & 0xFF) == byte);
+    _addByte(byte);
   }
 
-  void addBytes(Uint8List bytes) {
+  void writeBytes(Uint8List bytes) {
     if (bytes.isEmpty) {
       return;
     }
@@ -92,15 +72,15 @@
     _length = remainder;
   }
 
-  void addDouble(double value) {
+  void writeDouble(double value) {
     _doubleBuffer[0] = value;
-    addByte4(
+    _addByte4(
       _doubleBufferUint8[0],
       _doubleBufferUint8[1],
       _doubleBufferUint8[2],
       _doubleBufferUint8[3],
     );
-    addByte4(
+    _addByte4(
       _doubleBufferUint8[4],
       _doubleBufferUint8[5],
       _doubleBufferUint8[6],
@@ -108,22 +88,6 @@
     );
   }
 
-  Uint8List takeBytes() {
-    _builder.add(_buffer.sublist(0, _length));
-    return _builder.takeBytes();
-  }
-
-  @pragma("vm:prefer-inline")
-  void writeBool(bool value) {
-    writeByte(value ? 1 : 0);
-  }
-
-  @pragma("vm:prefer-inline")
-  void writeByte(int byte) {
-    assert((byte & 0xFF) == byte);
-    addByte(byte);
-  }
-
   void writeEnum(Enum e) {
     writeByte(e.index);
   }
@@ -229,11 +193,11 @@
   void writeUInt30(int value) {
     assert(value >= 0 && value >> 30 == 0);
     if (value < 0x80) {
-      addByte(value);
+      _addByte(value);
     } else if (value < 0x4000) {
-      addByte2((value >> 8) | 0x80, value & 0xFF);
+      _addByte2((value >> 8) | 0x80, value & 0xFF);
     } else {
-      addByte4((value >> 24) | 0xC0, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
+      _addByte4((value >> 24) | 0xC0, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
           value & 0xFF);
     }
   }
@@ -247,17 +211,53 @@
   }
 
   void writeUInt32(int value) {
-    addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
+    _addByte4((value >> 24) & 0xFF, (value >> 16) & 0xFF, (value >> 8) & 0xFF,
         value & 0xFF);
   }
 
   void writeUint8List(Uint8List bytes) {
     writeUInt30(bytes.length);
-    addBytes(bytes);
+    writeBytes(bytes);
   }
 
   void writeUri(Uri uri) {
     var uriStr = uri.toString();
     writeStringUtf8(uriStr);
   }
+
+  @pragma("vm:prefer-inline")
+  void _addByte(int byte) {
+    _buffer[_length++] = byte;
+    if (_length == _SIZE) {
+      _builder.add(_buffer);
+      _buffer = Uint8List(_SIZE);
+      _length = 0;
+    }
+  }
+
+  @pragma("vm:prefer-inline")
+  void _addByte2(int byte1, int byte2) {
+    if (_length < _SAFE_LENGTH) {
+      _buffer[_length++] = byte1;
+      _buffer[_length++] = byte2;
+    } else {
+      _addByte(byte1);
+      _addByte(byte2);
+    }
+  }
+
+  @pragma("vm:prefer-inline")
+  void _addByte4(int byte1, int byte2, int byte3, int byte4) {
+    if (_length < _SAFE_LENGTH) {
+      _buffer[_length++] = byte1;
+      _buffer[_length++] = byte2;
+      _buffer[_length++] = byte3;
+      _buffer[_length++] = byte4;
+    } else {
+      _addByte(byte1);
+      _addByte(byte2);
+      _addByte(byte3);
+      _addByte(byte4);
+    }
+  }
 }