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