@@ -382,7 +382,6 @@ class Builder {
382382 /// interpreted as a 4-byte Latin-1 encoded string that should be placed at
383383 /// bytes 4-7 of the file.
384384 void finish (int offset, [String ? fileIdentifier]) {
385- assert (! _finished);
386385 final sizeBeforePadding = size ();
387386 final requiredBytes = _sizeofUint32 * (fileIdentifier == null ? 1 : 2 );
388387 _prepare (max (requiredBytes, _maxAlign), 1 );
@@ -776,6 +775,7 @@ class Builder {
776775 /// tail pointer to point at the allocated space.
777776 @pragma ('vm:prefer-inline' )
778777 void _prepare (int size, int count, {int additionalBytes = 0 }) {
778+ assert (! _finished);
779779 // Update the alignment.
780780 if (_maxAlign < size) {
781781 _maxAlign = size;
@@ -985,20 +985,34 @@ class Int8Reader extends Reader<int> {
985985 int read (BufferContext bc, int offset) => bc._getInt8 (offset);
986986}
987987
988- /// The reader of lists of objects.
989- ///
990- /// The returned unmodifiable lists lazily read objects on access.
988+ /// The reader of lists of objects. Lazy by default - see [lazy] .
991989class ListReader <E > extends Reader <List <E >> {
992990 final Reader <E > _elementReader;
993991
994- const ListReader (this ._elementReader);
992+ /// Enables lazy reading of the list
993+ ///
994+ /// If true, the returned unmodifiable list lazily reads objects on access.
995+ /// Therefore, the underlying buffer must not change while accessing the list.
996+ ///
997+ /// If false, reads the whole list immediately on access.
998+ final bool lazy;
999+
1000+ const ListReader (this ._elementReader, {this .lazy = true });
9951001
9961002 @override
9971003 int get size => _sizeofUint32;
9981004
9991005 @override
1000- List <E > read (BufferContext bc, int offset) =>
1001- new _FbGenericList <E >(_elementReader, bc, bc.derefObject (offset));
1006+ List <E > read (BufferContext bc, int offset) {
1007+ final listOffset = bc.derefObject (offset);
1008+ return lazy
1009+ ? _FbGenericList <E >(_elementReader, bc, listOffset)
1010+ : List <E >.generate (
1011+ bc.buffer.getUint32 (listOffset, Endian .little),
1012+ (int index) => _elementReader.read (
1013+ bc, listOffset + size + _elementReader.size * index),
1014+ growable: true );
1015+ }
10021016}
10031017
10041018/// Object that can read a value at a [BufferContext] .
0 commit comments