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

Side by Side Diff: pkg/analyzer/lib/src/summary/flat_buffers.dart

Issue 1568343002: Support for writing Int32 lists. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.summary.flat_buffers; 5 library analyzer.src.summary.flat_buffers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:typed_data'; 9 import 'dart:typed_data';
10 10
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 _setUint32AtTail(_buf, tail, values.length); 242 _setUint32AtTail(_buf, tail, values.length);
243 tail -= 4; 243 tail -= 4;
244 for (Offset value in values) { 244 for (Offset value in values) {
245 _setUint32AtTail(_buf, tail, tail - value._tail); 245 _setUint32AtTail(_buf, tail, tail - value._tail);
246 tail -= 4; 246 tail -= 4;
247 } 247 }
248 return result; 248 return result;
249 } 249 }
250 250
251 /** 251 /**
252 * Write the given list of signed 32-bit integer [values].
253 */
254 Offset writeListInt32(List<int> values) {
255 if (_currentVTableBuilder != null) {
256 throw new StateError(
257 'Cannot write a non-scalar value while writing a table.');
258 }
259 _prepare(4, 1 + values.length);
260 Offset result = new Offset(_tail);
261 int tail = _tail;
262 _setUint32AtTail(_buf, tail, values.length);
263 tail -= 4;
264 for (int value in values) {
265 _setInt32AtTail(_buf, tail, value);
266 tail -= 4;
267 }
268 return result;
269 }
270
271 /**
252 * Write the given string [value] and return its [Offset], or `null` if 272 * Write the given string [value] and return its [Offset], or `null` if
253 * the [value] is equal to [def]. 273 * the [value] is equal to [def].
254 */ 274 */
255 Offset<String> writeString(String value, [String def]) { 275 Offset<String> writeString(String value, [String def]) {
256 if (_currentVTableBuilder != null) { 276 if (_currentVTableBuilder != null) {
257 throw new StateError( 277 throw new StateError(
258 'Cannot write a non-scalar value while writing a table.'); 278 'Cannot write a non-scalar value while writing a table.');
259 } 279 }
260 if (value != def) { 280 if (value != def) {
261 // TODO(scheglov) optimize for ASCII strings 281 // TODO(scheglov) optimize for ASCII strings
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 342 }
323 } 343 }
324 344
325 /** 345 /**
326 * The reader of 32-bit signed integers. 346 * The reader of 32-bit signed integers.
327 */ 347 */
328 class Int32Reader extends Reader<int> { 348 class Int32Reader extends Reader<int> {
329 const Int32Reader() : super(); 349 const Int32Reader() : super();
330 350
331 @override 351 @override
332 int get size => 2; 352 int get size => 4;
333 353
334 @override 354 @override
335 int read(BufferPointer bp) => bp._getInt32(); 355 int read(BufferPointer bp) => bp._getInt32();
336 } 356 }
337 357
338 /** 358 /**
339 * The reader of 8-bit signed integers. 359 * The reader of 8-bit signed integers.
340 */ 360 */
341 class Int8Reader extends Reader<int> { 361 class Int8Reader extends Reader<int> {
342 const Int8Reader() : super(); 362 const Int8Reader() : super();
343 363
344 @override 364 @override
345 int get size => 1; 365 int get size => 1;
346 366
347 @override 367 @override
348 int read(BufferPointer bp) => bp._getInt8(); 368 int read(BufferPointer bp) => bp._getInt8();
349 } 369 }
350 370
351 /** 371 /**
352 * The reader of object. 372 * The reader of lists of objects.
353 * 373 *
354 * The returned unmodifiable lists lazily read objects on access. 374 * The returned unmodifiable lists lazily read objects on access.
355 */ 375 */
356 class ListReader<E> extends Reader<List<E>> { 376 class ListReader<E> extends Reader<List<E>> {
357 final Reader<E> _elementReader; 377 final Reader<E> _elementReader;
358 378
359 const ListReader(this._elementReader); 379 const ListReader(this._elementReader);
360 380
361 @override 381 @override
362 int get size => 4; 382 int get size => 4;
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); 520 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN);
501 bufOffset += 2; 521 bufOffset += 2;
502 // Field offsets. 522 // Field offsets.
503 for (int fieldTail in fieldTails) { 523 for (int fieldTail in fieldTails) {
504 int fieldOffset = fieldTail == null ? 0 : tableTail - fieldTail; 524 int fieldOffset = fieldTail == null ? 0 : tableTail - fieldTail;
505 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); 525 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN);
506 bufOffset += 2; 526 bufOffset += 2;
507 } 527 }
508 } 528 }
509 } 529 }
OLDNEW
« 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