Skip to content

Commit

Permalink
Dart null safety - minor review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Jun 21, 2021
1 parent d7ca857 commit 304056a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dart/lib/flat_buffers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ class BufferContext {

ByteData get buffer => _buffer;

/// Create from a FlatBuffer represented by a list of bytes (uint8).
factory BufferContext.fromBytes(List<int> byteList) {
Uint8List uint8List = _asUint8List(byteList);
ByteData buf = new ByteData.view(uint8List.buffer, uint8List.offsetInBytes);
return BufferContext(buf);
}

/// Create from a FlatBuffer represented by ByteData.
BufferContext(this._buffer);

int derefObject(int offset) {
Expand Down Expand Up @@ -112,7 +114,6 @@ class Builder {
final int initialSize;

/// The list of existing VTable(s).
//final List<_VTable> _vTables = <_VTable>[];
final List<int> _vTables = List<int>.filled(16, 0, growable: true)
..length = 0;

Expand All @@ -128,7 +129,7 @@ class Builder {
int _tail = 0;

/// The location of the end of the current table, measured in bytes from the
/// end of [_buf], or `null` if a table is not currently being built.
/// end of [_buf].
int _currentTableEndTail = 0;

_VTable? _currentVTable;
Expand Down
8 changes: 4 additions & 4 deletions dart/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class Builder {
bd.buffer.asUint8List().setAll(0, buffer);
return bd.buffer;
}

void _integrityCheckOnValueAddition() {
if (_finished) {
throw StateError('Adding values after finish is prohibited');
Expand Down Expand Up @@ -288,7 +288,7 @@ class Builder {
_writeUInt(byteWidth, 1);
_finished = true;
}

_StackValue _createVector(int start, int vecLength, int step, [_StackValue? keys]) {
var bitWidth = BitWidthUtil.uwidth(vecLength);
var prefixElements = 1;
Expand Down Expand Up @@ -383,7 +383,7 @@ class Builder {
}
_endMap(pointer);
}

void _endMap(_StackPointer pointer) {
final vecLength = (_stack.length - pointer.stackPosition) >> 1;
final offsets = <int>[];
Expand Down Expand Up @@ -552,10 +552,10 @@ class _StackValue {

BitWidth elementWidth(int size, int index) {
if (ValueTypeUtils.isInline(_type)) return _width;
final offset = offsetLoc - _offset!;
for(var i = 0; i < 4; i++) {
final width = 1 << i;
final offsetLoc = size + BitWidthUtil.paddingSize(size, width) + index * width;
final offset = offsetLoc - _offset!;
final bitWidth = BitWidthUtil.uwidth(offset);
if (1 << bitWidth.index == width) {
return bitWidth;
Expand Down
2 changes: 1 addition & 1 deletion dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ dev_dependencies:
test_reflective_loader: ^0.2.0
path: ^1.8.0
environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

0 comments on commit 304056a

Please sign in to comment.