Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Unified Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1574683002: Include addBool/BoolReader into FlatBuffers. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove debug output. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/flat_buffers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698