Skip to content

Commit

Permalink
Avoid redundant ByteData allocation when decoding sfixed64 (#889)
Browse files Browse the repository at this point in the history
Ideally `Int64.fromBytes` would provide a `skip` argument (similar to
`Utf8Decoder.convert`) to avoid allocating intermediate views completely, but
for now we just remove the intermediate `ByteData`.
  • Loading branch information
osa1 authored Oct 25, 2023
1 parent 1b1d549 commit e146515
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions protobuf/lib/src/protobuf/coded_buffer_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ class CodedBufferReader {
int readFixed32() => _readByteData(4).getUint32(0, Endian.little);
Int64 readFixed64() => readSfixed64();
int readSfixed32() => _readByteData(4).getInt32(0, Endian.little);

Int64 readSfixed64() {
final data = _readByteData(8);
final view = Uint8List.view(data.buffer, data.offsetInBytes, 8);
final pos = _bufferPos;
_checkLimit(8);
final view = Uint8List.sublistView(_buffer, pos, pos + 8);
return Int64.fromBytes(view);
}

Expand Down

0 comments on commit e146515

Please sign in to comment.