/home/andy/git/oilshell/oil/mycpp/gc_list.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef MYCPP_GC_LIST_H |
2 | | #define MYCPP_GC_LIST_H |
3 | | |
4 | | #include <string.h> // memcpy |
5 | | |
6 | | #include <algorithm> // sort() is templated |
7 | | |
8 | | #include "mycpp/common.h" // DCHECK |
9 | | #include "mycpp/comparators.h" |
10 | | #include "mycpp/gc_alloc.h" // Alloc |
11 | | #include "mycpp/gc_builtins.h" // ValueError |
12 | | #include "mycpp/gc_slab.h" |
13 | | |
14 | | // GlobalList is layout-compatible with List (unit tests assert this), and it |
15 | | // can be a true C global (incurs zero startup time) |
16 | | |
17 | | template <typename T, int N> |
18 | | class GlobalList { |
19 | | public: |
20 | | int len_; |
21 | | int capacity_; |
22 | | GlobalSlab<T, N>* slab_; |
23 | | }; |
24 | | |
25 | | #define GLOBAL_LIST(name, T, N, array) \ |
26 | | GcGlobal<GlobalSlab<T, N>> _slab_##name = {ObjHeader::Global(TypeTag::Slab), \ |
27 | | {.items_ = array}}; \ |
28 | | GcGlobal<GlobalList<T, N>> _list_##name = { \ |
29 | | ObjHeader::Global(TypeTag::List), \ |
30 | | {.len_ = N, .capacity_ = N, .slab_ = &_slab_##name.obj}}; \ |
31 | | List<T>* name = reinterpret_cast<List<T>*>(&_list_##name.obj); |
32 | | |
33 | | template <typename T> |
34 | | class List { |
35 | | public: |
36 | 918 | List() : len_(0), capacity_(0), slab_(nullptr) { |
37 | 918 | } Line | Count | Source | 36 | 136 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 136 | } |
Line | Count | Source | 36 | 686 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 686 | } |
_ZN4ListIP6Tuple2IP6BigStriEEC2Ev Line | Count | Source | 36 | 1 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEEC2Ev Line | Count | Source | 36 | 9 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 9 | } |
_ZN4ListIPN10hnode_asdl5FieldEEC2Ev Line | Count | Source | 36 | 37 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev Line | Count | Source | 36 | 37 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 37 | } |
Line | Count | Source | 36 | 3 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 3 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEEC2Ev Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEEC2Ev Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEEC2Ev _ZN4ListIP6Tuple2IiiEEC2Ev Line | Count | Source | 36 | 4 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 4 | } |
Line | Count | Source | 36 | 2 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 2 | } |
Line | Count | Source | 36 | 2 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 2 | } |
_ZN4ListIPN4pyos11PasswdEntryEEC2Ev Line | Count | Source | 36 | 1 | List() : len_(0), capacity_(0), slab_(nullptr) { | 37 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEEC2Ev Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEEC2Ev Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEEC2Ev |
38 | | |
39 | | // Implements L[i] |
40 | | T at(int i); |
41 | | |
42 | | // returns index of the element |
43 | | int index(T element); |
44 | | |
45 | | // Implements L[i] = item |
46 | | void set(int i, T item); |
47 | | |
48 | | // L[begin:] |
49 | | List* slice(int begin); |
50 | | |
51 | | // L[begin:end] |
52 | | List* slice(int begin, int end); |
53 | | |
54 | | // Should we have a separate API that doesn't return it? |
55 | | // https://stackoverflow.com/questions/12600330/pop-back-return-value |
56 | | T pop(); |
57 | | |
58 | | // Used in osh/word_parse.py to remove from front |
59 | | T pop(int i); |
60 | | |
61 | | // Remove the first occourence of x from the list. |
62 | | void remove(T x); |
63 | | |
64 | | void clear(); |
65 | | |
66 | | // Used in osh/string_ops.py |
67 | | void reverse(); |
68 | | |
69 | | // Templated function |
70 | | void sort(); |
71 | | |
72 | | // Ensure that there's space for at LEAST this many items |
73 | | void reserve(int num_desired); |
74 | | |
75 | | // Append a single element to this list. |
76 | | void append(T item); |
77 | | |
78 | | // Extend this list with multiple elements. |
79 | | void extend(List<T>* other); |
80 | | |
81 | 903 | static constexpr ObjHeader obj_header() { |
82 | 903 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); |
83 | 903 | } _ZN4ListIP6BigStrE10obj_headerEv Line | Count | Source | 81 | 136 | static constexpr ObjHeader obj_header() { | 82 | 136 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 136 | } |
_ZN4ListIiE10obj_headerEv Line | Count | Source | 81 | 675 | static constexpr ObjHeader obj_header() { | 82 | 675 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 675 | } |
_ZN4ListIP6Tuple2IP6BigStriEE10obj_headerEv Line | Count | Source | 81 | 1 | static constexpr ObjHeader obj_header() { | 82 | 1 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE10obj_headerEv Line | Count | Source | 81 | 5 | static constexpr ObjHeader obj_header() { | 82 | 5 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 5 | } |
_ZN4ListIPN10hnode_asdl5FieldEE10obj_headerEv Line | Count | Source | 81 | 37 | static constexpr ObjHeader obj_header() { | 82 | 37 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv Line | Count | Source | 81 | 37 | static constexpr ObjHeader obj_header() { | 82 | 37 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7y_lhs_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10place_op_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13ComprehensionEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NamedArgEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9EggexFlagEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10obj_headerEv _ZN4ListIbE10obj_headerEv Line | Count | Source | 81 | 3 | static constexpr ObjHeader obj_header() { | 82 | 3 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 3 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10obj_headerEv _ZN4ListIP6Tuple2IiiEE10obj_headerEv Line | Count | Source | 81 | 4 | static constexpr ObjHeader obj_header() { | 82 | 4 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 4 | } |
_ZN4ListIPiE10obj_headerEv Line | Count | Source | 81 | 2 | static constexpr ObjHeader obj_header() { | 82 | 2 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 2 | } |
_ZN4ListIdE10obj_headerEv Line | Count | Source | 81 | 2 | static constexpr ObjHeader obj_header() { | 82 | 2 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 2 | } |
_ZN4ListIPN4pyos11PasswdEntryEE10obj_headerEv Line | Count | Source | 81 | 1 | static constexpr ObjHeader obj_header() { | 82 | 1 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 83 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10obj_headerEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE10obj_headerEv |
84 | | |
85 | | int len_; // number of entries |
86 | | int capacity_; // max entries before resizing |
87 | | |
88 | | // The container may be resized, so this field isn't in-line. |
89 | | Slab<T>* slab_; |
90 | | |
91 | | // A list has one Slab pointer which we need to follow. |
92 | 905 | static constexpr uint32_t field_mask() { |
93 | 905 | return maskbit(offsetof(List, slab_)); |
94 | 905 | } _ZN4ListIP6BigStrE10field_maskEv Line | Count | Source | 92 | 136 | static constexpr uint32_t field_mask() { | 93 | 136 | return maskbit(offsetof(List, slab_)); | 94 | 136 | } |
_ZN4ListIiE10field_maskEv Line | Count | Source | 92 | 677 | static constexpr uint32_t field_mask() { | 93 | 677 | return maskbit(offsetof(List, slab_)); | 94 | 677 | } |
_ZN4ListIP6Tuple2IP6BigStriEE10field_maskEv Line | Count | Source | 92 | 1 | static constexpr uint32_t field_mask() { | 93 | 1 | return maskbit(offsetof(List, slab_)); | 94 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE10field_maskEv Line | Count | Source | 92 | 5 | static constexpr uint32_t field_mask() { | 93 | 5 | return maskbit(offsetof(List, slab_)); | 94 | 5 | } |
_ZN4ListIPN10hnode_asdl5FieldEE10field_maskEv Line | Count | Source | 92 | 37 | static constexpr uint32_t field_mask() { | 93 | 37 | return maskbit(offsetof(List, slab_)); | 94 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv Line | Count | Source | 92 | 37 | static constexpr uint32_t field_mask() { | 93 | 37 | return maskbit(offsetof(List, slab_)); | 94 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7y_lhs_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10place_op_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13ComprehensionEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NamedArgEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9EggexFlagEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10field_maskEv _ZN4ListIbE10field_maskEv Line | Count | Source | 92 | 3 | static constexpr uint32_t field_mask() { | 93 | 3 | return maskbit(offsetof(List, slab_)); | 94 | 3 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10field_maskEv _ZN4ListIP6Tuple2IiiEE10field_maskEv Line | Count | Source | 92 | 4 | static constexpr uint32_t field_mask() { | 93 | 4 | return maskbit(offsetof(List, slab_)); | 94 | 4 | } |
_ZN4ListIPiE10field_maskEv Line | Count | Source | 92 | 2 | static constexpr uint32_t field_mask() { | 93 | 2 | return maskbit(offsetof(List, slab_)); | 94 | 2 | } |
_ZN4ListIdE10field_maskEv Line | Count | Source | 92 | 2 | static constexpr uint32_t field_mask() { | 93 | 2 | return maskbit(offsetof(List, slab_)); | 94 | 2 | } |
_ZN4ListIPN4pyos11PasswdEntryEE10field_maskEv Line | Count | Source | 92 | 1 | static constexpr uint32_t field_mask() { | 93 | 1 | return maskbit(offsetof(List, slab_)); | 94 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10field_maskEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE10field_maskEv |
95 | | |
96 | | DISALLOW_COPY_AND_ASSIGN(List) |
97 | | |
98 | | static_assert(sizeof(ObjHeader) % sizeof(T) == 0, |
99 | | "ObjHeader size should be multiple of item size"); |
100 | | static constexpr int kHeaderFudge = sizeof(ObjHeader) / sizeof(T); |
101 | | |
102 | | #if 0 |
103 | | // 24-byte pool comes from very common List header, and Token |
104 | | static constexpr int kPoolBytes1 = 24 - sizeof(ObjHeader); |
105 | | static_assert(kPoolBytes1 % sizeof(T) == 0, |
106 | | "An integral number of items should fit in first pool"); |
107 | | static constexpr int kNumItems1 = kPoolBytes1 / sizeof(T); |
108 | | #endif |
109 | | |
110 | | // Matches mark_sweep_heap.h |
111 | | static constexpr int kPoolBytes2 = 48 - sizeof(ObjHeader); |
112 | | static_assert(kPoolBytes2 % sizeof(T) == 0, |
113 | | "An integral number of items should fit in second pool"); |
114 | | static constexpr int kNumItems2 = kPoolBytes2 / sizeof(T); |
115 | | |
116 | | #if 0 |
117 | | static constexpr int kMinBytes2 = 128 - sizeof(ObjHeader); |
118 | | static_assert(kMinBytes2 % sizeof(T) == 0, |
119 | | "An integral number of items should fit"); |
120 | | static constexpr int kMinItems2 = kMinBytes2 / sizeof(T); |
121 | | #endif |
122 | | |
123 | | // Given the number of items desired, return the number items we should |
124 | | // reserve room for, according to our growth policy. |
125 | 924 | int HowManyItems(int num_desired) { |
126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So |
127 | | // just use the larger 48 byte pool. |
128 | | #if 0 |
129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 |
130 | | return kNumItems1; |
131 | | } |
132 | | #endif |
133 | 924 | if (num_desired <= kNumItems2) { // use full cell in pool 2 |
134 | 846 | return kNumItems2; |
135 | 846 | } |
136 | | #if 0 |
137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 |
138 | | return kMinItems2; |
139 | | } |
140 | | #endif |
141 | | |
142 | | // Make sure the total allocation is a power of 2. TODO: consider using |
143 | | // slightly less than power of 2, to account for malloc() headers, and |
144 | | // reduce fragmentation. |
145 | | // Example: |
146 | | // - ask for 11 integers |
147 | | // - round up 11+2 == 13 up to 16 items |
148 | | // - return 14 items |
149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. |
150 | 78 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; |
151 | 924 | } _ZN4ListIP6BigStrE12HowManyItemsEi Line | Count | Source | 125 | 155 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 155 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 118 | return kNumItems2; | 135 | 118 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 37 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 155 | } |
_ZN4ListIiE12HowManyItemsEi Line | Count | Source | 125 | 709 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 709 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 673 | return kNumItems2; | 135 | 673 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 36 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 709 | } |
_ZN4ListIP6Tuple2IP6BigStriEE12HowManyItemsEi Line | Count | Source | 125 | 1 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 1 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 1 | return kNumItems2; | 135 | 1 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE12HowManyItemsEi Line | Count | Source | 125 | 7 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 7 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 7 | return kNumItems2; | 135 | 7 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 7 | } |
_ZN4ListIPN10hnode_asdl5FieldEE12HowManyItemsEi Line | Count | Source | 125 | 37 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 37 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 37 | return kNumItems2; | 135 | 37 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE12HowManyItemsEi _ZN4ListIbE12HowManyItemsEi Line | Count | Source | 125 | 3 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 3 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 3 | return kNumItems2; | 135 | 3 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 3 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE12HowManyItemsEi _ZN4ListIP6Tuple2IiiEE12HowManyItemsEi Line | Count | Source | 125 | 4 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 4 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 4 | return kNumItems2; | 135 | 4 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 4 | } |
_ZN4ListIdE12HowManyItemsEi Line | Count | Source | 125 | 2 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 2 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 2 | return kNumItems2; | 135 | 2 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 2 | } |
_ZN4ListIPN4pyos11PasswdEntryEE12HowManyItemsEi Line | Count | Source | 125 | 6 | int HowManyItems(int num_desired) { | 126 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 127 | | // just use the larger 48 byte pool. | 128 | | #if 0 | 129 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 130 | | return kNumItems1; | 131 | | } | 132 | | #endif | 133 | 6 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 134 | 1 | return kNumItems2; | 135 | 1 | } | 136 | | #if 0 | 137 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 138 | | return kMinItems2; | 139 | | } | 140 | | #endif | 141 | | | 142 | | // Make sure the total allocation is a power of 2. TODO: consider using | 143 | | // slightly less than power of 2, to account for malloc() headers, and | 144 | | // reduce fragmentation. | 145 | | // Example: | 146 | | // - ask for 11 integers | 147 | | // - round up 11+2 == 13 up to 16 items | 148 | | // - return 14 items | 149 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 150 | 5 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 151 | 6 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE12HowManyItemsEi |
152 | | }; |
153 | | |
154 | | // "Constructors" as free functions since we can't allocate within a |
155 | | // constructor. Allocation may cause garbage collection, which interferes with |
156 | | // placement new. |
157 | | |
158 | | // This is not really necessary, only syntactic sugar. |
159 | | template <typename T> |
160 | 662 | List<T>* NewList() { |
161 | 662 | return Alloc<List<T>>(); |
162 | 662 | } _Z7NewListIP6BigStrEP4ListIT_Ev Line | Count | Source | 160 | 28 | List<T>* NewList() { | 161 | 28 | return Alloc<List<T>>(); | 162 | 28 | } |
Line | Count | Source | 160 | 628 | List<T>* NewList() { | 161 | 628 | return Alloc<List<T>>(); | 162 | 628 | } |
_Z7NewListIPiEP4ListIT_Ev Line | Count | Source | 160 | 2 | List<T>* NewList() { | 161 | 2 | return Alloc<List<T>>(); | 162 | 2 | } |
_Z7NewListIPN4pyos11PasswdEntryEEP4ListIT_Ev Line | Count | Source | 160 | 1 | List<T>* NewList() { | 161 | 1 | return Alloc<List<T>>(); | 162 | 1 | } |
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12CompoundWordEEP4ListIT_Ev _Z7NewListIP6Tuple2IiP6BigStrEEP4ListIT_Ev Line | Count | Source | 160 | 3 | List<T>* NewList() { | 161 | 3 | return Alloc<List<T>>(); | 162 | 3 | } |
|
163 | | |
164 | | // Literal ['foo', 'bar'] |
165 | | // This seems to allow better template argument type deduction than a |
166 | | // constructor. |
167 | | template <typename T> |
168 | 96 | List<T>* NewList(std::initializer_list<T> init) { |
169 | 96 | auto self = Alloc<List<T>>(); |
170 | | |
171 | 96 | int n = init.size(); |
172 | 96 | self->reserve(n); |
173 | | |
174 | 96 | int i = 0; |
175 | 200 | for (auto item : init) { |
176 | 200 | self->set(i, item); |
177 | 200 | ++i; |
178 | 200 | } |
179 | 96 | self->len_ = n; |
180 | 96 | return self; |
181 | 96 | } _Z7NewListIP6BigStrEP4ListIT_ESt16initializer_listIS3_E Line | Count | Source | 168 | 61 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 61 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 61 | int n = init.size(); | 172 | 61 | self->reserve(n); | 173 | | | 174 | 61 | int i = 0; | 175 | 69 | for (auto item : init) { | 176 | 69 | self->set(i, item); | 177 | 69 | ++i; | 178 | 69 | } | 179 | 61 | self->len_ = n; | 180 | 61 | return self; | 181 | 61 | } |
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 168 | 30 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 30 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 30 | int n = init.size(); | 172 | 30 | self->reserve(n); | 173 | | | 174 | 30 | int i = 0; | 175 | 119 | for (auto item : init) { | 176 | 119 | self->set(i, item); | 177 | 119 | ++i; | 178 | 119 | } | 179 | 30 | self->len_ = n; | 180 | 30 | return self; | 181 | 30 | } |
_Z7NewListIP6Tuple2IP6BigStriEEP4ListIT_ESt16initializer_listIS6_E Line | Count | Source | 168 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 1 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 1 | int n = init.size(); | 172 | 1 | self->reserve(n); | 173 | | | 174 | 1 | int i = 0; | 175 | 2 | for (auto item : init) { | 176 | 2 | self->set(i, item); | 177 | 2 | ++i; | 178 | 2 | } | 179 | 1 | self->len_ = n; | 180 | 1 | return self; | 181 | 1 | } |
_Z7NewListIP6Tuple2IiP6BigStrEEP4ListIT_ESt16initializer_listIS6_E Line | Count | Source | 168 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 1 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 1 | int n = init.size(); | 172 | 1 | self->reserve(n); | 173 | | | 174 | 1 | int i = 0; | 175 | 2 | for (auto item : init) { | 176 | 2 | self->set(i, item); | 177 | 2 | ++i; | 178 | 2 | } | 179 | 1 | self->len_ = n; | 180 | 1 | return self; | 181 | 1 | } |
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E _Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 168 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 1 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 1 | int n = init.size(); | 172 | 1 | self->reserve(n); | 173 | | | 174 | 1 | int i = 0; | 175 | 2 | for (auto item : init) { | 176 | 2 | self->set(i, item); | 177 | 2 | ++i; | 178 | 2 | } | 179 | 1 | self->len_ = n; | 180 | 1 | return self; | 181 | 1 | } |
_Z7NewListIdEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 168 | 2 | List<T>* NewList(std::initializer_list<T> init) { | 169 | 2 | auto self = Alloc<List<T>>(); | 170 | | | 171 | 2 | int n = init.size(); | 172 | 2 | self->reserve(n); | 173 | | | 174 | 2 | int i = 0; | 175 | 6 | for (auto item : init) { | 176 | 6 | self->set(i, item); | 177 | 6 | ++i; | 178 | 6 | } | 179 | 2 | self->len_ = n; | 180 | 2 | return self; | 181 | 2 | } |
Unexecuted instantiation: _Z7NewListIP6Tuple2IiiEEP4ListIT_ESt16initializer_listIS4_E |
182 | | |
183 | | // ['foo'] * 3 |
184 | | template <typename T> |
185 | 9 | List<T>* NewList(T item, int times) { |
186 | 9 | auto self = Alloc<List<T>>(); |
187 | | |
188 | 9 | self->reserve(times); |
189 | 9 | self->len_ = times; |
190 | 36 | for (int i = 0; i < times; ++i) { |
191 | 27 | self->set(i, item); |
192 | 27 | } |
193 | 9 | return self; |
194 | 9 | } _Z7NewListIP6BigStrEP4ListIT_ES3_i Line | Count | Source | 185 | 3 | List<T>* NewList(T item, int times) { | 186 | 3 | auto self = Alloc<List<T>>(); | 187 | | | 188 | 3 | self->reserve(times); | 189 | 3 | self->len_ = times; | 190 | 12 | for (int i = 0; i < times; ++i) { | 191 | 9 | self->set(i, item); | 192 | 9 | } | 193 | 3 | return self; | 194 | 3 | } |
_Z7NewListIbEP4ListIT_ES1_i Line | Count | Source | 185 | 2 | List<T>* NewList(T item, int times) { | 186 | 2 | auto self = Alloc<List<T>>(); | 187 | | | 188 | 2 | self->reserve(times); | 189 | 2 | self->len_ = times; | 190 | 8 | for (int i = 0; i < times; ++i) { | 191 | 6 | self->set(i, item); | 192 | 6 | } | 193 | 2 | return self; | 194 | 2 | } |
_Z7NewListIiEP4ListIT_ES1_i Line | Count | Source | 185 | 4 | List<T>* NewList(T item, int times) { | 186 | 4 | auto self = Alloc<List<T>>(); | 187 | | | 188 | 4 | self->reserve(times); | 189 | 4 | self->len_ = times; | 190 | 16 | for (int i = 0; i < times; ++i) { | 191 | 12 | self->set(i, item); | 192 | 12 | } | 193 | 4 | return self; | 194 | 4 | } |
|
195 | | |
196 | | template <typename T> |
197 | 4.86k | void List<T>::append(T item) { |
198 | 4.86k | reserve(len_ + 1); |
199 | 4.86k | slab_->items_[len_] = item; |
200 | 4.86k | ++len_; |
201 | 4.86k | } _ZN4ListIP6BigStrE6appendES1_ Line | Count | Source | 197 | 624 | void List<T>::append(T item) { | 198 | 624 | reserve(len_ + 1); | 199 | 624 | slab_->items_[len_] = item; | 200 | 624 | ++len_; | 201 | 624 | } |
Line | Count | Source | 197 | 4.06k | void List<T>::append(T item) { | 198 | 4.06k | reserve(len_ + 1); | 199 | 4.06k | slab_->items_[len_] = item; | 200 | 4.06k | ++len_; | 201 | 4.06k | } |
Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE6appendES4_ _ZN4ListIPN10hnode_asdl5FieldEE6appendES2_ Line | Count | Source | 197 | 65 | void List<T>::append(T item) { | 198 | 65 | reserve(len_ + 1); | 199 | 65 | slab_->items_[len_] = item; | 200 | 65 | ++len_; | 201 | 65 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE6appendES2_ _ZN4ListIP6Tuple2IiP6BigStrEE6appendES4_ Line | Count | Source | 197 | 20 | void List<T>::append(T item) { | 198 | 20 | reserve(len_ + 1); | 199 | 20 | slab_->items_[len_] = item; | 200 | 20 | ++len_; | 201 | 20 | } |
_ZN4ListIP6Tuple2IiiEE6appendES2_ Line | Count | Source | 197 | 8 | void List<T>::append(T item) { | 198 | 8 | reserve(len_ + 1); | 199 | 8 | slab_->items_[len_] = item; | 200 | 8 | ++len_; | 201 | 8 | } |
_ZN4ListIPN4pyos11PasswdEntryEE6appendES2_ Line | Count | Source | 197 | 76 | void List<T>::append(T item) { | 198 | 76 | reserve(len_ + 1); | 199 | 76 | slab_->items_[len_] = item; | 200 | 76 | ++len_; | 201 | 76 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE6appendES4_ Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE6appendES4_ |
202 | | |
203 | | template <typename T> |
204 | 4.19k | int len(const List<T>* L) { |
205 | 4.19k | return L->len_; |
206 | 4.19k | } Line | Count | Source | 204 | 3.97k | int len(const List<T>* L) { | 205 | 3.97k | return L->len_; | 206 | 3.97k | } |
_Z3lenIP6BigStrEiPK4ListIT_E Line | Count | Source | 204 | 199 | int len(const List<T>* L) { | 205 | 199 | return L->len_; | 206 | 199 | } |
Unexecuted instantiation: _Z3lenIPN15test_classes_gc10OpaqueBaseEEiPK4ListIT_E Unexecuted instantiation: _Z3lenIPN15test_classes_gc12PointersBaseEEiPK4ListIT_E Unexecuted instantiation: _Z3lenIPN15test_classes_gc14BaseWithMethodEEiPK4ListIT_E _Z3lenIP6Tuple2IiP6BigStrEEiPK4ListIT_E Line | Count | Source | 204 | 7 | int len(const List<T>* L) { | 205 | 7 | return L->len_; | 206 | 7 | } |
_Z3lenIP6Tuple2IiiEEiPK4ListIT_E Line | Count | Source | 204 | 4 | int len(const List<T>* L) { | 205 | 4 | return L->len_; | 206 | 4 | } |
Line | Count | Source | 204 | 2 | int len(const List<T>* L) { | 205 | 2 | return L->len_; | 206 | 2 | } |
Line | Count | Source | 204 | 4 | int len(const List<T>* L) { | 205 | 4 | return L->len_; | 206 | 4 | } |
_Z3lenIPN4pyos11PasswdEntryEEiPK4ListIT_E Line | Count | Source | 204 | 1 | int len(const List<T>* L) { | 205 | 1 | return L->len_; | 206 | 1 | } |
|
207 | | |
208 | | template <typename T> |
209 | | List<T>* list_repeat(T item, int times); |
210 | | |
211 | | template <typename T> |
212 | | inline bool list_contains(List<T>* haystack, T needle); |
213 | | |
214 | | template <typename K, typename V> |
215 | | class Dict; // forward decl |
216 | | |
217 | | template <typename V> |
218 | | List<BigStr*>* sorted(Dict<BigStr*, V>* d); |
219 | | |
220 | | template <typename T> |
221 | | List<T>* sorted(List<T>* l); |
222 | | |
223 | | // L[begin:] |
224 | | template <typename T> |
225 | 606 | List<T>* List<T>::slice(int begin) { |
226 | 606 | return slice(begin, len_); |
227 | 606 | } _ZN4ListIP6BigStrE5sliceEi Line | Count | Source | 225 | 3 | List<T>* List<T>::slice(int begin) { | 226 | 3 | return slice(begin, len_); | 227 | 3 | } |
Line | Count | Source | 225 | 603 | List<T>* List<T>::slice(int begin) { | 226 | 603 | return slice(begin, len_); | 227 | 603 | } |
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE5sliceEi |
228 | | |
229 | | // L[begin:end] |
230 | | template <typename T> |
231 | 611 | List<T>* List<T>::slice(int begin, int end) { |
232 | 611 | SLICE_ADJUST(begin, end, len_); |
233 | | |
234 | 611 | DCHECK(0 <= begin && begin <= len_); |
235 | 611 | DCHECK(0 <= end && end <= len_); |
236 | | |
237 | 0 | int new_len = end - begin; |
238 | 611 | DCHECK(0 <= new_len && new_len <= len_); |
239 | | |
240 | 0 | List<T>* result = NewList<T>(); |
241 | 611 | result->reserve(new_len); |
242 | | |
243 | | // Faster than append() in a loop |
244 | 611 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); |
245 | 611 | result->len_ = new_len; |
246 | | |
247 | 611 | return result; |
248 | 611 | } _ZN4ListIP6BigStrE5sliceEii Line | Count | Source | 231 | 3 | List<T>* List<T>::slice(int begin, int end) { | 232 | 3 | SLICE_ADJUST(begin, end, len_); | 233 | | | 234 | 3 | DCHECK(0 <= begin && begin <= len_); | 235 | 3 | DCHECK(0 <= end && end <= len_); | 236 | | | 237 | 0 | int new_len = end - begin; | 238 | 3 | DCHECK(0 <= new_len && new_len <= len_); | 239 | | | 240 | 0 | List<T>* result = NewList<T>(); | 241 | 3 | result->reserve(new_len); | 242 | | | 243 | | // Faster than append() in a loop | 244 | 3 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); | 245 | 3 | result->len_ = new_len; | 246 | | | 247 | 3 | return result; | 248 | 3 | } |
Line | Count | Source | 231 | 608 | List<T>* List<T>::slice(int begin, int end) { | 232 | 608 | SLICE_ADJUST(begin, end, len_); | 233 | | | 234 | 608 | DCHECK(0 <= begin && begin <= len_); | 235 | 608 | DCHECK(0 <= end && end <= len_); | 236 | | | 237 | 0 | int new_len = end - begin; | 238 | 608 | DCHECK(0 <= new_len && new_len <= len_); | 239 | | | 240 | 0 | List<T>* result = NewList<T>(); | 241 | 608 | result->reserve(new_len); | 242 | | | 243 | | // Faster than append() in a loop | 244 | 608 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); | 245 | 608 | result->len_ = new_len; | 246 | | | 247 | 608 | return result; | 248 | 608 | } |
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE5sliceEii |
249 | | |
250 | | // Ensure that there's space for a number of items |
251 | | template <typename T> |
252 | 5.61k | void List<T>::reserve(int num_desired) { |
253 | | // log("reserve capacity = %d, n = %d", capacity_, n); |
254 | | |
255 | | // Don't do anything if there's already enough space. |
256 | 5.61k | if (capacity_ >= num_desired) { |
257 | 4.69k | return; |
258 | 4.69k | } |
259 | | |
260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of |
261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for |
262 | | // List<int>. |
263 | | // |
264 | | // Example: the user reserves space for 3 integers. The minimum number of |
265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, |
266 | | // which leads to 8 + 6*4 = 32 byte Slab. |
267 | | |
268 | 924 | capacity_ = HowManyItems(num_desired); |
269 | 924 | auto new_slab = NewSlab<T>(capacity_); |
270 | | |
271 | 924 | if (len_ > 0) { |
272 | | // log("Copying %d bytes", len_ * sizeof(T)); |
273 | 65 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); |
274 | 65 | } |
275 | 924 | slab_ = new_slab; |
276 | 924 | } _ZN4ListIP6BigStrE7reserveEi Line | Count | Source | 252 | 705 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 705 | if (capacity_ >= num_desired) { | 257 | 550 | return; | 258 | 550 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 155 | capacity_ = HowManyItems(num_desired); | 269 | 155 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 155 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 34 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 34 | } | 275 | 155 | slab_ = new_slab; | 276 | 155 | } |
Line | Count | Source | 252 | 4.73k | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 4.73k | if (capacity_ >= num_desired) { | 257 | 4.02k | return; | 258 | 4.02k | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 709 | capacity_ = HowManyItems(num_desired); | 269 | 709 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 709 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 26 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 26 | } | 275 | 709 | slab_ = new_slab; | 276 | 709 | } |
_ZN4ListIP6Tuple2IP6BigStriEE7reserveEi Line | Count | Source | 252 | 1 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 1 | if (capacity_ >= num_desired) { | 257 | 0 | return; | 258 | 0 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 1 | capacity_ = HowManyItems(num_desired); | 269 | 1 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 1 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 1 | slab_ = new_slab; | 276 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE7reserveEi Line | Count | Source | 252 | 21 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 21 | if (capacity_ >= num_desired) { | 257 | 14 | return; | 258 | 14 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 7 | capacity_ = HowManyItems(num_desired); | 269 | 7 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 7 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 7 | slab_ = new_slab; | 276 | 7 | } |
_ZN4ListIPN10hnode_asdl5FieldEE7reserveEi Line | Count | Source | 252 | 65 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 65 | if (capacity_ >= num_desired) { | 257 | 28 | return; | 258 | 28 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 37 | capacity_ = HowManyItems(num_desired); | 269 | 37 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 37 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 37 | slab_ = new_slab; | 276 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi Line | Count | Source | 252 | 3 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 3 | if (capacity_ >= num_desired) { | 257 | 0 | return; | 258 | 0 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 3 | capacity_ = HowManyItems(num_desired); | 269 | 3 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 3 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 3 | slab_ = new_slab; | 276 | 3 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE7reserveEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE7reserveEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE7reserveEi _ZN4ListIP6Tuple2IiiEE7reserveEi Line | Count | Source | 252 | 8 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 8 | if (capacity_ >= num_desired) { | 257 | 4 | return; | 258 | 4 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 4 | capacity_ = HowManyItems(num_desired); | 269 | 4 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 4 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 4 | slab_ = new_slab; | 276 | 4 | } |
Line | Count | Source | 252 | 2 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 2 | if (capacity_ >= num_desired) { | 257 | 0 | return; | 258 | 0 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 2 | capacity_ = HowManyItems(num_desired); | 269 | 2 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 2 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 0 | } | 275 | 2 | slab_ = new_slab; | 276 | 2 | } |
_ZN4ListIPN4pyos11PasswdEntryEE7reserveEi Line | Count | Source | 252 | 76 | void List<T>::reserve(int num_desired) { | 253 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 254 | | | 255 | | // Don't do anything if there's already enough space. | 256 | 76 | if (capacity_ >= num_desired) { | 257 | 70 | return; | 258 | 70 | } | 259 | | | 260 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 261 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 262 | | // List<int>. | 263 | | // | 264 | | // Example: the user reserves space for 3 integers. The minimum number of | 265 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 266 | | // which leads to 8 + 6*4 = 32 byte Slab. | 267 | | | 268 | 6 | capacity_ = HowManyItems(num_desired); | 269 | 6 | auto new_slab = NewSlab<T>(capacity_); | 270 | | | 271 | 6 | if (len_ > 0) { | 272 | | // log("Copying %d bytes", len_ * sizeof(T)); | 273 | 5 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 274 | 5 | } | 275 | 6 | slab_ = new_slab; | 276 | 6 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE7reserveEi Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE7reserveEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE7reserveEi |
277 | | |
278 | | // Implements L[i] = item |
279 | | template <typename T> |
280 | 279 | void List<T>::set(int i, T item) { |
281 | 279 | if (i < 0) { |
282 | 0 | i = len_ + i; |
283 | 0 | } |
284 | | |
285 | 279 | DCHECK(i >= 0); |
286 | 279 | DCHECK(i < capacity_); |
287 | | |
288 | 0 | slab_->items_[i] = item; |
289 | 279 | } _ZN4ListIP6BigStrE3setEiS1_ Line | Count | Source | 280 | 90 | void List<T>::set(int i, T item) { | 281 | 90 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 90 | DCHECK(i >= 0); | 286 | 90 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 90 | } |
Line | Count | Source | 280 | 171 | void List<T>::set(int i, T item) { | 281 | 171 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 171 | DCHECK(i >= 0); | 286 | 171 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 171 | } |
_ZN4ListIP6Tuple2IP6BigStriEE3setEiS4_ Line | Count | Source | 280 | 2 | void List<T>::set(int i, T item) { | 281 | 2 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 2 | DCHECK(i >= 0); | 286 | 2 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 2 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE3setEiS4_ Line | Count | Source | 280 | 2 | void List<T>::set(int i, T item) { | 281 | 2 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 2 | DCHECK(i >= 0); | 286 | 2 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 2 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_ Line | Count | Source | 280 | 8 | void List<T>::set(int i, T item) { | 281 | 8 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 8 | DCHECK(i >= 0); | 286 | 8 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 8 | } |
Line | Count | Source | 280 | 6 | void List<T>::set(int i, T item) { | 281 | 6 | if (i < 0) { | 282 | 0 | i = len_ + i; | 283 | 0 | } | 284 | | | 285 | 6 | DCHECK(i >= 0); | 286 | 6 | DCHECK(i < capacity_); | 287 | | | 288 | 0 | slab_->items_[i] = item; | 289 | 6 | } |
Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE3setEiS2_ |
290 | | |
291 | | // Implements L[i] |
292 | | template <typename T> |
293 | 1.70k | T List<T>::at(int i) { |
294 | 1.70k | if (i < 0) { |
295 | 4 | int j = len_ + i; |
296 | 4 | if (j >= len_ || j < 0) { |
297 | 0 | throw Alloc<IndexError>(); |
298 | 0 | } |
299 | 4 | return slab_->items_[j]; |
300 | 4 | } |
301 | | |
302 | 1.69k | if (i >= len_ || i < 0) { |
303 | 0 | throw Alloc<IndexError>(); |
304 | 0 | } |
305 | 1.69k | return slab_->items_[i]; |
306 | 1.69k | } Line | Count | Source | 293 | 554 | T List<T>::at(int i) { | 294 | 554 | if (i < 0) { | 295 | 1 | int j = len_ + i; | 296 | 1 | if (j >= len_ || j < 0) { | 297 | 0 | throw Alloc<IndexError>(); | 298 | 0 | } | 299 | 1 | return slab_->items_[j]; | 300 | 1 | } | 301 | | | 302 | 553 | if (i >= len_ || i < 0) { | 303 | 0 | throw Alloc<IndexError>(); | 304 | 0 | } | 305 | 553 | return slab_->items_[i]; | 306 | 553 | } |
Line | Count | Source | 293 | 1.13k | T List<T>::at(int i) { | 294 | 1.13k | if (i < 0) { | 295 | 3 | int j = len_ + i; | 296 | 3 | if (j >= len_ || j < 0) { | 297 | 0 | throw Alloc<IndexError>(); | 298 | 0 | } | 299 | 3 | return slab_->items_[j]; | 300 | 3 | } | 301 | | | 302 | 1.12k | if (i >= len_ || i < 0) { | 303 | 0 | throw Alloc<IndexError>(); | 304 | 0 | } | 305 | 1.12k | return slab_->items_[i]; | 306 | 1.12k | } |
Line | Count | Source | 293 | 4 | T List<T>::at(int i) { | 294 | 4 | if (i < 0) { | 295 | 0 | int j = len_ + i; | 296 | 0 | if (j >= len_ || j < 0) { | 297 | 0 | throw Alloc<IndexError>(); | 298 | 0 | } | 299 | 0 | return slab_->items_[j]; | 300 | 0 | } | 301 | | | 302 | 4 | if (i >= len_ || i < 0) { | 303 | 0 | throw Alloc<IndexError>(); | 304 | 0 | } | 305 | 4 | return slab_->items_[i]; | 306 | 4 | } |
Line | Count | Source | 293 | 8 | T List<T>::at(int i) { | 294 | 8 | if (i < 0) { | 295 | 0 | int j = len_ + i; | 296 | 0 | if (j >= len_ || j < 0) { | 297 | 0 | throw Alloc<IndexError>(); | 298 | 0 | } | 299 | 0 | return slab_->items_[j]; | 300 | 0 | } | 301 | | | 302 | 8 | if (i >= len_ || i < 0) { | 303 | 0 | throw Alloc<IndexError>(); | 304 | 0 | } | 305 | 8 | return slab_->items_[i]; | 306 | 8 | } |
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE2atEi _ZN4ListIP6Tuple2IiP6BigStrEE2atEi Line | Count | Source | 293 | 5 | T List<T>::at(int i) { | 294 | 5 | if (i < 0) { | 295 | 0 | int j = len_ + i; | 296 | 0 | if (j >= len_ || j < 0) { | 297 | 0 | throw Alloc<IndexError>(); | 298 | 0 | } | 299 | 0 | return slab_->items_[j]; | 300 | 0 | } | 301 | | | 302 | 5 | if (i >= len_ || i < 0) { | 303 | 0 | throw Alloc<IndexError>(); | 304 | 0 | } | 305 | 5 | return slab_->items_[i]; | 306 | 5 | } |
|
307 | | |
308 | | // L.index(i) -- Python method |
309 | | template <typename T> |
310 | 8 | int List<T>::index(T value) { |
311 | 8 | int element_count = len(this); |
312 | 18 | for (int i = 0; i < element_count; i++) { |
313 | 16 | if (are_equal(slab_->items_[i], value)) { |
314 | 6 | return i; |
315 | 6 | } |
316 | 16 | } |
317 | 2 | throw Alloc<ValueError>(); |
318 | 8 | } |
319 | | |
320 | | // Should we have a separate API that doesn't return it? |
321 | | // https://stackoverflow.com/questions/12600330/pop-back-return-value |
322 | | template <typename T> |
323 | 7 | T List<T>::pop() { |
324 | 7 | if (len_ == 0) { |
325 | 0 | throw Alloc<IndexError>(); |
326 | 0 | } |
327 | 7 | len_--; |
328 | 7 | T result = slab_->items_[len_]; |
329 | 7 | slab_->items_[len_] = 0; // zero for GC scan |
330 | 7 | return result; |
331 | 7 | } Line | Count | Source | 323 | 5 | T List<T>::pop() { | 324 | 5 | if (len_ == 0) { | 325 | 0 | throw Alloc<IndexError>(); | 326 | 0 | } | 327 | 5 | len_--; | 328 | 5 | T result = slab_->items_[len_]; | 329 | 5 | slab_->items_[len_] = 0; // zero for GC scan | 330 | 5 | return result; | 331 | 5 | } |
Line | Count | Source | 323 | 2 | T List<T>::pop() { | 324 | 2 | if (len_ == 0) { | 325 | 0 | throw Alloc<IndexError>(); | 326 | 0 | } | 327 | 2 | len_--; | 328 | 2 | T result = slab_->items_[len_]; | 329 | 2 | slab_->items_[len_] = 0; // zero for GC scan | 330 | 2 | return result; | 331 | 2 | } |
|
332 | | |
333 | | // Used in osh/word_parse.py to remove from front |
334 | | template <typename T> |
335 | 10 | T List<T>::pop(int i) { |
336 | 10 | if (len_ < i) { |
337 | 0 | throw Alloc<IndexError>(); |
338 | 0 | } |
339 | | |
340 | 10 | T result = at(i); |
341 | 10 | len_--; |
342 | | |
343 | | // Shift everything by one |
344 | 10 | memmove(slab_->items_ + i, slab_->items_ + (i + 1), len_ * sizeof(T)); |
345 | | |
346 | | /* |
347 | | for (int j = 0; j < len_; j++) { |
348 | | slab_->items_[j] = slab_->items_[j+1]; |
349 | | } |
350 | | */ |
351 | | |
352 | 10 | slab_->items_[len_] = 0; // zero for GC scan |
353 | 10 | return result; |
354 | 10 | } |
355 | | |
356 | | template <typename T> |
357 | 6 | void List<T>::remove(T x) { |
358 | 6 | int idx = this->index(x); |
359 | 6 | this->pop(idx); // unused |
360 | 6 | } |
361 | | |
362 | | template <typename T> |
363 | 7 | void List<T>::clear() { |
364 | 7 | if (slab_) { |
365 | 4 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan |
366 | 4 | } |
367 | 7 | len_ = 0; |
368 | 7 | } Line | Count | Source | 363 | 4 | void List<T>::clear() { | 364 | 4 | if (slab_) { | 365 | 4 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan | 366 | 4 | } | 367 | 4 | len_ = 0; | 368 | 4 | } |
_ZN4ListIP6BigStrE5clearEv Line | Count | Source | 363 | 1 | void List<T>::clear() { | 364 | 1 | if (slab_) { | 365 | 0 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan | 366 | 0 | } | 367 | 1 | len_ = 0; | 368 | 1 | } |
Line | Count | Source | 363 | 2 | void List<T>::clear() { | 364 | 2 | if (slab_) { | 365 | 0 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan | 366 | 0 | } | 367 | 2 | len_ = 0; | 368 | 2 | } |
|
369 | | |
370 | | // Used in osh/string_ops.py |
371 | | template <typename T> |
372 | 8 | void List<T>::reverse() { |
373 | 16 | for (int i = 0; i < len_ / 2; ++i) { |
374 | | // log("swapping %d and %d", i, n-i); |
375 | 8 | T tmp = slab_->items_[i]; |
376 | 8 | int j = len_ - 1 - i; |
377 | 8 | slab_->items_[i] = slab_->items_[j]; |
378 | 8 | slab_->items_[j] = tmp; |
379 | 8 | } |
380 | 8 | } Unexecuted instantiation: _ZN4ListIP6BigStrE7reverseEv Line | Count | Source | 372 | 8 | void List<T>::reverse() { | 373 | 16 | for (int i = 0; i < len_ / 2; ++i) { | 374 | | // log("swapping %d and %d", i, n-i); | 375 | 8 | T tmp = slab_->items_[i]; | 376 | 8 | int j = len_ - 1 - i; | 377 | 8 | slab_->items_[i] = slab_->items_[j]; | 378 | 8 | slab_->items_[j] = tmp; | 379 | 8 | } | 380 | 8 | } |
|
381 | | |
382 | | // Extend this list with multiple elements. |
383 | | template <typename T> |
384 | 13 | void List<T>::extend(List<T>* other) { |
385 | 13 | int n = other->len_; |
386 | 13 | int new_len = len_ + n; |
387 | 13 | reserve(new_len); |
388 | | |
389 | 54 | for (int i = 0; i < n; ++i) { |
390 | 41 | set(len_ + i, other->slab_->items_[i]); |
391 | 41 | } |
392 | 13 | len_ = new_len; |
393 | 13 | } _ZN4ListIP6BigStrE6extendEPS2_ Line | Count | Source | 384 | 2 | void List<T>::extend(List<T>* other) { | 385 | 2 | int n = other->len_; | 386 | 2 | int new_len = len_ + n; | 387 | 2 | reserve(new_len); | 388 | | | 389 | 8 | for (int i = 0; i < n; ++i) { | 390 | 6 | set(len_ + i, other->slab_->items_[i]); | 391 | 6 | } | 392 | 2 | len_ = new_len; | 393 | 2 | } |
Line | Count | Source | 384 | 11 | void List<T>::extend(List<T>* other) { | 385 | 11 | int n = other->len_; | 386 | 11 | int new_len = len_ + n; | 387 | 11 | reserve(new_len); | 388 | | | 389 | 46 | for (int i = 0; i < n; ++i) { | 390 | 35 | set(len_ + i, other->slab_->items_[i]); | 391 | 35 | } | 392 | 11 | len_ = new_len; | 393 | 11 | } |
|
394 | | |
395 | 34 | inline bool _cmp(BigStr* a, BigStr* b) { |
396 | 34 | return mylib::str_cmp(a, b) < 0; |
397 | 34 | } |
398 | | |
399 | | template <typename T> |
400 | 8 | void List<T>::sort() { |
401 | 8 | std::sort(slab_->items_, slab_->items_ + len_, _cmp); |
402 | 8 | } |
403 | | |
404 | | // TODO: mycpp can just generate the constructor instead? |
405 | | // e.g. [None] * 3 |
406 | | template <typename T> |
407 | 5 | List<T>* list_repeat(T item, int times) { |
408 | 5 | return NewList<T>(item, times); |
409 | 5 | } _Z11list_repeatIP6BigStrEP4ListIT_ES3_i Line | Count | Source | 407 | 3 | List<T>* list_repeat(T item, int times) { | 408 | 3 | return NewList<T>(item, times); | 409 | 3 | } |
_Z11list_repeatIbEP4ListIT_ES1_i Line | Count | Source | 407 | 2 | List<T>* list_repeat(T item, int times) { | 408 | 2 | return NewList<T>(item, times); | 409 | 2 | } |
|
410 | | |
411 | | // e.g. 'a' in ['a', 'b', 'c'] |
412 | | template <typename T> |
413 | 24 | inline bool list_contains(List<T>* haystack, T needle) { |
414 | 24 | int n = len(haystack); |
415 | 57 | for (int i = 0; i < n; ++i) { |
416 | 47 | if (are_equal(haystack->at(i), needle)) { |
417 | 14 | return true; |
418 | 14 | } |
419 | 47 | } |
420 | 10 | return false; |
421 | 24 | } _Z13list_containsIiEbP4ListIT_ES1_ Line | Count | Source | 413 | 8 | inline bool list_contains(List<T>* haystack, T needle) { | 414 | 8 | int n = len(haystack); | 415 | 19 | for (int i = 0; i < n; ++i) { | 416 | 16 | if (are_equal(haystack->at(i), needle)) { | 417 | 5 | return true; | 418 | 5 | } | 419 | 16 | } | 420 | 3 | return false; | 421 | 8 | } |
_Z13list_containsIP6BigStrEbP4ListIT_ES3_ Line | Count | Source | 413 | 12 | inline bool list_contains(List<T>* haystack, T needle) { | 414 | 12 | int n = len(haystack); | 415 | 28 | for (int i = 0; i < n; ++i) { | 416 | 23 | if (are_equal(haystack->at(i), needle)) { | 417 | 7 | return true; | 418 | 7 | } | 419 | 23 | } | 420 | 5 | return false; | 421 | 12 | } |
_Z13list_containsIdEbP4ListIT_ES1_ Line | Count | Source | 413 | 4 | inline bool list_contains(List<T>* haystack, T needle) { | 414 | 4 | int n = len(haystack); | 415 | 10 | for (int i = 0; i < n; ++i) { | 416 | 8 | if (are_equal(haystack->at(i), needle)) { | 417 | 2 | return true; | 418 | 2 | } | 419 | 8 | } | 420 | 2 | return false; | 421 | 4 | } |
|
422 | | |
423 | | template <typename V> |
424 | 2 | List<BigStr*>* sorted(Dict<BigStr*, V>* d) { |
425 | 2 | auto keys = d->keys(); |
426 | 2 | keys->sort(); |
427 | 2 | return keys; |
428 | 2 | } |
429 | | |
430 | | template <typename T> |
431 | 2 | List<T>* sorted(List<T>* l) { |
432 | 2 | auto ret = list(l); |
433 | 2 | ret->sort(); |
434 | 2 | return ret; |
435 | 2 | } |
436 | | |
437 | | // list(L) copies the list |
438 | | template <typename T> |
439 | 7 | List<T>* list(List<T>* other) { |
440 | 7 | auto result = NewList<T>(); |
441 | 7 | result->extend(other); |
442 | 7 | return result; |
443 | 7 | } Line | Count | Source | 439 | 5 | List<T>* list(List<T>* other) { | 440 | 5 | auto result = NewList<T>(); | 441 | 5 | result->extend(other); | 442 | 5 | return result; | 443 | 5 | } |
_Z4listIP6BigStrEP4ListIT_ES5_ Line | Count | Source | 439 | 2 | List<T>* list(List<T>* other) { | 440 | 2 | auto result = NewList<T>(); | 441 | 2 | result->extend(other); | 442 | 2 | return result; | 443 | 2 | } |
|
444 | | |
445 | | template <class T> |
446 | | class ListIter { |
447 | | public: |
448 | 157 | explicit ListIter(List<T>* L) : L_(L), i_(0) { |
449 | | // Cheney only: L_ could be moved during iteration. |
450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); |
451 | 157 | } _ZN8ListIterIP6BigStrEC2EP4ListIS1_E Line | Count | Source | 448 | 40 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 40 | } |
_ZN8ListIterIiEC2EP4ListIiE Line | Count | Source | 448 | 22 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 22 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEEC2EP4ListIS4_E Line | Count | Source | 448 | 1 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 1 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E Line | Count | Source | 448 | 6 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 6 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E _ZN8ListIterIPN10hnode_asdl5FieldEEC2EP4ListIS2_E Line | Count | Source | 448 | 82 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 82 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7y_lhs_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10place_op_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEEC2EP4ListIS2_E _ZN8ListIterIbEC2EP4ListIbE Line | Count | Source | 448 | 1 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 1 | } |
_ZN8ListIterIP6Tuple2IiiEEC2EP4ListIS2_E Line | Count | Source | 448 | 4 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 4 | } |
_ZN8ListIterIPN4pyos11PasswdEntryEEC2EP4ListIS2_E Line | Count | Source | 448 | 1 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 449 | | // Cheney only: L_ could be moved during iteration. | 450 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 451 | 1 | } |
|
452 | | |
453 | 160 | ~ListIter() { |
454 | | // gHeap.PopRoot(); |
455 | 160 | } _ZN8ListIterIP6BigStrED2Ev Line | Count | Source | 453 | 40 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 40 | } |
Line | Count | Source | 453 | 25 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 25 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEED2Ev Line | Count | Source | 453 | 1 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 1 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEED2Ev Line | Count | Source | 453 | 6 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 6 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev _ZN8ListIterIPN10hnode_asdl5FieldEED2Ev Line | Count | Source | 453 | 82 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 82 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEED2Ev Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7y_lhs_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10place_op_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEED2Ev Line | Count | Source | 453 | 1 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 1 | } |
_ZN8ListIterIP6Tuple2IiiEED2Ev Line | Count | Source | 453 | 4 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 4 | } |
_ZN8ListIterIPN4pyos11PasswdEntryEED2Ev Line | Count | Source | 453 | 1 | ~ListIter() { | 454 | | // gHeap.PopRoot(); | 455 | 1 | } |
|
456 | 426 | void Next() { |
457 | 426 | i_++; |
458 | 426 | } _ZN8ListIterIP6BigStrE4NextEv Line | Count | Source | 456 | 148 | void Next() { | 457 | 148 | i_++; | 458 | 148 | } |
Line | Count | Source | 456 | 85 | void Next() { | 457 | 85 | i_++; | 458 | 85 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE4NextEv Line | Count | Source | 456 | 2 | void Next() { | 457 | 2 | i_++; | 458 | 2 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE4NextEv Line | Count | Source | 456 | 18 | void Next() { | 457 | 18 | i_++; | 458 | 18 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv _ZN8ListIterIPN10hnode_asdl5FieldEE4NextEv Line | Count | Source | 456 | 123 | void Next() { | 457 | 123 | i_++; | 458 | 123 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7y_lhs_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10place_op_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4NextEv Line | Count | Source | 456 | 2 | void Next() { | 457 | 2 | i_++; | 458 | 2 | } |
_ZN8ListIterIP6Tuple2IiiEE4NextEv Line | Count | Source | 456 | 8 | void Next() { | 457 | 8 | i_++; | 458 | 8 | } |
_ZN8ListIterIPN4pyos11PasswdEntryEE4NextEv Line | Count | Source | 456 | 40 | void Next() { | 457 | 40 | i_++; | 458 | 40 | } |
|
459 | 580 | bool Done() { |
460 | | // "unsigned size_t was a mistake" |
461 | 580 | return i_ >= static_cast<int>(L_->len_); |
462 | 580 | } _ZN8ListIterIP6BigStrE4DoneEv Line | Count | Source | 459 | 188 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 188 | return i_ >= static_cast<int>(L_->len_); | 462 | 188 | } |
Line | Count | Source | 459 | 104 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 104 | return i_ >= static_cast<int>(L_->len_); | 462 | 104 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE4DoneEv Line | Count | Source | 459 | 3 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 3 | return i_ >= static_cast<int>(L_->len_); | 462 | 3 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE4DoneEv Line | Count | Source | 459 | 24 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 24 | return i_ >= static_cast<int>(L_->len_); | 462 | 24 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv _ZN8ListIterIPN10hnode_asdl5FieldEE4DoneEv Line | Count | Source | 459 | 205 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 205 | return i_ >= static_cast<int>(L_->len_); | 462 | 205 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7y_lhs_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10place_op_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4DoneEv Line | Count | Source | 459 | 3 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 3 | return i_ >= static_cast<int>(L_->len_); | 462 | 3 | } |
_ZN8ListIterIP6Tuple2IiiEE4DoneEv Line | Count | Source | 459 | 12 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 12 | return i_ >= static_cast<int>(L_->len_); | 462 | 12 | } |
_ZN8ListIterIPN4pyos11PasswdEntryEE4DoneEv Line | Count | Source | 459 | 41 | bool Done() { | 460 | | // "unsigned size_t was a mistake" | 461 | 41 | return i_ >= static_cast<int>(L_->len_); | 462 | 41 | } |
|
463 | 446 | T Value() { |
464 | 446 | return L_->slab_->items_[i_]; |
465 | 446 | } _ZN8ListIterIP6BigStrE5ValueEv Line | Count | Source | 463 | 149 | T Value() { | 464 | 149 | return L_->slab_->items_[i_]; | 465 | 149 | } |
Line | Count | Source | 463 | 80 | T Value() { | 464 | 80 | return L_->slab_->items_[i_]; | 465 | 80 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE5ValueEv Line | Count | Source | 463 | 2 | T Value() { | 464 | 2 | return L_->slab_->items_[i_]; | 465 | 2 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE5ValueEv Line | Count | Source | 463 | 10 | T Value() { | 464 | 10 | return L_->slab_->items_[i_]; | 465 | 10 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv _ZN8ListIterIPN10hnode_asdl5FieldEE5ValueEv Line | Count | Source | 463 | 146 | T Value() { | 464 | 146 | return L_->slab_->items_[i_]; | 465 | 146 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7y_lhs_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10place_op_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE5ValueEv Line | Count | Source | 463 | 2 | T Value() { | 464 | 2 | return L_->slab_->items_[i_]; | 465 | 2 | } |
_ZN8ListIterIP6Tuple2IiiEE5ValueEv Line | Count | Source | 463 | 16 | T Value() { | 464 | 16 | return L_->slab_->items_[i_]; | 465 | 16 | } |
_ZN8ListIterIPN4pyos11PasswdEntryEE5ValueEv Line | Count | Source | 463 | 41 | T Value() { | 464 | 41 | return L_->slab_->items_[i_]; | 465 | 41 | } |
|
466 | 16 | T iterNext() { |
467 | 16 | if (Done()) { |
468 | 3 | throw Alloc<StopIteration>(); |
469 | 3 | } |
470 | 13 | T ret = L_->slab_->items_[i_]; |
471 | 13 | Next(); |
472 | 13 | return ret; |
473 | 16 | } _ZN8ListIterIP6Tuple2IiP6BigStrEE8iterNextEv Line | Count | Source | 466 | 10 | T iterNext() { | 467 | 10 | if (Done()) { | 468 | 2 | throw Alloc<StopIteration>(); | 469 | 2 | } | 470 | 8 | T ret = L_->slab_->items_[i_]; | 471 | 8 | Next(); | 472 | 8 | return ret; | 473 | 10 | } |
_ZN8ListIterIiE8iterNextEv Line | Count | Source | 466 | 6 | T iterNext() { | 467 | 6 | if (Done()) { | 468 | 1 | throw Alloc<StopIteration>(); | 469 | 1 | } | 470 | 5 | T ret = L_->slab_->items_[i_]; | 471 | 5 | Next(); | 472 | 5 | return ret; | 473 | 6 | } |
|
474 | | |
475 | | // only for use with generators |
476 | 3 | List<T>* GetList() { |
477 | 3 | return L_; |
478 | 3 | } |
479 | | |
480 | | private: |
481 | | List<T>* L_; |
482 | | int i_; |
483 | | }; |
484 | | |
485 | | // list(it) returns the iterator's backing list |
486 | | template <typename T> |
487 | 3 | List<T>* list(ListIter<T> it) { |
488 | 3 | return list(it.GetList()); |
489 | 3 | } |
490 | | |
491 | | // TODO: Does using pointers rather than indices make this more efficient? |
492 | | template <class T> |
493 | | class ReverseListIter { |
494 | | public: |
495 | 4 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { |
496 | 4 | } _ZN15ReverseListIterIP6BigStrEC2EP4ListIS1_E Line | Count | Source | 495 | 1 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { | 496 | 1 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E Line | Count | Source | 495 | 1 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { | 496 | 1 | } |
_ZN15ReverseListIterIiEC2EP4ListIiE Line | Count | Source | 495 | 2 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { | 496 | 2 | } |
|
497 | 10 | void Next() { |
498 | 10 | i_--; |
499 | 10 | } _ZN15ReverseListIterIP6BigStrE4NextEv Line | Count | Source | 497 | 2 | void Next() { | 498 | 2 | i_--; | 499 | 2 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4NextEv Line | Count | Source | 497 | 2 | void Next() { | 498 | 2 | i_--; | 499 | 2 | } |
_ZN15ReverseListIterIiE4NextEv Line | Count | Source | 497 | 6 | void Next() { | 498 | 6 | i_--; | 499 | 6 | } |
|
500 | 14 | bool Done() { |
501 | 14 | return i_ < 0; |
502 | 14 | } _ZN15ReverseListIterIP6BigStrE4DoneEv Line | Count | Source | 500 | 3 | bool Done() { | 501 | 3 | return i_ < 0; | 502 | 3 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4DoneEv Line | Count | Source | 500 | 3 | bool Done() { | 501 | 3 | return i_ < 0; | 502 | 3 | } |
_ZN15ReverseListIterIiE4DoneEv Line | Count | Source | 500 | 8 | bool Done() { | 501 | 8 | return i_ < 0; | 502 | 8 | } |
|
503 | 10 | T Value() { |
504 | 10 | return L_->slab_->items_[i_]; |
505 | 10 | } _ZN15ReverseListIterIP6BigStrE5ValueEv Line | Count | Source | 503 | 2 | T Value() { | 504 | 2 | return L_->slab_->items_[i_]; | 505 | 2 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE5ValueEv Line | Count | Source | 503 | 2 | T Value() { | 504 | 2 | return L_->slab_->items_[i_]; | 505 | 2 | } |
_ZN15ReverseListIterIiE5ValueEv Line | Count | Source | 503 | 6 | T Value() { | 504 | 6 | return L_->slab_->items_[i_]; | 505 | 6 | } |
|
506 | | |
507 | | private: |
508 | | List<T>* L_; |
509 | | int i_; |
510 | | }; |
511 | | |
512 | | int max(List<int>* elems); |
513 | | |
514 | | #endif // MYCPP_GC_LIST_H |