Chromium Code Reviews| Index: pkg/analyzer/lib/src/summary/flat_buffers.dart |
| diff --git a/pkg/analyzer/lib/src/summary/flat_buffers.dart b/pkg/analyzer/lib/src/summary/flat_buffers.dart |
| index 5c1df2e66413c5589a11d1a2b0457e2ffd4707e0..708fa022517b0254fac68ceb60484da9ba3aa274 100644 |
| --- a/pkg/analyzer/lib/src/summary/flat_buffers.dart |
| +++ b/pkg/analyzer/lib/src/summary/flat_buffers.dart |
| @@ -10,6 +10,19 @@ import 'dart:math'; |
| import 'dart:typed_data'; |
| /** |
| + * The reader of booleans. |
| + */ |
| +class BoolReader extends Reader<bool> { |
| + const BoolReader() : super(); |
| + |
| + @override |
| + int get size => 1; |
| + |
| + @override |
| + bool read(BufferPointer bp) => bp._getInt8() == 1; |
|
Paul Berry
2016/01/09 14:38:46
Nit: I'd prefer to do `bp._getInt8() != 0`, for co
scheglov
2016/01/09 18:26:14
Done.
|
| +} |
| + |
| +/** |
| * A pointer to some data. |
| */ |
| class BufferPointer { |
| @@ -102,6 +115,23 @@ class Builder { |
| } |
| /** |
| + * Add the [field] with the given boolean [value]. The field is not added if |
| + * the [value] is equal to [def]. Booleans are stored as 8-bit fields with |
| + * `0` for `false` and `1` for `true`. |
| + */ |
| + void addBool(int field, bool value, [bool def]) { |
| + if (_currentVTable == null) { |
| + throw new StateError('Start a table before adding values.'); |
| + } |
| + if (value != null && value != def) { |
| + int size = 1; |
| + _prepare(size, 1); |
| + _trackField(field); |
| + _buf.setInt8(_buf.lengthInBytes - _tail, value ? 1 : 0); |
| + } |
| + } |
| + |
| + /** |
| * Add the [field] with the given 32-bit signed integer [value]. The field is |
| * not added if the [value] is equal to [def]. |
| */ |
| @@ -109,7 +139,7 @@ class Builder { |
| if (_currentVTable == null) { |
| throw new StateError('Start a table before adding values.'); |
| } |
| - if (value != def) { |
| + if (value != null && value != def) { |
| int size = 4; |
| _prepare(size, 1); |
| _trackField(field); |
| @@ -125,7 +155,7 @@ class Builder { |
| if (_currentVTable == null) { |
| throw new StateError('Start a table before adding values.'); |
| } |
| - if (value != def) { |
| + if (value != null && value != def) { |
| int size = 8; |
| _prepare(size, 1); |
| _trackField(field); |
| @@ -141,7 +171,7 @@ class Builder { |
| if (_currentVTable == null) { |
| throw new StateError('Start a table before adding values.'); |
| } |
| - if (value != def) { |
| + if (value != null && value != def) { |
| int size = 1; |
| _prepare(size, 1); |
| _trackField(field); |