Unverified Commit 38f360f9 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Increased WriteBuffers starting capacity to 64 bytes. (#101790)

parent 88724e59
......@@ -13,10 +13,14 @@ import 'dart:typed_data';
/// The byte order used is [Endian.host] throughout.
class WriteBuffer {
/// Creates an interface for incrementally building a [ByteData] instance.
factory WriteBuffer() {
/// [startCapacity] determines the start size of the [WriteBuffer] in bytes.
/// The closer that value is to the real size used, the better the
/// performance.
factory WriteBuffer({int startCapacity = 8}) {
assert(startCapacity > 0);
final ByteData eightBytes = ByteData(8);
final Uint8List eightBytesAsList = eightBytes.buffer.asUint8List();
return WriteBuffer._(Uint8List(8), eightBytes, eightBytesAsList);
return WriteBuffer._(Uint8List(startCapacity), eightBytes, eightBytesAsList);
}
WriteBuffer._(this._buffer, this._eightBytes, this._eightBytesAsList);
......
......@@ -310,7 +310,7 @@ class StandardMessageCodec implements MessageCodec<Object?> {
ByteData? encodeMessage(Object? message) {
if (message == null)
return null;
final WriteBuffer buffer = WriteBuffer();
final WriteBuffer buffer = WriteBuffer(startCapacity: 64);
writeValue(buffer, message);
return buffer.done();
}
......
......@@ -124,5 +124,11 @@ void main() {
write.done();
expect(() => write.done(), throwsStateError);
});
test('empty WriteBuffer', () {
expect(() => WriteBuffer(startCapacity: 0), throwsAssertionError);
});
test('size 1', () {
expect(() => WriteBuffer(startCapacity: 1), returnsNormally);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment