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

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

Issue 1760523008: Don't use List caches for lists of primitive values. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 | no next file » | 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:math'; 9 import 'dart:math';
10 import 'dart:typed_data'; 10 import 'dart:typed_data';
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 int get size => 1; 729 int get size => 1;
730 730
731 @override 731 @override
732 int read(BufferPointer bp) => bp._getUint8(); 732 int read(BufferPointer bp) => bp._getUint8();
733 } 733 }
734 734
735 /** 735 /**
736 * List of booleans backed by 8-bit unsigned integers. 736 * List of booleans backed by 8-bit unsigned integers.
737 */ 737 */
738 class _FbBoolList extends Object with ListMixin<bool> implements List<bool> { 738 class _FbBoolList extends Object with ListMixin<bool> implements List<bool> {
739 final List<int> uint8List; 739 final BufferPointer bp;
740 int _length; 740 int _length;
741 741
742 _FbBoolList(BufferPointer bp) 742 _FbBoolList(this.bp);
743 : uint8List = new _FbGenericList<int>(const Uint8Reader(), bp);
744 743
745 @override 744 @override
746 int get length { 745 int get length {
747 if (_length == null) { 746 if (_length == null) {
748 _length = (uint8List.length - 1) * 8 - uint8List.last; 747 int byteLength = bp._getUint32();
748 _length = (byteLength - 1) * 8 - _getByte(byteLength - 1);
749 } 749 }
750 return _length; 750 return _length;
751 } 751 }
752 752
753 @override 753 @override
754 void set length(int i) => 754 void set length(int i) =>
755 throw new StateError('Attempt to modify immutable list'); 755 throw new StateError('Attempt to modify immutable list');
756 756
757 @override 757 @override
758 bool operator [](int i) { 758 bool operator [](int i) {
759 int index = i ~/ 8; 759 int index = i ~/ 8;
760 int mask = 1 << i % 8; 760 int mask = 1 << i % 8;
761 return uint8List[index] & mask != 0; 761 return _getByte(index) & mask != 0;
762 } 762 }
763 763
764 @override 764 @override
765 void operator []=(int i, bool e) => 765 void operator []=(int i, bool e) =>
766 throw new StateError('Attempt to modify immutable list'); 766 throw new StateError('Attempt to modify immutable list');
767
768 int _getByte(int index) => bp._getUint8(4 + index);
767 } 769 }
768 770
769 /** 771 /**
770 * The list backed by 64-bit values - Uint64 length and Float64. 772 * The list backed by 64-bit values - Uint64 length and Float64.
771 */ 773 */
772 class _FbFloat64List extends _FbList<double> { 774 class _FbFloat64List extends _FbList<double> {
773 List<double> _items;
774
775 _FbFloat64List(BufferPointer bp) : super(bp); 775 _FbFloat64List(BufferPointer bp) : super(bp);
776 776
777 @override 777 @override
778 double operator [](int i) { 778 double operator [](int i) {
779 _items ??= new List<double>(length); 779 return bp._getFloat64(8 + 8 * i);
780 double item = _items[i];
781 if (item == null) {
782 BufferPointer ref = bp._advance(8 + 8 * i);
783 item = ref._getFloat64();
784 _items[i] = item;
785 }
786 return item;
787 } 780 }
788 } 781 }
789 782
790 /** 783 /**
791 * List backed by a generic object which may have any size. 784 * List backed by a generic object which may have any size.
792 */ 785 */
793 class _FbGenericList<E> extends _FbList<E> { 786 class _FbGenericList<E> extends _FbList<E> {
794 final Reader<E> elementReader; 787 final Reader<E> elementReader;
795 788
796 List<E> _items; 789 List<E> _items;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 824
832 @override 825 @override
833 void operator []=(int i, E e) => 826 void operator []=(int i, E e) =>
834 throw new StateError('Attempt to modify immutable list'); 827 throw new StateError('Attempt to modify immutable list');
835 } 828 }
836 829
837 /** 830 /**
838 * List backed by 32-bit unsigned integers. 831 * List backed by 32-bit unsigned integers.
839 */ 832 */
840 class _FbUint32List extends _FbList<int> { 833 class _FbUint32List extends _FbList<int> {
841 List<int> _items;
842
843 _FbUint32List(BufferPointer bp) : super(bp); 834 _FbUint32List(BufferPointer bp) : super(bp);
844 835
845 @override 836 @override
846 int operator [](int i) { 837 int operator [](int i) {
847 _items ??= new List<int>(length); 838 return bp._getUint32(4 + 4 * i);
848 int item = _items[i];
849 if (item == null) {
850 item = bp._getUint32(4 + 4 * i);
851 _items[i] = item;
852 }
853 return item;
854 } 839 }
855 } 840 }
856 841
857 /** 842 /**
858 * Class that describes the structure of a table. 843 * Class that describes the structure of a table.
859 */ 844 */
860 class _VTable { 845 class _VTable {
861 final List<int> fieldTails = <int>[]; 846 final List<int> fieldTails = <int>[];
862 final List<int> fieldOffsets = <int>[]; 847 final List<int> fieldOffsets = <int>[];
863 848
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 // Table size. 906 // Table size.
922 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN); 907 buf.setUint16(bufOffset, tableSize, Endianness.LITTLE_ENDIAN);
923 bufOffset += 2; 908 bufOffset += 2;
924 // Field offsets. 909 // Field offsets.
925 for (int fieldOffset in fieldOffsets) { 910 for (int fieldOffset in fieldOffsets) {
926 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN); 911 buf.setUint16(bufOffset, fieldOffset, Endianness.LITTLE_ENDIAN);
927 bufOffset += 2; 912 bufOffset += 2;
928 } 913 }
929 } 914 }
930 } 915 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698