/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 | 136 | List() : len_(0), capacity_(0), slab_(nullptr) { |
38 | 136 | } Line | Count | Source | 37 | 30 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 30 | } |
Line | Count | Source | 37 | 24 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 24 | } |
_ZN4ListIP6Tuple2IP6BigStriEEC2Ev Line | Count | Source | 37 | 1 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEEC2Ev Line | Count | Source | 37 | 6 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 6 | } |
_ZN4ListIPN10hnode_asdl5FieldEEC2Ev Line | Count | Source | 37 | 37 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev Line | Count | Source | 37 | 37 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 37 | } |
Line | Count | Source | 37 | 1 | List() : len_(0), capacity_(0), slab_(nullptr) { | 38 | 1 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEEC2Ev Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEEC2Ev Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEEC2Ev |
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 | 121 | static constexpr ObjHeader obj_header() { |
83 | 121 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); |
84 | 121 | } _ZN4ListIP6BigStrE10obj_headerEv Line | Count | Source | 82 | 30 | static constexpr ObjHeader obj_header() { | 83 | 30 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 30 | } |
_ZN4ListIiE10obj_headerEv Line | Count | Source | 82 | 13 | static constexpr ObjHeader obj_header() { | 83 | 13 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 13 | } |
_ZN4ListIP6Tuple2IP6BigStriEE10obj_headerEv Line | Count | Source | 82 | 1 | static constexpr ObjHeader obj_header() { | 83 | 1 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE10obj_headerEv Line | Count | Source | 82 | 2 | static constexpr ObjHeader obj_header() { | 83 | 2 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 2 | } |
_ZN4ListIPN10hnode_asdl5FieldEE10obj_headerEv Line | Count | Source | 82 | 37 | static constexpr ObjHeader obj_header() { | 83 | 37 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv Line | Count | Source | 82 | 37 | static constexpr ObjHeader obj_header() { | 83 | 37 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7y_lhs_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10place_op_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13ComprehensionEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NamedArgEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9EggexFlagEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10obj_headerEv _ZN4ListIbE10obj_headerEv Line | Count | Source | 82 | 1 | static constexpr ObjHeader obj_header() { | 83 | 1 | return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>)); | 84 | 1 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10obj_headerEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10obj_headerEv |
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 | 121 | static constexpr uint32_t field_mask() { |
94 | 121 | return maskbit(offsetof(List, slab_)); |
95 | 121 | } _ZN4ListIP6BigStrE10field_maskEv Line | Count | Source | 93 | 30 | static constexpr uint32_t field_mask() { | 94 | 30 | return maskbit(offsetof(List, slab_)); | 95 | 30 | } |
_ZN4ListIiE10field_maskEv Line | Count | Source | 93 | 13 | static constexpr uint32_t field_mask() { | 94 | 13 | return maskbit(offsetof(List, slab_)); | 95 | 13 | } |
_ZN4ListIP6Tuple2IP6BigStriEE10field_maskEv Line | Count | Source | 93 | 1 | static constexpr uint32_t field_mask() { | 94 | 1 | return maskbit(offsetof(List, slab_)); | 95 | 1 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE10field_maskEv Line | Count | Source | 93 | 2 | static constexpr uint32_t field_mask() { | 94 | 2 | return maskbit(offsetof(List, slab_)); | 95 | 2 | } |
_ZN4ListIPN10hnode_asdl5FieldEE10field_maskEv Line | Count | Source | 93 | 37 | static constexpr uint32_t field_mask() { | 94 | 37 | return maskbit(offsetof(List, slab_)); | 95 | 37 | } |
_ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv Line | Count | Source | 93 | 37 | static constexpr uint32_t field_mask() { | 94 | 37 | return maskbit(offsetof(List, slab_)); | 95 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7y_lhs_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10place_op_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13ComprehensionEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NamedArgEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9EggexFlagEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10field_maskEv _ZN4ListIbE10field_maskEv Line | Count | Source | 93 | 1 | static constexpr uint32_t field_mask() { | 94 | 1 | return maskbit(offsetof(List, slab_)); | 95 | 1 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10field_maskEv Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10field_maskEv |
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 | 116 | 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 | 116 | if (num_desired <= kNumItems2) { // use full cell in pool 2 |
135 | 94 | return kNumItems2; |
136 | 94 | } |
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 | 116 | } _ZN4ListIP6BigStrE12HowManyItemsEi Line | Count | Source | 126 | 42 | 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 | 42 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 26 | return kNumItems2; | 136 | 26 | } | 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 | 16 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 42 | } |
_ZN4ListIiE12HowManyItemsEi Line | Count | Source | 126 | 29 | 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 | 29 | 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 | 6 | return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge; | 152 | 29 | } |
_ZN4ListIP6Tuple2IP6BigStriEE12HowManyItemsEi 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 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE12HowManyItemsEi Line | Count | Source | 126 | 6 | 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 | 6 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 6 | return kNumItems2; | 136 | 6 | } | 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 | 6 | } |
_ZN4ListIPN10hnode_asdl5FieldEE12HowManyItemsEi Line | Count | Source | 126 | 37 | 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 | 37 | if (num_desired <= kNumItems2) { // use full cell in pool 2 | 135 | 37 | return kNumItems2; | 136 | 37 | } | 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 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE12HowManyItemsEi _ZN4ListIbE12HowManyItemsEi 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 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE12HowManyItemsEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE12HowManyItemsEi |
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 | 6 | List<T>* NewList() { |
162 | 6 | return Alloc<List<T>>(); |
163 | 6 | } _Z7NewListIP6BigStrEP4ListIT_Ev Line | Count | Source | 161 | 3 | List<T>* NewList() { | 162 | 3 | return Alloc<List<T>>(); | 163 | 3 | } |
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 | 18 | List<T>* NewList(std::initializer_list<T> init) { |
170 | 18 | auto self = Alloc<List<T>>(); |
171 | | |
172 | 18 | int n = init.size(); |
173 | 18 | self->reserve(n); |
174 | | |
175 | 18 | int i = 0; |
176 | 59 | for (auto item : init) { |
177 | 59 | self->set(i, item); |
178 | 59 | ++i; |
179 | 59 | } |
180 | 18 | self->len_ = n; |
181 | 18 | return self; |
182 | 18 | } _Z7NewListIP6BigStrEP4ListIT_ESt16initializer_listIS3_E Line | Count | Source | 169 | 10 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 10 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 10 | int n = init.size(); | 173 | 10 | self->reserve(n); | 174 | | | 175 | 10 | int i = 0; | 176 | 36 | for (auto item : init) { | 177 | 36 | self->set(i, item); | 178 | 36 | ++i; | 179 | 36 | } | 180 | 10 | self->len_ = n; | 181 | 10 | return self; | 182 | 10 | } |
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 169 | 5 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 5 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 5 | int n = init.size(); | 173 | 5 | self->reserve(n); | 174 | | | 175 | 5 | int i = 0; | 176 | 17 | for (auto item : init) { | 177 | 17 | self->set(i, item); | 178 | 17 | ++i; | 179 | 17 | } | 180 | 5 | self->len_ = n; | 181 | 5 | return self; | 182 | 5 | } |
_Z7NewListIP6Tuple2IP6BigStriEEP4ListIT_ESt16initializer_listIS6_E Line | Count | Source | 169 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 1 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 1 | int n = init.size(); | 173 | 1 | self->reserve(n); | 174 | | | 175 | 1 | int i = 0; | 176 | 2 | for (auto item : init) { | 177 | 2 | self->set(i, item); | 178 | 2 | ++i; | 179 | 2 | } | 180 | 1 | self->len_ = n; | 181 | 1 | return self; | 182 | 1 | } |
_Z7NewListIP6Tuple2IiP6BigStrEEP4ListIT_ESt16initializer_listIS6_E Line | Count | Source | 169 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 1 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 1 | int n = init.size(); | 173 | 1 | self->reserve(n); | 174 | | | 175 | 1 | int i = 0; | 176 | 2 | for (auto item : init) { | 177 | 2 | self->set(i, item); | 178 | 2 | ++i; | 179 | 2 | } | 180 | 1 | self->len_ = n; | 181 | 1 | return self; | 182 | 1 | } |
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E _Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E Line | Count | Source | 169 | 1 | List<T>* NewList(std::initializer_list<T> init) { | 170 | 1 | auto self = Alloc<List<T>>(); | 171 | | | 172 | 1 | int n = init.size(); | 173 | 1 | self->reserve(n); | 174 | | | 175 | 1 | int i = 0; | 176 | 2 | for (auto item : init) { | 177 | 2 | self->set(i, item); | 178 | 2 | ++i; | 179 | 2 | } | 180 | 1 | self->len_ = n; | 181 | 1 | return self; | 182 | 1 | } |
|
183 | | |
184 | | // ['foo'] * 3 |
185 | | template <typename T> |
186 | 1 | List<T>* NewList(T item, int times) { |
187 | 1 | auto self = Alloc<List<T>>(); |
188 | | |
189 | 1 | self->reserve(times); |
190 | 1 | self->len_ = times; |
191 | 4 | for (int i = 0; i < times; ++i) { |
192 | 3 | self->set(i, item); |
193 | 3 | } |
194 | 1 | return self; |
195 | 1 | } |
196 | | |
197 | | template <typename T> |
198 | 704 | void List<T>::append(T item) { |
199 | 704 | reserve(len_ + 1); |
200 | 704 | slab_->items_[len_] = item; |
201 | 704 | ++len_; |
202 | 704 | } _ZN4ListIP6BigStrE6appendES1_ Line | Count | Source | 198 | 321 | void List<T>::append(T item) { | 199 | 321 | reserve(len_ + 1); | 200 | 321 | slab_->items_[len_] = item; | 201 | 321 | ++len_; | 202 | 321 | } |
Line | Count | Source | 198 | 303 | void List<T>::append(T item) { | 199 | 303 | reserve(len_ + 1); | 200 | 303 | slab_->items_[len_] = item; | 201 | 303 | ++len_; | 202 | 303 | } |
Unexecuted instantiation: _ZN4ListIP6Tuple2IP6BigStriEE6appendES4_ _ZN4ListIPN10hnode_asdl5FieldEE6appendES2_ Line | Count | Source | 198 | 65 | void List<T>::append(T item) { | 199 | 65 | reserve(len_ + 1); | 200 | 65 | slab_->items_[len_] = item; | 201 | 65 | ++len_; | 202 | 65 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE6appendES2_ Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE6appendES2_ _ZN4ListIP6Tuple2IiP6BigStrEE6appendES4_ Line | Count | Source | 198 | 15 | void List<T>::append(T item) { | 199 | 15 | reserve(len_ + 1); | 200 | 15 | slab_->items_[len_] = item; | 201 | 15 | ++len_; | 202 | 15 | } |
|
203 | | |
204 | | template <typename T> |
205 | 40 | int len(const List<T>* L) { |
206 | 40 | return L->len_; |
207 | 40 | } Line | Count | Source | 205 | 13 | int len(const List<T>* L) { | 206 | 13 | return L->len_; | 207 | 13 | } |
_Z3lenIP6BigStrEiPK4ListIT_E Line | Count | Source | 205 | 26 | int len(const List<T>* L) { | 206 | 26 | return L->len_; | 207 | 26 | } |
Unexecuted instantiation: _Z3lenIPN15test_classes_gc10OpaqueBaseEEiPK4ListIT_E Unexecuted instantiation: _Z3lenIPN15test_classes_gc12PointersBaseEEiPK4ListIT_E Unexecuted instantiation: _Z3lenIPN15test_classes_gc14BaseWithMethodEEiPK4ListIT_E _Z3lenIP6Tuple2IiP6BigStrEEiPK4ListIT_E Line | Count | Source | 205 | 1 | int len(const List<T>* L) { | 206 | 1 | return L->len_; | 207 | 1 | } |
|
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 | 4 | List<T>* List<T>::slice(int begin) { |
227 | 4 | return slice(begin, len_); |
228 | 4 | } _ZN4ListIP6BigStrE5sliceEi Line | Count | Source | 226 | 3 | List<T>* List<T>::slice(int begin) { | 227 | 3 | return slice(begin, len_); | 228 | 3 | } |
Line | Count | Source | 226 | 1 | List<T>* List<T>::slice(int begin) { | 227 | 1 | return slice(begin, len_); | 228 | 1 | } |
|
229 | | |
230 | | // L[begin:end] |
231 | | template <typename T> |
232 | 5 | List<T>* List<T>::slice(int begin, int end) { |
233 | 5 | SLICE_ADJUST(begin, end, len_); |
234 | | |
235 | 5 | DCHECK(0 <= begin && begin <= len_); |
236 | 5 | DCHECK(0 <= end && end <= len_); |
237 | | |
238 | 0 | int new_len = end - begin; |
239 | 5 | DCHECK(0 <= new_len && new_len <= len_); |
240 | | |
241 | 0 | List<T>* result = NewList<T>(); |
242 | 5 | result->reserve(new_len); |
243 | | |
244 | | // Faster than append() in a loop |
245 | 5 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); |
246 | 5 | result->len_ = new_len; |
247 | | |
248 | 5 | return result; |
249 | 5 | } _ZN4ListIP6BigStrE5sliceEii Line | Count | Source | 232 | 3 | List<T>* List<T>::slice(int begin, int end) { | 233 | 3 | SLICE_ADJUST(begin, end, len_); | 234 | | | 235 | 3 | DCHECK(0 <= begin && begin <= len_); | 236 | 3 | DCHECK(0 <= end && end <= len_); | 237 | | | 238 | 0 | int new_len = end - begin; | 239 | 3 | DCHECK(0 <= new_len && new_len <= len_); | 240 | | | 241 | 0 | List<T>* result = NewList<T>(); | 242 | 3 | result->reserve(new_len); | 243 | | | 244 | | // Faster than append() in a loop | 245 | 3 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); | 246 | 3 | result->len_ = new_len; | 247 | | | 248 | 3 | return result; | 249 | 3 | } |
Line | Count | Source | 232 | 2 | List<T>* List<T>::slice(int begin, int end) { | 233 | 2 | SLICE_ADJUST(begin, end, len_); | 234 | | | 235 | 2 | DCHECK(0 <= begin && begin <= len_); | 236 | 2 | DCHECK(0 <= end && end <= len_); | 237 | | | 238 | 0 | int new_len = end - begin; | 239 | 2 | DCHECK(0 <= new_len && new_len <= len_); | 240 | | | 241 | 0 | List<T>* result = NewList<T>(); | 242 | 2 | result->reserve(new_len); | 243 | | | 244 | | // Faster than append() in a loop | 245 | 2 | memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T)); | 246 | 2 | result->len_ = new_len; | 247 | | | 248 | 2 | return result; | 249 | 2 | } |
|
250 | | |
251 | | // Ensure that there's space for a number of items |
252 | | template <typename T> |
253 | 729 | 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 | 729 | if (capacity_ >= num_desired) { |
258 | 613 | return; |
259 | 613 | } |
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 | 116 | capacity_ = HowManyItems(num_desired); |
270 | 116 | auto new_slab = NewSlab<T>(capacity_); |
271 | | |
272 | 116 | if (len_ > 0) { |
273 | | // log("Copying %d bytes", len_ * sizeof(T)); |
274 | 21 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); |
275 | 21 | } |
276 | 116 | slab_ = new_slab; |
277 | 116 | } _ZN4ListIP6BigStrE7reserveEi Line | Count | Source | 253 | 335 | 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 | 335 | if (capacity_ >= num_desired) { | 258 | 293 | return; | 259 | 293 | } | 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 | 42 | capacity_ = HowManyItems(num_desired); | 270 | 42 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 42 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 15 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 15 | } | 276 | 42 | slab_ = new_slab; | 277 | 42 | } |
Line | Count | Source | 253 | 311 | 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 | 311 | if (capacity_ >= num_desired) { | 258 | 282 | return; | 259 | 282 | } | 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 | 29 | capacity_ = HowManyItems(num_desired); | 270 | 29 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 29 | if (len_ > 0) { | 273 | | // log("Copying %d bytes", len_ * sizeof(T)); | 274 | 6 | memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T)); | 275 | 6 | } | 276 | 29 | slab_ = new_slab; | 277 | 29 | } |
_ZN4ListIP6Tuple2IP6BigStriEE7reserveEi Line | Count | Source | 253 | 1 | 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 | if (capacity_ >= num_desired) { | 258 | 0 | return; | 259 | 0 | } | 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 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE7reserveEi Line | Count | Source | 253 | 16 | 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 | 16 | if (capacity_ >= num_desired) { | 258 | 10 | return; | 259 | 10 | } | 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 | 6 | capacity_ = HowManyItems(num_desired); | 270 | 6 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 6 | 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 | 6 | slab_ = new_slab; | 277 | 6 | } |
_ZN4ListIPN10hnode_asdl5FieldEE7reserveEi Line | Count | Source | 253 | 65 | 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 | 65 | if (capacity_ >= num_desired) { | 258 | 28 | return; | 259 | 28 | } | 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 | 37 | capacity_ = HowManyItems(num_desired); | 270 | 37 | auto new_slab = NewSlab<T>(capacity_); | 271 | | | 272 | 37 | 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 | 37 | slab_ = new_slab; | 277 | 37 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi Line | Count | Source | 253 | 1 | 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 | if (capacity_ >= num_desired) { | 258 | 0 | return; | 259 | 0 | } | 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 | } |
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE7reserveEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE7reserveEi Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE7reserveEi |
278 | | |
279 | | // Implements L[i] = item |
280 | | template <typename T> |
281 | 68 | void List<T>::set(int i, T item) { |
282 | 68 | if (i < 0) { |
283 | 0 | i = len_ + i; |
284 | 0 | } |
285 | | |
286 | 68 | DCHECK(i >= 0); |
287 | 68 | DCHECK(i < capacity_); |
288 | | |
289 | 0 | slab_->items_[i] = item; |
290 | 68 | } _ZN4ListIP6BigStrE3setEiS1_ Line | Count | Source | 281 | 39 | void List<T>::set(int i, T item) { | 282 | 39 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 39 | DCHECK(i >= 0); | 287 | 39 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 39 | } |
Line | Count | Source | 281 | 23 | void List<T>::set(int i, T item) { | 282 | 23 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 23 | DCHECK(i >= 0); | 287 | 23 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 23 | } |
_ZN4ListIP6Tuple2IP6BigStriEE3setEiS4_ Line | Count | Source | 281 | 2 | void List<T>::set(int i, T item) { | 282 | 2 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 2 | DCHECK(i >= 0); | 287 | 2 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 2 | } |
_ZN4ListIP6Tuple2IiP6BigStrEE3setEiS4_ Line | Count | Source | 281 | 2 | void List<T>::set(int i, T item) { | 282 | 2 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 2 | DCHECK(i >= 0); | 287 | 2 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 2 | } |
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_ Line | Count | Source | 281 | 2 | void List<T>::set(int i, T item) { | 282 | 2 | if (i < 0) { | 283 | 0 | i = len_ + i; | 284 | 0 | } | 285 | | | 286 | 2 | DCHECK(i >= 0); | 287 | 2 | DCHECK(i < capacity_); | 288 | | | 289 | 0 | slab_->items_[i] = item; | 290 | 2 | } |
|
291 | | |
292 | | // Implements L[i] |
293 | | template <typename T> |
294 | 1.11k | T List<T>::at(int i) { |
295 | 1.11k | if (i < 0) { |
296 | 4 | int j = len_ + i; |
297 | 4 | if (j >= len_ || j < 0) { |
298 | 0 | throw Alloc<IndexError>(); |
299 | 0 | } |
300 | 4 | return slab_->items_[j]; |
301 | 4 | } |
302 | | |
303 | 1.10k | if (i >= len_ || i < 0) { |
304 | 0 | throw Alloc<IndexError>(); |
305 | 0 | } |
306 | 1.10k | return slab_->items_[i]; |
307 | 1.10k | } Line | Count | Source | 294 | 266 | T List<T>::at(int i) { | 295 | 266 | if (i < 0) { | 296 | 1 | int j = len_ + i; | 297 | 1 | if (j >= len_ || j < 0) { | 298 | 0 | throw Alloc<IndexError>(); | 299 | 0 | } | 300 | 1 | return slab_->items_[j]; | 301 | 1 | } | 302 | | | 303 | 265 | if (i >= len_ || i < 0) { | 304 | 0 | throw Alloc<IndexError>(); | 305 | 0 | } | 306 | 265 | return slab_->items_[i]; | 307 | 265 | } |
Line | Count | Source | 294 | 847 | T List<T>::at(int i) { | 295 | 847 | if (i < 0) { | 296 | 3 | int j = len_ + i; | 297 | 3 | if (j >= len_ || j < 0) { | 298 | 0 | throw Alloc<IndexError>(); | 299 | 0 | } | 300 | 3 | return slab_->items_[j]; | 301 | 3 | } | 302 | | | 303 | 844 | if (i >= len_ || i < 0) { | 304 | 0 | throw Alloc<IndexError>(); | 305 | 0 | } | 306 | 844 | return slab_->items_[i]; | 307 | 844 | } |
|
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 | 5 | T List<T>::pop() { |
325 | 5 | if (len_ == 0) { |
326 | 0 | throw Alloc<IndexError>(); |
327 | 0 | } |
328 | 5 | len_--; |
329 | 5 | T result = slab_->items_[len_]; |
330 | 5 | slab_->items_[len_] = 0; // zero for GC scan |
331 | 5 | return result; |
332 | 5 | } |
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 | 2 | void List<T>::clear() { |
365 | 2 | if (slab_) { |
366 | 1 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan |
367 | 1 | } |
368 | 2 | len_ = 0; |
369 | 2 | } Line | Count | Source | 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 | } |
_ZN4ListIP6BigStrE5clearEv Line | Count | Source | 364 | 1 | void List<T>::clear() { | 365 | 1 | if (slab_) { | 366 | 0 | memset(slab_->items_, 0, len_ * sizeof(T)); // zero for GC scan | 367 | 0 | } | 368 | 1 | len_ = 0; | 369 | 1 | } |
|
370 | | |
371 | | // Used in osh/string_ops.py |
372 | | template <typename T> |
373 | 0 | void List<T>::reverse() { |
374 | 0 | for (int i = 0; i < len_ / 2; ++i) { |
375 | | // log("swapping %d and %d", i, n-i); |
376 | 0 | T tmp = slab_->items_[i]; |
377 | 0 | int j = len_ - 1 - i; |
378 | 0 | slab_->items_[i] = slab_->items_[j]; |
379 | 0 | slab_->items_[j] = tmp; |
380 | 0 | } |
381 | 0 | } |
382 | | |
383 | | // Extend this list with multiple elements. |
384 | | template <typename T> |
385 | 1 | void List<T>::extend(List<T>* other) { |
386 | 1 | int n = other->len_; |
387 | 1 | int new_len = len_ + n; |
388 | 1 | reserve(new_len); |
389 | | |
390 | 6 | for (int i = 0; i < n; ++i) { |
391 | 5 | set(len_ + i, other->slab_->items_[i]); |
392 | 5 | } |
393 | 1 | len_ = new_len; |
394 | 1 | } Unexecuted instantiation: _ZN4ListIP6BigStrE6extendEPS2_ Line | Count | Source | 385 | 1 | void List<T>::extend(List<T>* other) { | 386 | 1 | int n = other->len_; | 387 | 1 | int new_len = len_ + n; | 388 | 1 | reserve(new_len); | 389 | | | 390 | 6 | for (int i = 0; i < n; ++i) { | 391 | 5 | set(len_ + i, other->slab_->items_[i]); | 392 | 5 | } | 393 | 1 | len_ = new_len; | 394 | 1 | } |
|
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 | 1 | List<T>* list_repeat(T item, int times) { |
418 | 1 | return NewList<T>(item, times); |
419 | 1 | } |
420 | | |
421 | | // e.g. 'a' in ['a', 'b', 'c'] |
422 | | template <typename T> |
423 | 6 | inline bool list_contains(List<T>* haystack, T needle) { |
424 | 6 | int n = len(haystack); |
425 | 13 | for (int i = 0; i < n; ++i) { |
426 | 11 | if (items_equal(haystack->at(i), needle)) { |
427 | 4 | return true; |
428 | 4 | } |
429 | 11 | } |
430 | 2 | return false; |
431 | 6 | } _Z13list_containsIiEbP4ListIT_ES1_ Line | Count | Source | 423 | 4 | inline bool list_contains(List<T>* haystack, T needle) { | 424 | 4 | int n = len(haystack); | 425 | 9 | for (int i = 0; i < n; ++i) { | 426 | 8 | if (items_equal(haystack->at(i), needle)) { | 427 | 3 | return true; | 428 | 3 | } | 429 | 8 | } | 430 | 1 | return false; | 431 | 4 | } |
_Z13list_containsIP6BigStrEbP4ListIT_ES3_ Line | Count | Source | 423 | 2 | inline bool list_contains(List<T>* haystack, T needle) { | 424 | 2 | int n = len(haystack); | 425 | 4 | for (int i = 0; i < n; ++i) { | 426 | 3 | if (items_equal(haystack->at(i), needle)) { | 427 | 1 | return true; | 428 | 1 | } | 429 | 3 | } | 430 | 1 | return false; | 431 | 2 | } |
|
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 | 1 | List<T>* list(List<T>* other) { |
450 | 1 | auto result = NewList<T>(); |
451 | 1 | result->extend(other); |
452 | 1 | return result; |
453 | 1 | } |
454 | | |
455 | | template <class T> |
456 | | class ListIter { |
457 | | public: |
458 | 124 | 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 | 124 | } _ZN8ListIterIP6BigStrEC2EP4ListIS1_E Line | Count | Source | 458 | 18 | 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 | 18 | } |
_ZN8ListIterIiEC2EP4ListIiE Line | Count | Source | 458 | 16 | 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 | 16 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEEC2EP4ListIS4_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 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E Line | Count | Source | 458 | 6 | 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 | 6 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E _ZN8ListIterIPN10hnode_asdl5FieldEEC2EP4ListIS2_E Line | Count | Source | 458 | 82 | 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 | 82 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEEC2EP4ListIS2_E Unexecuted instantiation: _ZN8ListIterIPN11syntax_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 _ZN8ListIterIbEC2EP4ListIbE 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 | } |
|
462 | | |
463 | 125 | ~ListIter() { |
464 | | // gHeap.PopRoot(); |
465 | 125 | } _ZN8ListIterIP6BigStrED2Ev Line | Count | Source | 463 | 18 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 18 | } |
Line | Count | Source | 463 | 17 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 17 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEED2Ev Line | Count | Source | 463 | 1 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 1 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEED2Ev Line | Count | Source | 463 | 6 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 6 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev _ZN8ListIterIPN10hnode_asdl5FieldEED2Ev Line | Count | Source | 463 | 82 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 82 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEED2Ev Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEED2Ev Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEED2Ev Unexecuted instantiation: _ZN8ListIterIPN11syntax_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 Line | Count | Source | 463 | 1 | ~ListIter() { | 464 | | // gHeap.PopRoot(); | 465 | 1 | } |
|
466 | 286 | void Next() { |
467 | 286 | i_++; |
468 | 286 | } _ZN8ListIterIP6BigStrE4NextEv Line | Count | Source | 466 | 88 | void Next() { | 467 | 88 | i_++; | 468 | 88 | } |
Line | Count | Source | 466 | 53 | void Next() { | 467 | 53 | i_++; | 468 | 53 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE4NextEv Line | Count | Source | 466 | 2 | void Next() { | 467 | 2 | i_++; | 468 | 2 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE4NextEv Line | Count | Source | 466 | 18 | void Next() { | 467 | 18 | i_++; | 468 | 18 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv _ZN8ListIterIPN10hnode_asdl5FieldEE4NextEv Line | Count | Source | 466 | 123 | void Next() { | 467 | 123 | i_++; | 468 | 123 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE4NextEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_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 Line | Count | Source | 466 | 2 | void Next() { | 467 | 2 | i_++; | 468 | 2 | } |
|
469 | 409 | bool Done() { |
470 | | // "unsigned size_t was a mistake" |
471 | 409 | return i_ >= static_cast<int>(L_->len_); |
472 | 409 | } _ZN8ListIterIP6BigStrE4DoneEv Line | Count | Source | 469 | 106 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 106 | return i_ >= static_cast<int>(L_->len_); | 472 | 106 | } |
Line | Count | Source | 469 | 68 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 68 | return i_ >= static_cast<int>(L_->len_); | 472 | 68 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE4DoneEv Line | Count | Source | 469 | 3 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 3 | return i_ >= static_cast<int>(L_->len_); | 472 | 3 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE4DoneEv Line | Count | Source | 469 | 24 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 24 | return i_ >= static_cast<int>(L_->len_); | 472 | 24 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv _ZN8ListIterIPN10hnode_asdl5FieldEE4DoneEv Line | Count | Source | 469 | 205 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 205 | return i_ >= static_cast<int>(L_->len_); | 472 | 205 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE4DoneEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_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 Line | Count | Source | 469 | 3 | bool Done() { | 470 | | // "unsigned size_t was a mistake" | 471 | 3 | return i_ >= static_cast<int>(L_->len_); | 472 | 3 | } |
|
473 | 297 | T Value() { |
474 | 297 | return L_->slab_->items_[i_]; |
475 | 297 | } _ZN8ListIterIP6BigStrE5ValueEv Line | Count | Source | 473 | 89 | T Value() { | 474 | 89 | return L_->slab_->items_[i_]; | 475 | 89 | } |
Line | Count | Source | 473 | 48 | T Value() { | 474 | 48 | return L_->slab_->items_[i_]; | 475 | 48 | } |
_ZN8ListIterIP6Tuple2IP6BigStriEE5ValueEv Line | Count | Source | 473 | 2 | T Value() { | 474 | 2 | return L_->slab_->items_[i_]; | 475 | 2 | } |
_ZN8ListIterIP6Tuple2IiP6BigStrEE5ValueEv Line | Count | Source | 473 | 10 | T Value() { | 474 | 10 | return L_->slab_->items_[i_]; | 475 | 10 | } |
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv _ZN8ListIterIPN10hnode_asdl5FieldEE5ValueEv Line | Count | Source | 473 | 146 | T Value() { | 474 | 146 | return L_->slab_->items_[i_]; | 475 | 146 | } |
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NamedArgEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9AssocPairEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9EggexFlagEE5ValueEv Unexecuted instantiation: _ZN8ListIterIPN11syntax_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 Line | Count | Source | 473 | 2 | T Value() { | 474 | 2 | return L_->slab_->items_[i_]; | 475 | 2 | } |
|
476 | 16 | T iterNext() { |
477 | 16 | if (Done()) { |
478 | 3 | throw Alloc<StopIteration>(); |
479 | 3 | } |
480 | 13 | T ret = L_->slab_->items_[i_]; |
481 | 13 | Next(); |
482 | 13 | return ret; |
483 | 16 | } _ZN8ListIterIP6Tuple2IiP6BigStrEE8iterNextEv Line | Count | Source | 476 | 10 | T iterNext() { | 477 | 10 | if (Done()) { | 478 | 2 | throw Alloc<StopIteration>(); | 479 | 2 | } | 480 | 8 | T ret = L_->slab_->items_[i_]; | 481 | 8 | Next(); | 482 | 8 | return ret; | 483 | 10 | } |
_ZN8ListIterIiE8iterNextEv Line | Count | Source | 476 | 6 | T iterNext() { | 477 | 6 | if (Done()) { | 478 | 1 | throw Alloc<StopIteration>(); | 479 | 1 | } | 480 | 5 | T ret = L_->slab_->items_[i_]; | 481 | 5 | Next(); | 482 | 5 | return ret; | 483 | 6 | } |
|
484 | | |
485 | | // only for use with generators |
486 | 1 | List<T>* GetList() { |
487 | 1 | return L_; |
488 | 1 | } |
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 | 1 | List<T>* list(ListIter<T> it) { |
498 | 1 | return list(it.GetList()); |
499 | 1 | } |
500 | | |
501 | | // TODO: Does using pointers rather than indices make this more efficient? |
502 | | template <class T> |
503 | | class ReverseListIter { |
504 | | public: |
505 | 2 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { |
506 | 2 | } _ZN15ReverseListIterIP6BigStrEC2EP4ListIS1_E Line | Count | Source | 505 | 1 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { | 506 | 1 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E Line | Count | Source | 505 | 1 | explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) { | 506 | 1 | } |
|
507 | 4 | void Next() { |
508 | 4 | i_--; |
509 | 4 | } _ZN15ReverseListIterIP6BigStrE4NextEv Line | Count | Source | 507 | 2 | void Next() { | 508 | 2 | i_--; | 509 | 2 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4NextEv Line | Count | Source | 507 | 2 | void Next() { | 508 | 2 | i_--; | 509 | 2 | } |
|
510 | 6 | bool Done() { |
511 | 6 | return i_ < 0; |
512 | 6 | } _ZN15ReverseListIterIP6BigStrE4DoneEv Line | Count | Source | 510 | 3 | bool Done() { | 511 | 3 | return i_ < 0; | 512 | 3 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4DoneEv Line | Count | Source | 510 | 3 | bool Done() { | 511 | 3 | return i_ < 0; | 512 | 3 | } |
|
513 | 4 | T Value() { |
514 | 4 | return L_->slab_->items_[i_]; |
515 | 4 | } _ZN15ReverseListIterIP6BigStrE5ValueEv Line | Count | Source | 513 | 2 | T Value() { | 514 | 2 | return L_->slab_->items_[i_]; | 515 | 2 | } |
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE5ValueEv Line | Count | Source | 513 | 2 | T Value() { | 514 | 2 | return L_->slab_->items_[i_]; | 515 | 2 | } |
|
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 |