/home/uke/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_mops.h" // BigInt |
13 | | #include "mycpp/gc_slab.h" |
14 | | |
15 | | // GlobalList is layout-compatible with List (unit tests assert this), and it |
16 | | // can be a true C global (incurs zero startup time) |
17 | | |
18 | | template <typename T, int N> |
19 | | class GlobalList { |
20 | | public: |
21 | | int len_; |
22 | | int capacity_; |
23 | | GlobalSlab<T, N>* slab_; |
24 | | }; |
25 | | |
26 | | #define GLOBAL_LIST(name, T, N, array) \ |
27 | | GcGlobal<GlobalSlab<T, N>> _slab_##name = {ObjHeader::Global(TypeTag::Slab), \ |
28 | | {.items_ = array}}; \ |
29 | | GcGlobal<GlobalList<T, N>> _list_##name = { \ |
30 | | ObjHeader::Global(TypeTag::List), \ |
31 | | {.len_ = N, .capacity_ = N, .slab_ = &_slab_##name.obj}}; \ |
32 | | List<T>* name = reinterpret_cast<List<T>*>(&_list_##name.obj); |
33 | | |
34 | | template <typename T> |
35 | | class List { |
36 | | public: |
37 | 33 | List() : len_(0), capacity_(0), slab_(nullptr) { |
38 | 33 | } Line | Count | Source | 37 | 17 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 17 | } |
Line | Count | Source | 37 | 12 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 12 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev _ZN4ListIPN4pyos11PasswdEntryEEC2Ev Line | Count | Source | 37 | 1 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEEC2Ev Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEEC2Ev Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEEC2Ev Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEEC2Ev Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEEC2Ev Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEEC2Ev Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEEC2Ev _ZN4ListIP6Tuple2IiP6BigStrEEC2Ev Line | Count | Source | 37 | 3 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 3 | } |
|
39 | | |
40 | | // Implements L[i] |
41 | | T at(int i); |
42 | | |
43 | | // returns index of the element |
44 | | int index(T element); |
45 | | |
46 | | // Implements L[i] = item |
47 | | void set(int i, T item); |
48 | | |
49 | | // L[begin:] |
50 | | List* slice(int begin); |
51 | | |
52 | | // L[begin:end] |
53 | | List* slice(int begin, int end); |
54 | | |
55 | | // Should we have a separate API that doesn't return it? |
56 | | // https://stackoverflow.com/questions/12600330/pop-back-return-value |
57 | | T pop(); |
58 | | |
59 | | // Used in osh/word_parse.py to remove from front |
60 | | T pop(int i); |
61 | | |
62 | | // Remove the first occourence of x from the list. |
63 | | void remove(T x); |
64 | | |
65 | | void clear(); |
66 | | |
67 | | // Used in osh/string_ops.py |
68 | | void reverse(); |
69 | | |
70 | | // Templated function |
71 | | void sort(); |
72 | | |
73 | | // Ensure that there's space for at LEAST this many items |
74 | | void reserve(int num_desired); |
75 | | |
76 | | // Append a single element to this list. |
77 | | void append(T item); |
78 | | |
79 | | // Extend this list with multiple elements. |
80 | | void extend(List<T>* other); |
81 | | |
82 | 33 | static constexpr ObjHeader obj_header() { |
83 | 33 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); |
84 | 33 | } _ZN4ListIP6BigStrE10obj_headerEv Line | Count | Source | 82 | 17 | static constexpr ObjHeader obj_header() { | 83 | 17 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 17 | } |
_ZN4ListIiE10obj_headerEv Line | Count | Source | 82 | 12 | static constexpr ObjHeader obj_header() { | 83 | 12 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 12 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10obj_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_asdl5RedirEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_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 Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11MeasuredDocEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10obj_headerEv _ZN4ListIPN4pyos11PasswdEntryEE10obj_headerEv Line | Count | Source | 82 | 1 | static constexpr ObjHeader obj_header() { | 83 | 1 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10obj_headerEv Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE10obj_headerEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE10obj_headerEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE10obj_headerEv _ZN4ListIP6Tuple2IiP6BigStrEE10obj_headerEv Line | Count | Source | 82 | 3 | static constexpr ObjHeader obj_header() { | 83 | 3 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 3 | } |
|
85 | | |
86 | | int len_; // number of entries |
87 | | int capacity_; // max entries before resizing |
88 | | |
89 | | // The container may be resized, so this field isn't in-line. |
90 | | Slab<T>* slab_; |
91 | | |
92 | | // A list has one Slab pointer which we need to follow. |
93 | 33 | static constexpr uint32_t field_mask() { |
94 | 33 | return maskbit(offsetof(List, slab_)); |
95 | 33 | } _ZN4ListIP6BigStrE10field_maskEv Line | Count | Source | 93 | 17 | static constexpr uint32_t field_mask() { | 94 | 17 | return maskbit(offsetof(List, slab_)); | 95 | 17 | } |
_ZN4ListIiE10field_maskEv Line | Count | Source | 93 | 12 | static constexpr uint32_t field_mask() { | 94 | 12 | return maskbit(offsetof(List, slab_)); | 95 | 12 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10field_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_asdl5RedirEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_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 Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11MeasuredDocEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10field_maskEv _ZN4ListIPN4pyos11PasswdEntryEE10field_maskEv Line | Count | Source | 93 | 1 | static constexpr uint32_t field_mask() { | 94 | 1 | return maskbit(offsetof(List, slab_)); | 95 | 1 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10field_maskEv Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE10field_maskEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE10field_maskEv Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE10field_maskEv _ZN4ListIP6Tuple2IiP6BigStrEE10field_maskEv Line | Count | Source | 93 | 3 | static constexpr uint32_t field_mask() { | 94 | 3 | return maskbit(offsetof(List, slab_)); | 95 | 3 | } |
|
96 | | |
97 | | DISALLOW_COPY_AND_ASSIGN(List) |
98 | | |
99 | | static_assert(sizeof(ObjHeader) % sizeof(T) == 0, |
100 | | "ObjHeader size should be multiple of item size"); |
101 | | static constexpr int kHeaderFudge = sizeof(ObjHeader) / sizeof(T); |
102 | | |
103 | | #if 0 |
104 | | // 24-byte pool comes from very common List header, and Token |
105 | | static constexpr int kPoolBytes1 = 24 - sizeof(ObjHeader); |
106 | | static_assert(kPoolBytes1 % sizeof(T) == 0, |
107 | | "An integral number of items should fit in first pool"); |
108 | | static constexpr int kNumItems1 = kPoolBytes1 / sizeof(T); |
109 | | #endif |
110 | | |
111 | | // Matches mark_sweep_heap.h |
112 | | static constexpr int kPoolBytes2 = 48 - sizeof(ObjHeader); |
113 | | static_assert(kPoolBytes2 % sizeof(T) == 0, |
114 | | "An integral number of items should fit in second pool"); |
115 | | static constexpr int kNumItems2 = kPoolBytes2 / sizeof(T); |
116 | | |
117 | | #if 0 |
118 | | static constexpr int kMinBytes2 = 128 - sizeof(ObjHeader); |
119 | | static_assert(kMinBytes2 % sizeof(T) == 0, |
120 | | "An integral number of items should fit"); |
121 | | static constexpr int kMinItems2 = kMinBytes2 / sizeof(T); |
122 | | #endif |
123 | | |
124 | | // Given the number of items desired, return the number items we should |
125 | | // reserve room for, according to our growth policy. |
126 | 45 | int HowManyItems(int num_desired) { |
127 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So |
128 | | // just use the larger 48 byte pool. |
129 | | #if 0 |
130 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 |
131 | | return kNumItems1; |
132 | | } |
133 | | #endif |
134 | 45 | if (num_desired <= kNumItems2) { // use full cell in pool 2 |
135 | 23 | return kNumItems2; |
136 | 23 | } |
137 | | #if 0 |
138 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 |
139 | | return kMinItems2; |
140 | | } |
141 | | #endif |
142 | | |
143 | | // Make sure the total allocation is a power of 2. TODO: consider using |
144 | | // slightly less than power of 2, to account for malloc() headers, and |
145 | | // reduce fragmentation. |
146 | | // Example: |
147 | | // - ask for 11 integers |
148 | | // - round up 11+2 == 13 up to 16 items |
149 | | // - return 14 items |
150 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. |
151 | 22 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; |
152 | 45 | } _ZN4ListIiE12HowManyItemsEi Line | Count | Source | 126 | 14 | int HowManyItems(int num_desired) { | 127 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 128 | | // just use the larger 48 byte pool. | 129 | | #if 0 | 130 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 131 | | return kNumItems1; | 132 | | } | 133 | | #endif | 134 | 14 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 8 | return kNumItems2; | 136 | 8 | } | 137 | | #if 0 | 138 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 139 | | return kMinItems2; | 140 | | } | 141 | | #endif | 142 | | | 143 | | // Make sure the total allocation is a power of 2. TODO: consider using | 144 | | // slightly less than power of 2, to account for malloc() headers, and | 145 | | // reduce fragmentation. | 146 | | // Example: | 147 | | // - ask for 11 integers | 148 | | // - round up 11+2 == 13 up to 16 items | 149 | | // - return 14 items | 150 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 151 | 6 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 14 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE12HowManyItemsEi _ZN4ListIP6BigStrE12HowManyItemsEi Line | Count | Source | 126 | 26 | int HowManyItems(int num_desired) { | 127 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 128 | | // just use the larger 48 byte pool. | 129 | | #if 0 | 130 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 131 | | return kNumItems1; | 132 | | } | 133 | | #endif | 134 | 26 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 13 | return kNumItems2; | 136 | 13 | } | 137 | | #if 0 | 138 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 139 | | return kMinItems2; | 140 | | } | 141 | | #endif | 142 | | | 143 | | // Make sure the total allocation is a power of 2. TODO: consider using | 144 | | // slightly less than power of 2, to account for malloc() headers, and | 145 | | // reduce fragmentation. | 146 | | // Example: | 147 | | // - ask for 11 integers | 148 | | // - round up 11+2 == 13 up to 16 items | 149 | | // - return 14 items | 150 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 151 | 13 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 26 | } |
_ZN4ListIPN4pyos11PasswdEntryEE12HowManyItemsEi Line | Count | Source | 126 | 4 | int HowManyItems(int num_desired) { | 127 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 128 | | // just use the larger 48 byte pool. | 129 | | #if 0 | 130 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 131 | | return kNumItems1; | 132 | | } | 133 | | #endif | 134 | 4 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 1 | return kNumItems2; | 136 | 1 | } | 137 | | #if 0 | 138 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 139 | | return kMinItems2; | 140 | | } | 141 | | #endif | 142 | | | 143 | | // Make sure the total allocation is a power of 2. TODO: consider using | 144 | | // slightly less than power of 2, to account for malloc() headers, and | 145 | | // reduce fragmentation. | 146 | | // Example: | 147 | | // - ask for 11 integers | 148 | | // - round up 11+2 == 13 up to 16 items | 149 | | // - return 14 items | 150 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 151 | 3 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 4 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE12HowManyItemsEi _ZN4ListIP6Tuple2IiP6BigStrEE12HowManyItemsEi Line | Count | Source | 126 | 1 | int HowManyItems(int num_desired) { | 127 | | // Using the 24-byte pool leads to too much GC of tiny slab objects! So | 128 | | // just use the larger 48 byte pool. | 129 | | #if 0 | 130 | | if (num_desired <= kNumItems1) { // use full cell in pool 1 | 131 | | return kNumItems1; | 132 | | } | 133 | | #endif | 134 | 1 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 1 | return kNumItems2; | 136 | 1 | } | 137 | | #if 0 | 138 | | if (num_desired <= kMinItems2) { // 48 -> 128, not 48 -> 64 | 139 | | return kMinItems2; | 140 | | } | 141 | | #endif | 142 | | | 143 | | // Make sure the total allocation is a power of 2. TODO: consider using | 144 | | // slightly less than power of 2, to account for malloc() headers, and | 145 | | // reduce fragmentation. | 146 | | // Example: | 147 | | // - ask for 11 integers | 148 | | // - round up 11+2 == 13 up to 16 items | 149 | | // - return 14 items | 150 | | // - 14 integers is 56 bytes, plus 8 byte GC header => 64 byte alloc. | 151 | 0 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 1 | } |
|
153 | | }; |
154 | | |
155 | | // "Constructors" as free functions since we can't allocate within a |
156 | | // constructor. Allocation may cause garbage collection, which interferes with |
157 | | // placement new. |
158 | | |
159 | | // This is not really necessary, only syntactic sugar. |
160 | | template <typename T> |
161 | 25 | List<T>* NewList() { |
162 | 25 | return Alloc<List<T>>(); |
163 | 25 | } _Z7NewListIP6BigStrEP4ListIT_Ev Line | Count | Source | 161 | 13 | List<T>* NewList() { | 162 | 13 | return Alloc<List<T>>(); | 163 | 13 | } |
Line | Count | Source | 161 | 8 | List<T>* NewList() { | 162 | 8 | return Alloc<List<T>>(); | 163 | 8 | } |
_Z7NewListIPN4pyos11PasswdEntryEEP4ListIT_Ev Line | Count | Source | 161 | 1 | List<T>* NewList() { | 162 | 1 | return Alloc<List<T>>(); | 163 | 1 | } |
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12CompoundWordEEP4ListIT_Ev _Z7NewListIP6Tuple2IiP6BigStrEEP4ListIT_Ev Line | Count | Source | 161 | 3 | List<T>* NewList() { | 162 | 3 | return Alloc<List<T>>(); | 163 | 3 | } |
|
164 | | |
165 | | // Literal ['foo', 'bar'] |
166 | | // This seems to allow better template argument type deduction than a |
167 | | // constructor. |
168 | | template <typename T> |
169 | 3 | List<T>* NewList(std::initializer_list<T> init) { |
170 | 3 | auto self = Alloc<List<T>>(); |
171 | | |
172 | 3 | int n = init.size(); |
173 | 3 | self->reserve(n); |
174 | | |
175 | 3 | int i = 0; |
176 | 8 | for (auto item : init) { |
177 | 8 | self->set(i, item); |
178 | 8 | ++i; |
179 | 8 | } |
180 | 3 | self->len_ = n; |
181 | 3 | return self; |
182 | 3 | } _Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 169 | 3 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 3 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 3 | int n = init.size(); | 173 | 3 | self->reserve(n); | 174 | | | 175 | 3 | int i = 0; | 176 | 8 | for (auto item : init) { | 177 | 8 | self->set(i, item); | 178 | 8 | ++i; | 179 | 8 | } | 180 | 3 | self->len_ = n; | 181 | 3 | return self; | 182 | 3 | } |
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E Unexecuted instantiation: _Z7NewListIP6BigStrEP4ListIT_ESt16initializer_listIS3_E Unexecuted instantiation: _Z7NewListIP6Tuple2IiiEEP4ListIT_ESt16initializer_listIS4_E Unexecuted instantiation: _Z7NewListIPN11pretty_asdl11DocFragmentEEP4ListIT_ESt16initializer_listIS4_E |
183 | | |
184 | | // ['foo'] * 3 |
185 | | template <typename T> |
186 | | List<T>* NewList(T item, int times) { |
187 | | auto self = Alloc<List<T>>(); |
188 | | |
189 | | self->reserve(times); |
190 | | self->len_ = times; |
191 | | for (int i = 0; i < times; ++i) { |
192 | | self->set(i, item); |
193 | | } |
194 | | return self; |
195 | | } |
196 | | |
197 | | template <typename T> |
198 | 1.17k | void List<T>::append(T item) { |
199 | 1.17k | reserve(len_ + 1); |
200 | 1.17k | slab_->items_[len_] = item; |
201 | 1.17k | ++len_; |
202 | 1.17k | } Line | Count | Source | 198 | 1.06k | void List<T>::append(T item) { | 199 | 1.06k | reserve(len_ + 1); | 200 | 1.06k | slab_->items_[len_] = item; | 201 | 1.06k | ++len_; | 202 | 1.06k | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_ _ZN4ListIP6BigStrE6appendES1_ Line | Count | Source | 198 | 93 | void List<T>::append(T item) { | 199 | 93 | reserve(len_ + 1); | 200 | 93 | slab_->items_[len_] = item; | 201 | 93 | ++len_; | 202 | 93 | } |
_ZN4ListIPN4pyos11PasswdEntryEE6appendES2_ Line | Count | Source | 198 | 20 | void List<T>::append(T item) { | 199 | 20 | reserve(len_ + 1); | 200 | 20 | slab_->items_[len_] = item; | 201 | 20 | ++len_; | 202 | 20 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE6appendES4_ Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE6appendES4_ Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE6appendES2_ Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE6appendES4_ _ZN4ListIP6Tuple2IiP6BigStrEE6appendES4_ Line | Count | Source | 198 | 5 | void List<T>::append(T item) { | 199 | 5 | reserve(len_ + 1); | 200 | 5 | slab_->items_[len_] = item; | 201 | 5 | ++len_; | 202 | 5 | } |
|
203 | | |
204 | | template <typename T> |
205 | 29 | int len(const List<T>* L) { |
206 | 29 | return L->len_; |
207 | 29 | } _Z3lenIP6BigStrEiPK4ListIT_E Line | Count | Source | 205 | 7 | int len(const List<T>* L) { | 206 | 7 | return L->len_; | 207 | 7 | } |
Line | Count | Source | 205 | 15 | int len(const List<T>* L) { | 206 | 15 | return L->len_; | 207 | 15 | } |
_Z3lenIPN4pyos11PasswdEntryEEiPK4ListIT_E Line | Count | Source | 205 | 1 | int len(const List<T>* L) { | 206 | 1 | return L->len_; | 207 | 1 | } |
Unexecuted instantiation: _Z3lenIPN11pretty_asdl11DocFragmentEEiPK4ListIT_E _Z3lenIP6Tuple2IiP6BigStrEEiPK4ListIT_E Line | Count | Source | 205 | 6 | int len(const List<T>* L) { | 206 | 6 | return L->len_; | 207 | 6 | } |
|
208 | | |
209 | | template <typename T> |
210 | | List<T>* list_repeat(T item, int times); |
211 | | |
212 | | template <typename T> |
213 | | inline bool list_contains(List<T>* haystack, T needle); |
214 | | |
215 | | template <typename K, typename V> |
216 | | class Dict; // forward decl |
217 | | |
218 | | template <typename V> |
219 | | List<BigStr*>* sorted(Dict<BigStr*, V>* d); |
220 | | |
221 | | template <typename T> |
222 | | List<T>* sorted(List<T>* l); |
223 | | |
224 | | // L[begin:] |
225 | | template <typename T> |
226 | 0 | List<T>* List<T>::slice(int begin) { |
227 | 0 | return slice(begin, len_); |
228 | 0 | } Unexecuted instantiation: _ZN4ListIP6BigStrE5sliceEi Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE5sliceEi |
229 | | |
230 | | // L[begin:end] |
231 | | template <typename T> |
232 | 0 | List<T>* List<T>::slice(int begin, int end) { |
233 | 0 | SLICE_ADJUST(begin, end, len_); |
234 | |
|
235 | 0 | DCHECK(0 <= begin && begin <= len_); |
236 | 0 | DCHECK(0 <= end && end <= len_); |
237 | | |
238 | 0 | int new_len = end - begin; |
239 | 0 | DCHECK(0 <= new_len && new_len <= len_); |
240 | | |
241 | 0 | List<T>* result = NewList<T>(); |
242 | 0 | result->reserve(new_len); |
243 | | |
244 | | // Faster than append() in a loop |
245 | 0 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); |
246 | 0 | result->len_ = new_len; |
247 | |
|
248 | 0 | return result; |
249 | 0 | } Unexecuted instantiation: _ZN4ListIP6BigStrE5sliceEii Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE5sliceEii |
250 | | |
251 | | // Ensure that there's space for a number of items |
252 | | template <typename T> |
253 | 1.18k | void List<T>::reserve(int num_desired) { |
254 | | // log("reserve capacity = %d, n = %d", capacity_, n); |
255 | | |
256 | | // Don't do anything if there's already enough space. |
257 | 1.18k | if (capacity_ >= num_desired) { |
258 | 1.14k | return; |
259 | 1.14k | } |
260 | | |
261 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of |
262 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for |
263 | | // List<int>. |
264 | | // |
265 | | // Example: the user reserves space for 3 integers. The minimum number of |
266 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, |
267 | | // which leads to 8 + 6*4 = 32 byte Slab. |
268 | | |
269 | 45 | capacity_ = HowManyItems(num_desired); |
270 | 45 | auto new_slab = NewSlab<T>(capacity_); |
271 | | |
272 | 45 | if (len_ > 0) { |
273 | | // log("Copying %d bytes", len_ * sizeof(T)); |
274 | 18 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); |
275 | 18 | } |
276 | 45 | slab_ = new_slab; |
277 | 45 | } Line | Count | Source | 253 | 1.07k | void List<T>::reserve(int num_desired) { | 254 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 255 | | | 256 | | // Don't do anything if there's already enough space. | 257 | 1.07k | if (capacity_ >= num_desired) { | 258 | 1.05k | return; | 259 | 1.05k | } | 260 | | | 261 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 262 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 263 | | // List<int>. | 264 | | // | 265 | | // Example: the user reserves space for 3 integers. The minimum number of | 266 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 267 | | // which leads to 8 + 6*4 = 32 byte Slab. | 268 | | | 269 | 14 | capacity_ = HowManyItems(num_desired); | 270 | 14 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 14 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 2 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 2 | } | 276 | 14 | slab_ = new_slab; | 277 | 14 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl5FieldEE7reserveEi Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi _ZN4ListIP6BigStrE7reserveEi Line | Count | Source | 253 | 93 | void List<T>::reserve(int num_desired) { | 254 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 255 | | | 256 | | // Don't do anything if there's already enough space. | 257 | 93 | if (capacity_ >= num_desired) { | 258 | 67 | return; | 259 | 67 | } | 260 | | | 261 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 262 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 263 | | // List<int>. | 264 | | // | 265 | | // Example: the user reserves space for 3 integers. The minimum number of | 266 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 267 | | // which leads to 8 + 6*4 = 32 byte Slab. | 268 | | | 269 | 26 | capacity_ = HowManyItems(num_desired); | 270 | 26 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 26 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 13 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 13 | } | 276 | 26 | slab_ = new_slab; | 277 | 26 | } |
_ZN4ListIPN4pyos11PasswdEntryEE7reserveEi Line | Count | Source | 253 | 20 | void List<T>::reserve(int num_desired) { | 254 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 255 | | | 256 | | // Don't do anything if there's already enough space. | 257 | 20 | if (capacity_ >= num_desired) { | 258 | 16 | return; | 259 | 16 | } | 260 | | | 261 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 262 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 263 | | // List<int>. | 264 | | // | 265 | | // Example: the user reserves space for 3 integers. The minimum number of | 266 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 267 | | // which leads to 8 + 6*4 = 32 byte Slab. | 268 | | | 269 | 4 | capacity_ = HowManyItems(num_desired); | 270 | 4 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 4 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 3 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 3 | } | 276 | 4 | slab_ = new_slab; | 277 | 4 | } |
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE7reserveEi Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE7reserveEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE7reserveEi Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE7reserveEi Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE7reserveEi Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStrbEE7reserveEi _ZN4ListIP6Tuple2IiP6BigStrEE7reserveEi Line | Count | Source | 253 | 5 | void List<T>::reserve(int num_desired) { | 254 | | // log("reserve capacity = %d, n = %d", capacity_, n); | 255 | | | 256 | | // Don't do anything if there's already enough space. | 257 | 5 | if (capacity_ >= num_desired) { | 258 | 4 | return; | 259 | 4 | } | 260 | | | 261 | | // Slabs should be a total of 2^N bytes. kCapacityAdjust is the number of | 262 | | // items that the 8 byte header takes up: 1 for List<T*>, and 2 for | 263 | | // List<int>. | 264 | | // | 265 | | // Example: the user reserves space for 3 integers. The minimum number of | 266 | | // items would be 5, which is rounded up to 8. Subtract 2 again, giving 6, | 267 | | // which leads to 8 + 6*4 = 32 byte Slab. | 268 | | | 269 | 1 | capacity_ = HowManyItems(num_desired); | 270 | 1 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 1 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 0 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 0 | } | 276 | 1 | slab_ = new_slab; | 277 | 1 | } |
|
278 | | |
279 | | // Implements L[i] = item |
280 | | template <typename T> |
281 | 8 | void List<T>::set(int i, T item) { |
282 | 8 | if (i < 0) { |
283 | 0 | i = len_ + i; |
284 | 0 | } |
285 | | |
286 | 8 | DCHECK(i >= 0); |
287 | 8 | DCHECK(i < capacity_); |
288 | | |
289 | 0 | slab_->items_[i] = item; |
290 | 8 | } Line | Count | Source | 281 | 8 | void List<T>::set(int i, T item) { | 282 | 8 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 8 | DCHECK(i >= 0); | 287 | 8 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 8 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_ Unexecuted instantiation: _ZN4ListIP6BigStrE3setEiS1_ Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE3setEiS2_ Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11DocFragmentEE3setEiS2_ |
291 | | |
292 | | // Implements L[i] |
293 | | template <typename T> |
294 | 38 | T List<T>::at(int i) { |
295 | 38 | if (i < 0) { |
296 | 0 | int j = len_ + i; |
297 | 0 | if (j >= len_ || j < 0) { |
298 | 0 | throw Alloc<IndexError>(); |
299 | 0 | } |
300 | 0 | return slab_->items_[j]; |
301 | 0 | } |
302 | | |
303 | 38 | if (i >= len_ || i < 0) { |
304 | 0 | throw Alloc<IndexError>(); |
305 | 0 | } |
306 | 38 | return slab_->items_[i]; |
307 | 38 | } Line | Count | Source | 294 | 26 | T List<T>::at(int i) { | 295 | 26 | if (i < 0) { | 296 | 0 | int j = len_ + i; | 297 | 0 | if (j >= len_ || j < 0) { | 298 | 0 | throw Alloc<IndexError>(); | 299 | 0 | } | 300 | 0 | return slab_->items_[j]; | 301 | 0 | } | 302 | | | 303 | 26 | if (i >= len_ || i < 0) { | 304 | 0 | throw Alloc<IndexError>(); | 305 | 0 | } | 306 | 26 | return slab_->items_[i]; | 307 | 26 | } |
Line | Count | Source | 294 | 7 | T List<T>::at(int i) { | 295 | 7 | if (i < 0) { | 296 | 0 | int j = len_ + i; | 297 | 0 | if (j >= len_ || j < 0) { | 298 | 0 | throw Alloc<IndexError>(); | 299 | 0 | } | 300 | 0 | return slab_->items_[j]; | 301 | 0 | } | 302 | | | 303 | 7 | if (i >= len_ || i < 0) { | 304 | 0 | throw Alloc<IndexError>(); | 305 | 0 | } | 306 | 7 | return slab_->items_[i]; | 307 | 7 | } |
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE2atEi _ZN4ListIP6Tuple2IiP6BigStrEE2atEi Line | Count | Source | 294 | 5 | T List<T>::at(int i) { | 295 | 5 | if (i < 0) { | 296 | 0 | int j = len_ + i; | 297 | 0 | if (j >= len_ || j < 0) { | 298 | 0 | throw Alloc<IndexError>(); | 299 | 0 | } | 300 | 0 | return slab_->items_[j]; | 301 | 0 | } | 302 | | | 303 | 5 | if (i >= len_ || i < 0) { | 304 | 0 | throw Alloc<IndexError>(); | 305 | 0 | } | 306 | 5 | return slab_->items_[i]; | 307 | 5 | } |
|
308 | | |
309 | | // L.index(i) -- Python method |
310 | | template <typename T> |
311 | | int List<T>::index(T value) { |
312 | | int element_count = len(this); |
313 | | for (int i = 0; i < element_count; i++) { |
314 | | if (items_equal(slab_->items_[i], value)) { |
315 | | return i; |
316 | | } |
317 | | } |
318 | | throw Alloc<ValueError>(); |
319 | | } |
320 | | |
321 | | // Should we have a separate API that doesn't return it? |
322 | | // https://stackoverflow.com/questions/12600330/pop-back-return-value |
323 | | template <typename T> |
324 | 0 | T List<T>::pop() { |
325 | 0 | if (len_ == 0) { |
326 | 0 | throw Alloc<IndexError>(); |
327 | 0 | } |
328 | 0 | len_--; |
329 | 0 | T result = slab_->items_[len_]; |
330 | 0 | slab_->items_[len_] = 0; // zero for GC scan |
331 | 0 | return result; |
332 | 0 | } |
333 | | |
334 | | // Used in osh/word_parse.py to remove from front |
335 | | template <typename T> |
336 | | T List<T>::pop(int i) { |
337 | | if (len_ < i) { |
338 | | throw Alloc<IndexError>(); |
339 | | } |
340 | | |
341 | | T result = at(i); |
342 | | len_--; |
343 | | |
344 | | // Shift everything by one |
345 | | memmove(slab_->items_ + i, slab_->items_ + (i + 1), (len_ - i) * sizeof(T)); |
346 | | |
347 | | /* |
348 | | for (int j = 0; j < len_; j++) { |
349 | | slab_->items_[j] = slab_->items_[j+1]; |
350 | | } |
351 | | */ |
352 | | |
353 | | slab_->items_[len_] = 0; // zero for GC scan |
354 | | return result; |
355 | | } |
356 | | |
357 | | template <typename T> |
358 | | void List<T>::remove(T x) { |
359 | | int idx = this->index(x); |
360 | | this->pop(idx); // unused |
361 | | } |
362 | | |
363 | | template <typename T> |
364 | 1 | void List<T>::clear() { |
365 | 1 | if (slab_) { |
366 | 1 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan |
367 | 1 | } |
368 | 1 | len_ = 0; |
369 | 1 | } |
370 | | |
371 | | // Used in osh/string_ops.py |
372 | | template <typename T> |
373 | | void List<T>::reverse() { |
374 | | for (int i = 0; i < len_ / 2; ++i) { |
375 | | // log("swapping %d and %d", i, n-i); |
376 | | T tmp = slab_->items_[i]; |
377 | | int j = len_ - 1 - i; |
378 | | slab_->items_[i] = slab_->items_[j]; |
379 | | slab_->items_[j] = tmp; |
380 | | } |
381 | | } |
382 | | |
383 | | // Extend this list with multiple elements. |
384 | | template <typename T> |
385 | | void List<T>::extend(List<T>* other) { |
386 | | int n = other->len_; |
387 | | int new_len = len_ + n; |
388 | | reserve(new_len); |
389 | | |
390 | | for (int i = 0; i < n; ++i) { |
391 | | set(len_ + i, other->slab_->items_[i]); |
392 | | } |
393 | | len_ = new_len; |
394 | | } |
395 | | |
396 | 0 | inline bool CompareBigStr(BigStr* a, BigStr* b) { |
397 | 0 | return mylib::str_cmp(a, b) < 0; |
398 | 0 | } |
399 | | |
400 | | template <> |
401 | 0 | inline void List<BigStr*>::sort() { |
402 | 0 | std::sort(slab_->items_, slab_->items_ + len_, CompareBigStr); |
403 | 0 | } |
404 | | |
405 | 0 | inline bool CompareBigInt(mops::BigInt a, mops::BigInt b) { |
406 | 0 | return a < b; |
407 | 0 | } |
408 | | |
409 | | template <> |
410 | 0 | inline void List<mops::BigInt>::sort() { |
411 | 0 | std::sort(slab_->items_, slab_->items_ + len_, CompareBigInt); |
412 | 0 | } |
413 | | |
414 | | // TODO: mycpp can just generate the constructor instead? |
415 | | // e.g. [None] * 3 |
416 | | template <typename T> |
417 | | List<T>* list_repeat(T item, int times) { |
418 | | return NewList<T>(item, times); |
419 | | } |
420 | | |
421 | | // e.g. 'a' in ['a', 'b', 'c'] |
422 | | template <typename T> |
423 | 0 | inline bool list_contains(List<T>* haystack, T needle) { |
424 | 0 | int n = len(haystack); |
425 | 0 | for (int i = 0; i < n; ++i) { |
426 | 0 | if (items_equal(haystack->at(i), needle)) { |
427 | 0 | return true; |
428 | 0 | } |
429 | 0 | } |
430 | 0 | return false; |
431 | 0 | } |
432 | | |
433 | | template <typename V> |
434 | | List<BigStr*>* sorted(Dict<BigStr*, V>* d) { |
435 | | auto keys = d->keys(); |
436 | | keys->sort(); |
437 | | return keys; |
438 | | } |
439 | | |
440 | | template <typename T> |
441 | | List<T>* sorted(List<T>* l) { |
442 | | auto ret = list(l); |
443 | | ret->sort(); |
444 | | return ret; |
445 | | } |
446 | | |
447 | | // list(L) copies the list |
448 | | template <typename T> |
449 | | List<T>* list(List<T>* other) { |
450 | | auto result = NewList<T>(); |
451 | | result->extend(other); |
452 | | return result; |
453 | | } |
454 | | |
455 | | template <class T> |
456 | | class ListIter { |
457 | | public: |
458 | 1 | explicit ListIter(List<T>* L) : L_(L), i_(0) { |
459 | | // Cheney only: L_ could be moved during iteration. |
460 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); |
461 | 1 | } _ZN8ListIterIPN4pyos11PasswdEntryEEC2EP4ListIS2_E Line | Count | Source | 458 | 1 | explicit ListIter(List<T>* L) : L_(L), i_(0) { | 459 | | // Cheney only: L_ could be moved during iteration. | 460 | | // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_)); | 461 | 1 | } |
Unexecuted instantiation: _ZN8ListIterIP6BigStrEC2EP4ListIS1_E 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: _ZN8ListIterIiEC2EP4ListIiE Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11pretty_asdl11MeasuredDocEEC2EP4ListIS2_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_asdl5ParamEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEEC2EP4ListIS2_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 Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIP6Tuple2IP6BigStriEEC2EP4ListIS4_E Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl5FieldEEC2EP4ListIS2_E |
462 | | |
463 | 1 | ~ListIter() { |
464 | | // gHeap.PopRoot(); |
465 | 1 | } _ZN8ListIterIPN4pyos11PasswdEntryEED2Ev Line | Count | Source | 463 | 1 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 1 | } |
Unexecuted instantiation: _ZN8ListIterIP6BigStrED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEED2Ev Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIiED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11pretty_asdl11MeasuredDocEED2Ev 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_asdl5ParamEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEED2Ev 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 Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev Unexecuted instantiation: _ZN8ListIterIP6Tuple2IP6BigStriEED2Ev Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl5FieldEED2Ev |
466 | 19 | void Next() { |
467 | 19 | i_++; |
468 | 19 | } _ZN8ListIterIPN4pyos11PasswdEntryEE4NextEv Line | Count | Source | 466 | 19 | void Next() { | 467 | 19 | i_++; | 468 | 19 | } |
Unexecuted instantiation: _ZN8ListIterIP6BigStrE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIiE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11pretty_asdl11MeasuredDocEE4NextEv 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_asdl5ParamEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE4NextEv 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 Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIP6Tuple2IP6BigStriEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl5FieldEE4NextEv |
469 | 20 | bool Done() { |
470 | | // "unsigned size_t was a mistake" |
471 | 20 | return i_ >= static_cast<int>(L_->len_); |
472 | 20 | } _ZN8ListIterIPN4pyos11PasswdEntryEE4DoneEv Line | Count | Source | 469 | 20 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 20 | return i_ >= static_cast<int>(L_->len_); | 472 | 20 | } |
Unexecuted instantiation: _ZN8ListIterIP6BigStrE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIiE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11pretty_asdl11MeasuredDocEE4DoneEv 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_asdl5ParamEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE4DoneEv 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 Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIP6Tuple2IP6BigStriEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl5FieldEE4DoneEv |
473 | 20 | T Value() { |
474 | 20 | return L_->slab_->items_[i_]; |
475 | 20 | } _ZN8ListIterIPN4pyos11PasswdEntryEE5ValueEv Line | Count | Source | 473 | 20 | T Value() { | 474 | 20 | return L_->slab_->items_[i_]; | 475 | 20 | } |
Unexecuted instantiation: _ZN8ListIterIP6BigStrE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIiE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11pretty_asdl11MeasuredDocEE5ValueEv 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_asdl5ParamEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5RedirEE5ValueEv 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 Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIP6Tuple2IP6BigStriEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl5FieldEE5ValueEv |
476 | | T iterNext() { |
477 | | if (Done()) { |
478 | | throw Alloc<StopIteration>(); |
479 | | } |
480 | | T ret = L_->slab_->items_[i_]; |
481 | | Next(); |
482 | | return ret; |
483 | | } |
484 | | |
485 | | // only for use with generators |
486 | | List<T>* GetList() { |
487 | | return L_; |
488 | | } |
489 | | |
490 | | private: |
491 | | List<T>* L_; |
492 | | int i_; |
493 | | }; |
494 | | |
495 | | // list(it) returns the iterator's backing list |
496 | | template <typename T> |
497 | | List<T>* list(ListIter<T> it) { |
498 | | return list(it.GetList()); |
499 | | } |
500 | | |
501 | | // TODO: Does using pointers rather than indices make this more efficient? |
502 | | template <class T> |
503 | | class ReverseListIter { |
504 | | public: |
505 | 0 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { |
506 | 0 | } |
507 | 0 | void Next() { |
508 | 0 | i_--; |
509 | 0 | } |
510 | 0 | bool Done() { |
511 | 0 | return i_ < 0; |
512 | 0 | } |
513 | 0 | T Value() { |
514 | 0 | return L_->slab_->items_[i_]; |
515 | 0 | } |
516 | | |
517 | | private: |
518 | | List<T>* L_; |
519 | | int i_; |
520 | | }; |
521 | | |
522 | | int max(List<int>* elems); |
523 | | |
524 | | #endif // MYCPP_GC_LIST_H |