examples

Coverage Report

Created: 2025-05-18 01:46

/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
758
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
758
  }
_ZN4ListIiEC2Ev
Line
Count
Source
37
25
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
25
  }
_ZN4ListIP6BigStrEC2Ev
Line
Count
Source
37
40
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
40
  }
_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
  }
_ZN4ListIPN11pretty_asdl11MeasuredDocEEC2Ev
Line
Count
Source
37
609
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
609
  }
_ZN4ListIPN10hnode_asdl5FieldEEC2Ev
Line
Count
Source
37
57
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
57
  }
_ZN4ListIPN11pretty_asdl11DocFragmentEEC2Ev
Line
Count
Source
37
19
  List() : len_(0), capacity_(0), slab_(nullptr) {
38
19
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev
_ZN4ListIbEC2Ev
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
 protected:
41
  // Used for ASDL subtypes with <.  NOT even a shallow copy - it ALIASES thes
42
  // slab.
43
  explicit List(List* other)
44
1
      : len_(other->len_), capacity_(other->capacity_), slab_(other->slab_) {
45
1
  }
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
466
  static constexpr ObjHeader obj_header() {
91
466
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
466
  }
_ZN4ListIiE10obj_headerEv
Line
Count
Source
90
14
  static constexpr ObjHeader obj_header() {
91
14
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
14
  }
_ZN4ListIP6BigStrE10obj_headerEv
Line
Count
Source
90
39
  static constexpr ObjHeader obj_header() {
91
39
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
39
  }
_ZN4ListIP6Tuple2IP6BigStriEE10obj_headerEv
Line
Count
Source
90
1
  static constexpr ObjHeader obj_header() {
91
1
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
1
  }
_ZN4ListIP6Tuple2IiP6BigStrEE10obj_headerEv
Line
Count
Source
90
2
  static constexpr ObjHeader obj_header() {
91
2
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
2
  }
_ZN4ListIPN10hnode_asdl5FieldEE10obj_headerEv
Line
Count
Source
90
57
  static constexpr ObjHeader obj_header() {
91
57
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
57
  }
_ZN4ListIPN11pretty_asdl11MeasuredDocEE10obj_headerEv
Line
Count
Source
90
333
  static constexpr ObjHeader obj_header() {
91
333
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
333
  }
_ZN4ListIPN11pretty_asdl11DocFragmentEE10obj_headerEv
Line
Count
Source
90
19
  static constexpr ObjHeader obj_header() {
91
19
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
92
19
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10value_asdl16InitializerValueEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17InitializerWord_tEE10obj_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_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
_ZN4ListIbE10obj_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: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10obj_headerEv
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
744
  static constexpr uint32_t field_mask() {
105
744
    return maskbit(offsetof(List, slab_));
106
744
  }
_ZN4ListIiE10field_maskEv
Line
Count
Source
104
14
  static constexpr uint32_t field_mask() {
105
14
    return maskbit(offsetof(List, slab_));
106
14
  }
_ZN4ListIP6BigStrE10field_maskEv
Line
Count
Source
104
41
  static constexpr uint32_t field_mask() {
105
41
    return maskbit(offsetof(List, slab_));
106
41
  }
_ZN4ListIP6Tuple2IP6BigStriEE10field_maskEv
Line
Count
Source
104
1
  static constexpr uint32_t field_mask() {
105
1
    return maskbit(offsetof(List, slab_));
106
1
  }
_ZN4ListIP6Tuple2IiP6BigStrEE10field_maskEv
Line
Count
Source
104
2
  static constexpr uint32_t field_mask() {
105
2
    return maskbit(offsetof(List, slab_));
106
2
  }
_ZN4ListIPN11pretty_asdl11MeasuredDocEE10field_maskEv
Line
Count
Source
104
609
  static constexpr uint32_t field_mask() {
105
609
    return maskbit(offsetof(List, slab_));
106
609
  }
_ZN4ListIPN10hnode_asdl5FieldEE10field_maskEv
Line
Count
Source
104
57
  static constexpr uint32_t field_mask() {
105
57
    return maskbit(offsetof(List, slab_));
106
57
  }
_ZN4ListIPN11pretty_asdl11DocFragmentEE10field_maskEv
Line
Count
Source
104
19
  static constexpr uint32_t field_mask() {
105
19
    return maskbit(offsetof(List, slab_));
106
19
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10value_asdl7value_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10value_asdl16InitializerValueEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17InitializerWord_tEE10field_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_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
_ZN4ListIbE10field_maskEv
Line
Count
Source
104
1
  static constexpr uint32_t field_mask() {
105
1
    return maskbit(offsetof(List, slab_));
106
1
  }
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE10field_maskEv
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
924
  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
924
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
754
      return kNumItems2;
147
754
    }
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
170
    return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge;
163
924
  }
_ZN4ListIiE12HowManyItemsEi
Line
Count
Source
137
30
  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
30
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
24
      return kNumItems2;
147
24
    }
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
6
    return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge;
163
30
  }
_ZN4ListIP6BigStrE12HowManyItemsEi
Line
Count
Source
137
53
  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
53
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
37
      return kNumItems2;
147
37
    }
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
16
    return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge;
163
53
  }
_ZN4ListIP6Tuple2IP6BigStriEE12HowManyItemsEi
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
  }
_ZN4ListIP6Tuple2IiP6BigStrEE12HowManyItemsEi
Line
Count
Source
137
6
  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
6
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
6
      return kNumItems2;
147
6
    }
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
6
  }
_ZN4ListIPN11pretty_asdl11MeasuredDocEE12HowManyItemsEi
Line
Count
Source
137
719
  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
719
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
609
      return kNumItems2;
147
609
    }
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
110
    return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge;
163
719
  }
_ZN4ListIPN11pretty_asdl11DocFragmentEE12HowManyItemsEi
Line
Count
Source
137
57
  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
57
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
19
      return kNumItems2;
147
19
    }
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
38
    return RoundUp(num_desired + kHeaderFudge) - kHeaderFudge;
163
57
  }
_ZN4ListIPN10hnode_asdl5FieldEE12HowManyItemsEi
Line
Count
Source
137
57
  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
57
    if (num_desired <= kNumItems2) {  // use full cell in pool 2
146
57
      return kNumItems2;
147
57
    }
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
57
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE12HowManyItemsEi
_ZN4ListIbE12HowManyItemsEi
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
  }
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE12HowManyItemsEi
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE12HowManyItemsEi
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE12HowManyItemsEi
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
6
List<T>* NewList() {
173
6
  return Alloc<List<T>>();
174
6
}
_Z7NewListIiEP4ListIT_Ev
Line
Count
Source
172
3
List<T>* NewList() {
173
3
  return Alloc<List<T>>();
174
3
}
_Z7NewListIP6BigStrEP4ListIT_Ev
Line
Count
Source
172
3
List<T>* NewList() {
173
3
  return Alloc<List<T>>();
174
3
}
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_Ev
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl5FieldEEP4ListIT_Ev
175
176
// Literal ['foo', 'bar']
177
// This seems to allow better template argument type deduction than a
178
// constructor.
179
template <typename T>
180
266
List<T>* NewList(std::initializer_list<T> init) {
181
266
  auto self = Alloc<List<T>>();
182
183
266
  int n = init.size();
184
266
  self->reserve(n);
185
186
266
  int i = 0;
187
709
  for (auto item : init) {
188
709
    self->slab_->items_[i] = item;
189
709
    ++i;
190
709
  }
191
266
  self->len_ = n;
192
266
  return self;
193
266
}
_Z7NewListIP6BigStrEP4ListIT_ESt16initializer_listIS3_E
Line
Count
Source
180
19
List<T>* NewList(std::initializer_list<T> init) {
181
19
  auto self = Alloc<List<T>>();
182
183
19
  int n = init.size();
184
19
  self->reserve(n);
185
186
19
  int i = 0;
187
55
  for (auto item : init) {
188
55
    self->slab_->items_[i] = item;
189
55
    ++i;
190
55
  }
191
19
  self->len_ = n;
192
19
  return self;
193
19
}
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
180
6
List<T>* NewList(std::initializer_list<T> init) {
181
6
  auto self = Alloc<List<T>>();
182
183
6
  int n = init.size();
184
6
  self->reserve(n);
185
186
6
  int i = 0;
187
20
  for (auto item : init) {
188
20
    self->slab_->items_[i] = item;
189
20
    ++i;
190
20
  }
191
6
  self->len_ = n;
192
6
  return self;
193
6
}
_Z7NewListIP6Tuple2IP6BigStriEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
180
1
List<T>* NewList(std::initializer_list<T> init) {
181
1
  auto self = Alloc<List<T>>();
182
183
1
  int n = init.size();
184
1
  self->reserve(n);
185
186
1
  int i = 0;
187
2
  for (auto item : init) {
188
2
    self->slab_->items_[i] = item;
189
2
    ++i;
190
2
  }
191
1
  self->len_ = n;
192
1
  return self;
193
1
}
_Z7NewListIP6Tuple2IiP6BigStrEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
180
1
List<T>* NewList(std::initializer_list<T> init) {
181
1
  auto self = Alloc<List<T>>();
182
183
1
  int n = init.size();
184
1
  self->reserve(n);
185
186
1
  int i = 0;
187
2
  for (auto item : init) {
188
2
    self->slab_->items_[i] = item;
189
2
    ++i;
190
2
  }
191
1
  self->len_ = n;
192
1
  return self;
193
1
}
_Z7NewListIPN11pretty_asdl11MeasuredDocEEP4ListIT_ESt16initializer_listIS4_E
Line
Count
Source
180
219
List<T>* NewList(std::initializer_list<T> init) {
181
219
  auto self = Alloc<List<T>>();
182
183
219
  int n = init.size();
184
219
  self->reserve(n);
185
186
219
  int i = 0;
187
609
  for (auto item : init) {
188
609
    self->slab_->items_[i] = item;
189
609
    ++i;
190
609
  }
191
219
  self->len_ = n;
192
219
  return self;
193
219
}
_Z7NewListIPN11pretty_asdl11DocFragmentEEP4ListIT_ESt16initializer_listIS4_E
Line
Count
Source
180
19
List<T>* NewList(std::initializer_list<T> init) {
181
19
  auto self = Alloc<List<T>>();
182
183
19
  int n = init.size();
184
19
  self->reserve(n);
185
186
19
  int i = 0;
187
19
  for (auto item : init) {
188
19
    self->slab_->items_[i] = item;
189
19
    ++i;
190
19
  }
191
19
  self->len_ = n;
192
19
  return self;
193
19
}
_Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
180
1
List<T>* NewList(std::initializer_list<T> init) {
181
1
  auto self = Alloc<List<T>>();
182
183
1
  int n = init.size();
184
1
  self->reserve(n);
185
186
1
  int i = 0;
187
2
  for (auto item : init) {
188
2
    self->slab_->items_[i] = item;
189
2
    ++i;
190
2
  }
191
1
  self->len_ = n;
192
1
  return self;
193
1
}
194
195
// ['foo'] * 3
196
template <typename T>
197
1
List<T>* NewList(T item, int times) {
198
1
  auto self = Alloc<List<T>>();
199
200
1
  self->reserve(times);
201
1
  self->len_ = times;
202
4
  for (int i = 0; i < times; ++i) {
203
3
    self->set(i, item);
204
3
  }
205
1
  return self;
206
1
}
207
208
template <typename T>
209
2.99k
void List<T>::append(T item) {
210
2.99k
  reserve(len_ + 1);
211
2.99k
  slab_->items_[len_] = item;
212
2.99k
  ++len_;
213
2.99k
}
_ZN4ListIiE6appendEi
Line
Count
Source
209
303
void List<T>::append(T item) {
210
303
  reserve(len_ + 1);
211
303
  slab_->items_[len_] = item;
212
303
  ++len_;
213
303
}
_ZN4ListIP6BigStrE6appendES1_
Line
Count
Source
209
324
void List<T>::append(T item) {
210
324
  reserve(len_ + 1);
211
324
  slab_->items_[len_] = item;
212
324
  ++len_;
213
324
}
_ZN4ListIPN11pretty_asdl11MeasuredDocEE6appendES2_
Line
Count
Source
209
1.47k
void List<T>::append(T item) {
210
1.47k
  reserve(len_ + 1);
211
1.47k
  slab_->items_[len_] = item;
212
1.47k
  ++len_;
213
1.47k
}
_ZN4ListIPN11pretty_asdl11DocFragmentEE6appendES2_
Line
Count
Source
209
781
void List<T>::append(T item) {
210
781
  reserve(len_ + 1);
211
781
  slab_->items_[len_] = item;
212
781
  ++len_;
213
781
}
_ZN4ListIPN10hnode_asdl5FieldEE6appendES2_
Line
Count
Source
209
105
void List<T>::append(T item) {
210
105
  reserve(len_ + 1);
211
105
  slab_->items_[len_] = item;
212
105
  ++len_;
213
105
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE6appendES2_
_ZN4ListIP6Tuple2IiP6BigStrEE6appendES4_
Line
Count
Source
209
15
void List<T>::append(T item) {
210
15
  reserve(len_ + 1);
211
15
  slab_->items_[len_] = item;
212
15
  ++len_;
213
15
}
214
215
template <typename T>
216
1.74k
int len(const List<T>* L) {
217
1.74k
  return L->len_;
218
1.74k
}
_Z3lenIiEiPK4ListIT_E
Line
Count
Source
216
13
int len(const List<T>* L) {
217
13
  return L->len_;
218
13
}
_Z3lenIP6BigStrEiPK4ListIT_E
Line
Count
Source
216
33
int len(const List<T>* L) {
217
33
  return L->len_;
218
33
}
Unexecuted instantiation: _Z3lenIPN11pretty_asdl11MeasuredDocEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN10hnode_asdl7hnode_tEEiPK4ListIT_E
_Z3lenIPN10hnode_asdl5FieldEEiPK4ListIT_E
Line
Count
Source
216
57
int len(const List<T>* L) {
217
57
  return L->len_;
218
57
}
_Z3lenIPN11pretty_asdl11DocFragmentEEiPK4ListIT_E
Line
Count
Source
216
1.63k
int len(const List<T>* L) {
217
1.63k
  return L->len_;
218
1.63k
}
Unexecuted instantiation: _Z3lenIPN15test_classes_gc10OpaqueBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN15test_classes_gc12PointersBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN15test_classes_gc14BaseWithMethodEEiPK4ListIT_E
_Z3lenIP6Tuple2IiP6BigStrEEiPK4ListIT_E
Line
Count
Source
216
1
int len(const List<T>* L) {
217
1
  return L->len_;
218
1
}
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
4
List<T>* List<T>::slice(int begin) {
238
4
  return slice(begin, len_);
239
4
}
_ZN4ListIP6BigStrE5sliceEi
Line
Count
Source
237
3
List<T>* List<T>::slice(int begin) {
238
3
  return slice(begin, len_);
239
3
}
_ZN4ListIiE5sliceEi
Line
Count
Source
237
1
List<T>* List<T>::slice(int begin) {
238
1
  return slice(begin, len_);
239
1
}
240
241
// L[begin:end]
242
template <typename T>
243
5
List<T>* List<T>::slice(int begin, int end) {
244
5
  SLICE_ADJUST(begin, end, len_);
245
246
5
  DCHECK(0 <= begin && begin <= len_);
247
5
  DCHECK(0 <= end && end <= len_);
248
249
0
  int new_len = end - begin;
250
5
  DCHECK(0 <= new_len && new_len <= len_);
251
252
0
  List<T>* result = NewList<T>();
253
5
  if (new_len == 0) {  // empty slice
254
0
    return result;
255
0
  }
256
257
5
  result->reserve(new_len);
258
5
  DCHECK(result->slab_);
259
  // Faster than append() in a loop
260
0
  memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T));
261
5
  result->len_ = new_len;
262
263
5
  return result;
264
5
}
_ZN4ListIP6BigStrE5sliceEii
Line
Count
Source
243
3
List<T>* List<T>::slice(int begin, int end) {
244
3
  SLICE_ADJUST(begin, end, len_);
245
246
3
  DCHECK(0 <= begin && begin <= len_);
247
3
  DCHECK(0 <= end && end <= len_);
248
249
0
  int new_len = end - begin;
250
3
  DCHECK(0 <= new_len && new_len <= len_);
251
252
0
  List<T>* result = NewList<T>();
253
3
  if (new_len == 0) {  // empty slice
254
0
    return result;
255
0
  }
256
257
3
  result->reserve(new_len);
258
3
  DCHECK(result->slab_);
259
  // Faster than append() in a loop
260
0
  memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T));
261
3
  result->len_ = new_len;
262
263
3
  return result;
264
3
}
_ZN4ListIiE5sliceEii
Line
Count
Source
243
2
List<T>* List<T>::slice(int begin, int end) {
244
2
  SLICE_ADJUST(begin, end, len_);
245
246
2
  DCHECK(0 <= begin && begin <= len_);
247
2
  DCHECK(0 <= end && end <= len_);
248
249
0
  int new_len = end - begin;
250
2
  DCHECK(0 <= new_len && new_len <= len_);
251
252
0
  List<T>* result = NewList<T>();
253
2
  if (new_len == 0) {  // empty slice
254
0
    return result;
255
0
  }
256
257
2
  result->reserve(new_len);
258
2
  DCHECK(result->slab_);
259
  // Faster than append() in a loop
260
0
  memcpy(result->slab_->items_, slab_->items_ + begin, new_len * sizeof(T));
261
2
  result->len_ = new_len;
262
263
2
  return result;
264
2
}
265
266
// Ensure that there's space for a number of items
267
template <typename T>
268
3.27k
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
3.27k
  if (capacity_ >= num_desired) {
273
2.34k
    return;
274
2.34k
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
924
  capacity_ = HowManyItems(num_desired);
285
924
  auto new_slab = NewSlab<T>(capacity_);
286
287
924
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
169
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
169
  }
291
924
  slab_ = new_slab;
292
924
}
_ZN4ListIiE7reserveEi
Line
Count
Source
268
312
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
312
  if (capacity_ >= num_desired) {
273
282
    return;
274
282
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
30
  capacity_ = HowManyItems(num_desired);
285
30
  auto new_slab = NewSlab<T>(capacity_);
286
287
30
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
6
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
6
  }
291
30
  slab_ = new_slab;
292
30
}
_ZN4ListIP6BigStrE7reserveEi
Line
Count
Source
268
347
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
347
  if (capacity_ >= num_desired) {
273
294
    return;
274
294
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
53
  capacity_ = HowManyItems(num_desired);
285
53
  auto new_slab = NewSlab<T>(capacity_);
286
287
53
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
15
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
15
  }
291
53
  slab_ = new_slab;
292
53
}
_ZN4ListIP6Tuple2IP6BigStriEE7reserveEi
Line
Count
Source
268
1
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
1
  if (capacity_ >= num_desired) {
273
0
    return;
274
0
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
1
  capacity_ = HowManyItems(num_desired);
285
1
  auto new_slab = NewSlab<T>(capacity_);
286
287
1
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
0
  }
291
1
  slab_ = new_slab;
292
1
}
_ZN4ListIP6Tuple2IiP6BigStrEE7reserveEi
Line
Count
Source
268
16
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
16
  if (capacity_ >= num_desired) {
273
10
    return;
274
10
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
6
  capacity_ = HowManyItems(num_desired);
285
6
  auto new_slab = NewSlab<T>(capacity_);
286
287
6
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
0
  }
291
6
  slab_ = new_slab;
292
6
}
_ZN4ListIPN11pretty_asdl11MeasuredDocEE7reserveEi
Line
Count
Source
268
1.68k
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
1.68k
  if (capacity_ >= num_desired) {
273
970
    return;
274
970
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
719
  capacity_ = HowManyItems(num_desired);
285
719
  auto new_slab = NewSlab<T>(capacity_);
286
287
719
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
110
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
110
  }
291
719
  slab_ = new_slab;
292
719
}
_ZN4ListIPN11pretty_asdl11DocFragmentEE7reserveEi
Line
Count
Source
268
800
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
800
  if (capacity_ >= num_desired) {
273
743
    return;
274
743
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
57
  capacity_ = HowManyItems(num_desired);
285
57
  auto new_slab = NewSlab<T>(capacity_);
286
287
57
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
38
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
38
  }
291
57
  slab_ = new_slab;
292
57
}
_ZN4ListIPN10hnode_asdl5FieldEE7reserveEi
Line
Count
Source
268
105
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
105
  if (capacity_ >= num_desired) {
273
48
    return;
274
48
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
57
  capacity_ = HowManyItems(num_desired);
285
57
  auto new_slab = NewSlab<T>(capacity_);
286
287
57
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
0
  }
291
57
  slab_ = new_slab;
292
57
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi
_ZN4ListIbE7reserveEi
Line
Count
Source
268
1
void List<T>::reserve(int num_desired) {
269
  // log("reserve capacity = %d, n = %d", capacity_, n);
270
271
  // Don't do anything if there's already enough space.
272
1
  if (capacity_ >= num_desired) {
273
0
    return;
274
0
  }
275
276
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
277
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
278
  // List<int>.
279
  //
280
  // Example: the user reserves space for 3 integers.  The minimum number of
281
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
282
  // which leads to 8 + 6*4 = 32 byte Slab.
283
284
1
  capacity_ = HowManyItems(num_desired);
285
1
  auto new_slab = NewSlab<T>(capacity_);
286
287
1
  if (len_ > 0) {
288
    // log("Copying %d bytes", len_ * sizeof(T));
289
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
290
0
  }
291
1
  slab_ = new_slab;
292
1
}
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc10OpaqueBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc12PointersBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN15test_classes_gc14BaseWithMethodEE7reserveEi
293
294
// Implements L[i] = item
295
template <typename T>
296
5
void List<T>::set(int i, T item) {
297
5
  if (i < 0) {
298
0
    i = len_ + i;
299
0
  }
300
301
5
  if (0 > i || i >= len_) {
302
0
    throw Alloc<IndexError>();
303
0
  }
304
305
5
  slab_->items_[i] = item;
306
5
}
_ZN4ListIiE3setEii
Line
Count
Source
296
1
void List<T>::set(int i, T item) {
297
1
  if (i < 0) {
298
0
    i = len_ + i;
299
0
  }
300
301
1
  if (0 > i || i >= len_) {
302
0
    throw Alloc<IndexError>();
303
0
  }
304
305
1
  slab_->items_[i] = item;
306
1
}
_ZN4ListIP6BigStrE3setEiS1_
Line
Count
Source
296
4
void List<T>::set(int i, T item) {
297
4
  if (i < 0) {
298
0
    i = len_ + i;
299
0
  }
300
301
4
  if (0 > i || i >= len_) {
302
0
    throw Alloc<IndexError>();
303
0
  }
304
305
4
  slab_->items_[i] = item;
306
4
}
307
308
// Implements L[i]
309
template <typename T>
310
1.11k
T List<T>::at(int i) {
311
1.11k
  if (i < 0) {
312
4
    i = len_ + i;
313
4
  }
314
315
1.11k
  if (0 > i || i >= len_) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
1.11k
  return slab_->items_[i];
319
1.11k
}
_ZN4ListIiE2atEi
Line
Count
Source
310
266
T List<T>::at(int i) {
311
266
  if (i < 0) {
312
1
    i = len_ + i;
313
1
  }
314
315
266
  if (0 > i || i >= len_) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
266
  return slab_->items_[i];
319
266
}
_ZN4ListIP6BigStrE2atEi
Line
Count
Source
310
851
T List<T>::at(int i) {
311
851
  if (i < 0) {
312
3
    i = len_ + i;
313
3
  }
314
315
851
  if (0 > i || i >= len_) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
851
  return slab_->items_[i];
319
851
}
320
321
// L.index(i) -- Python method
322
template <typename T>
323
int List<T>::index(T value) {
324
  int element_count = len(this);
325
  for (int i = 0; i < element_count; i++) {
326
    if (items_equal(slab_->items_[i], value)) {
327
      return i;
328
    }
329
  }
330
  throw Alloc<ValueError>();
331
}
332
333
// Should we have a separate API that doesn't return it?
334
// https://stackoverflow.com/questions/12600330/pop-back-return-value
335
template <typename T>
336
805
T List<T>::pop() {
337
805
  if (len_ == 0) {
338
0
    throw Alloc<IndexError>();
339
0
  }
340
805
  len_--;
341
805
  T result = slab_->items_[len_];
342
805
  slab_->items_[len_] = 0;  // zero for GC scan
343
805
  return result;
344
805
}
_ZN4ListIP6BigStrE3popEv
Line
Count
Source
336
5
T List<T>::pop() {
337
5
  if (len_ == 0) {
338
0
    throw Alloc<IndexError>();
339
0
  }
340
5
  len_--;
341
5
  T result = slab_->items_[len_];
342
5
  slab_->items_[len_] = 0;  // zero for GC scan
343
5
  return result;
344
5
}
_ZN4ListIPN11pretty_asdl11DocFragmentEE3popEv
Line
Count
Source
336
800
T List<T>::pop() {
337
800
  if (len_ == 0) {
338
0
    throw Alloc<IndexError>();
339
0
  }
340
800
  len_--;
341
800
  T result = slab_->items_[len_];
342
800
  slab_->items_[len_] = 0;  // zero for GC scan
343
800
  return result;
344
800
}
345
346
// Used in osh/word_parse.py to remove from front
347
template <typename T>
348
T List<T>::pop(int i) {
349
  if (len_ < i) {
350
    throw Alloc<IndexError>();
351
  }
352
353
  T result = at(i);
354
  len_--;
355
356
  // Shift everything by one
357
  memmove(slab_->items_ + i, slab_->items_ + (i + 1), (len_ - i) * sizeof(T));
358
359
  /*
360
  for (int j = 0; j < len_; j++) {
361
    slab_->items_[j] = slab_->items_[j+1];
362
  }
363
  */
364
365
  slab_->items_[len_] = 0;  // zero for GC scan
366
  return result;
367
}
368
369
template <typename T>
370
void List<T>::remove(T x) {
371
  int idx = this->index(x);
372
  this->pop(idx);  // unused
373
}
374
375
template <typename T>
376
2
void List<T>::clear() {
377
2
  if (slab_) {
378
1
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
379
1
  }
380
2
  len_ = 0;
381
2
}
_ZN4ListIiE5clearEv
Line
Count
Source
376
1
void List<T>::clear() {
377
1
  if (slab_) {
378
1
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
379
1
  }
380
1
  len_ = 0;
381
1
}
_ZN4ListIP6BigStrE5clearEv
Line
Count
Source
376
1
void List<T>::clear() {
377
1
  if (slab_) {
378
0
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
379
0
  }
380
1
  len_ = 0;
381
1
}
382
383
// used by ASDL
384
template <typename T>
385
1
void List<T>::SetTaken() {
386
1
  slab_ = nullptr;
387
1
  len_ = 0;
388
1
  capacity_ = 0;
389
1
}
_ZN4ListIP6BigStrE8SetTakenEv
Line
Count
Source
385
1
void List<T>::SetTaken() {
386
1
  slab_ = nullptr;
387
1
  len_ = 0;
388
1
  capacity_ = 0;
389
1
}
Unexecuted instantiation: _ZN4ListIPN11pretty_asdl11MeasuredDocEE8SetTakenEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE8SetTakenEv
390
391
// Used in osh/string_ops.py
392
template <typename T>
393
0
void List<T>::reverse() {
394
0
  for (int i = 0; i < len_ / 2; ++i) {
395
    // log("swapping %d and %d", i, n-i);
396
0
    T tmp = slab_->items_[i];
397
0
    int j = len_ - 1 - i;
398
0
    slab_->items_[i] = slab_->items_[j];
399
0
    slab_->items_[j] = tmp;
400
0
  }
401
0
}
402
403
// Extend this list with multiple elements.
404
template <typename T>
405
1
void List<T>::extend(List<T>* other) {
406
1
  int n = other->len_;
407
1
  int new_len = len_ + n;
408
1
  reserve(new_len);
409
410
6
  for (int i = 0; i < n; ++i) {
411
5
    slab_->items_[len_ + i] = other->slab_->items_[i];
412
5
  }
413
1
  len_ = new_len;
414
1
}
Unexecuted instantiation: _ZN4ListIP6BigStrE6extendEPS2_
_ZN4ListIiE6extendEPS0_
Line
Count
Source
405
1
void List<T>::extend(List<T>* other) {
406
1
  int n = other->len_;
407
1
  int new_len = len_ + n;
408
1
  reserve(new_len);
409
410
6
  for (int i = 0; i < n; ++i) {
411
5
    slab_->items_[len_ + i] = other->slab_->items_[i];
412
5
  }
413
1
  len_ = new_len;
414
1
}
415
416
0
inline bool CompareBigStr(BigStr* a, BigStr* b) {
417
0
  return mylib::str_cmp(a, b) < 0;
418
0
}
419
420
template <>
421
0
inline void List<BigStr*>::sort() {
422
0
  if (slab_) {
423
0
    std::sort(slab_->items_, slab_->items_ + len_, CompareBigStr);
424
0
  }
425
0
}
426
427
0
inline bool CompareBigInt(mops::BigInt a, mops::BigInt b) {
428
0
  return a < b;
429
0
}
430
431
template <>
432
0
inline void List<mops::BigInt>::sort() {
433
0
  std::sort(slab_->items_, slab_->items_ + len_, CompareBigInt);
434
0
}
435
436
// TODO: mycpp can just generate the constructor instead?
437
// e.g. [None] * 3
438
template <typename T>
439
1
List<T>* list_repeat(T item, int times) {
440
1
  return NewList<T>(item, times);
441
1
}
442
443
// e.g. 'a' in ['a', 'b', 'c']
444
template <typename T>
445
6
inline bool list_contains(List<T>* haystack, T needle) {
446
6
  int n = len(haystack);
447
13
  for (int i = 0; i < n; ++i) {
448
11
    if (items_equal(haystack->at(i), needle)) {
449
4
      return true;
450
4
    }
451
11
  }
452
2
  return false;
453
6
}
_Z13list_containsIiEbP4ListIT_ES1_
Line
Count
Source
445
4
inline bool list_contains(List<T>* haystack, T needle) {
446
4
  int n = len(haystack);
447
9
  for (int i = 0; i < n; ++i) {
448
8
    if (items_equal(haystack->at(i), needle)) {
449
3
      return true;
450
3
    }
451
8
  }
452
1
  return false;
453
4
}
_Z13list_containsIP6BigStrEbP4ListIT_ES3_
Line
Count
Source
445
2
inline bool list_contains(List<T>* haystack, T needle) {
446
2
  int n = len(haystack);
447
4
  for (int i = 0; i < n; ++i) {
448
3
    if (items_equal(haystack->at(i), needle)) {
449
1
      return true;
450
1
    }
451
3
  }
452
1
  return false;
453
2
}
454
455
template <typename V>
456
List<BigStr*>* sorted(Dict<BigStr*, V>* d) {
457
  auto keys = d->keys();
458
  keys->sort();
459
  return keys;
460
}
461
462
template <typename T>
463
List<T>* sorted(List<T>* l) {
464
  auto ret = list(l);
465
  ret->sort();
466
  return ret;
467
}
468
469
// list(L) copies the list
470
template <typename T>
471
1
List<T>* list(List<T>* other) {
472
1
  auto result = NewList<T>();
473
1
  result->extend(other);
474
1
  return result;
475
1
}
476
477
template <class T>
478
class ListIter {
479
 public:
480
604
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
604
  }
_ZN8ListIterIP6BigStrEC2EP4ListIS1_E
Line
Count
Source
480
28
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
28
  }
_ZN8ListIterIiEC2EP4ListIiE
Line
Count
Source
480
16
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
16
  }
_ZN8ListIterIP6Tuple2IP6BigStriEEC2EP4ListIS4_E
Line
Count
Source
480
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
1
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E
Line
Count
Source
480
6
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
6
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E
_ZN8ListIterIPN10hnode_asdl5FieldEEC2EP4ListIS2_E
Line
Count
Source
480
57
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
57
  }
_ZN8ListIterIPN11pretty_asdl11MeasuredDocEEC2EP4ListIS2_E
Line
Count
Source
480
495
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
495
  }
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEEC2EP4ListIS2_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_asdl10SourceLineEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl16InitializerValueEEC2EP4ListIS2_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
_ZN8ListIterIbEC2EP4ListIbE
Line
Count
Source
480
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
481
    // Cheney only: L_ could be moved during iteration.
482
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
483
1
  }
484
485
605
  ~ListIter() {
486
    // gHeap.PopRoot();
487
605
  }
_ZN8ListIterIP6BigStrED2Ev
Line
Count
Source
485
28
  ~ListIter() {
486
    // gHeap.PopRoot();
487
28
  }
_ZN8ListIterIiED2Ev
Line
Count
Source
485
17
  ~ListIter() {
486
    // gHeap.PopRoot();
487
17
  }
_ZN8ListIterIP6Tuple2IP6BigStriEED2Ev
Line
Count
Source
485
1
  ~ListIter() {
486
    // gHeap.PopRoot();
487
1
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEED2Ev
Line
Count
Source
485
6
  ~ListIter() {
486
    // gHeap.PopRoot();
487
6
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev
_ZN8ListIterIPN10hnode_asdl5FieldEED2Ev
Line
Count
Source
485
57
  ~ListIter() {
486
    // gHeap.PopRoot();
487
57
  }
_ZN8ListIterIPN11pretty_asdl11MeasuredDocEED2Ev
Line
Count
Source
485
495
  ~ListIter() {
486
    // gHeap.PopRoot();
487
495
  }
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl16InitializerValueEED2Ev
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
_ZN8ListIterIbED2Ev
Line
Count
Source
485
1
  ~ListIter() {
486
    // gHeap.PopRoot();
487
1
  }
488
1.72k
  void Next() {
489
1.72k
    i_++;
490
1.72k
  }
_ZN8ListIterIP6BigStrE4NextEv
Line
Count
Source
488
109
  void Next() {
489
109
    i_++;
490
109
  }
_ZN8ListIterIiE4NextEv
Line
Count
Source
488
53
  void Next() {
489
53
    i_++;
490
53
  }
_ZN8ListIterIP6Tuple2IP6BigStriEE4NextEv
Line
Count
Source
488
2
  void Next() {
489
2
    i_++;
490
2
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEE4NextEv
Line
Count
Source
488
18
  void Next() {
489
18
    i_++;
490
18
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv
_ZN8ListIterIPN10hnode_asdl5FieldEE4NextEv
Line
Count
Source
488
105
  void Next() {
489
105
    i_++;
490
105
  }
_ZN8ListIterIPN11pretty_asdl11MeasuredDocEE4NextEv
Line
Count
Source
488
1.43k
  void Next() {
489
1.43k
    i_++;
490
1.43k
  }
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl16InitializerValueEE4NextEv
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
_ZN8ListIterIbE4NextEv
Line
Count
Source
488
2
  void Next() {
489
2
    i_++;
490
2
  }
491
2.32k
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
2.32k
    return i_ >= static_cast<int>(L_->len_);
494
2.32k
  }
_ZN8ListIterIP6BigStrE4DoneEv
Line
Count
Source
491
137
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
137
    return i_ >= static_cast<int>(L_->len_);
494
137
  }
_ZN8ListIterIiE4DoneEv
Line
Count
Source
491
68
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
68
    return i_ >= static_cast<int>(L_->len_);
494
68
  }
_ZN8ListIterIP6Tuple2IP6BigStriEE4DoneEv
Line
Count
Source
491
3
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
3
    return i_ >= static_cast<int>(L_->len_);
494
3
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEE4DoneEv
Line
Count
Source
491
24
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
24
    return i_ >= static_cast<int>(L_->len_);
494
24
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv
_ZN8ListIterIPN10hnode_asdl5FieldEE4DoneEv
Line
Count
Source
491
162
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
162
    return i_ >= static_cast<int>(L_->len_);
494
162
  }
_ZN8ListIterIPN11pretty_asdl11MeasuredDocEE4DoneEv
Line
Count
Source
491
1.92k
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
1.92k
    return i_ >= static_cast<int>(L_->len_);
494
1.92k
  }
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl16InitializerValueEE4DoneEv
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
_ZN8ListIterIbE4DoneEv
Line
Count
Source
491
3
  bool Done() {
492
    // "unsigned size_t was a mistake"
493
3
    return i_ >= static_cast<int>(L_->len_);
494
3
  }
495
1.70k
  T Value() {
496
1.70k
    return L_->slab_->items_[i_];
497
1.70k
  }
_ZN8ListIterIP6BigStrE5ValueEv
Line
Count
Source
495
110
  T Value() {
496
110
    return L_->slab_->items_[i_];
497
110
  }
_ZN8ListIterIiE5ValueEv
Line
Count
Source
495
48
  T Value() {
496
48
    return L_->slab_->items_[i_];
497
48
  }
_ZN8ListIterIP6Tuple2IP6BigStriEE5ValueEv
Line
Count
Source
495
2
  T Value() {
496
2
    return L_->slab_->items_[i_];
497
2
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEE5ValueEv
Line
Count
Source
495
10
  T Value() {
496
10
    return L_->slab_->items_[i_];
497
10
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv
_ZN8ListIterIPN10hnode_asdl5FieldEE5ValueEv
Line
Count
Source
495
105
  T Value() {
496
105
    return L_->slab_->items_[i_];
497
105
  }
_ZN8ListIterIPN11pretty_asdl11MeasuredDocEE5ValueEv
Line
Count
Source
495
1.43k
  T Value() {
496
1.43k
    return L_->slab_->items_[i_];
497
1.43k
  }
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl7value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN10value_asdl16InitializerValueEE5ValueEv
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
_ZN8ListIterIbE5ValueEv
Line
Count
Source
495
2
  T Value() {
496
2
    return L_->slab_->items_[i_];
497
2
  }
498
16
  T iterNext() {
499
16
    if (Done()) {
500
3
      throw Alloc<StopIteration>();
501
3
    }
502
13
    T ret = L_->slab_->items_[i_];
503
13
    Next();
504
13
    return ret;
505
16
  }
_ZN8ListIterIP6Tuple2IiP6BigStrEE8iterNextEv
Line
Count
Source
498
10
  T iterNext() {
499
10
    if (Done()) {
500
2
      throw Alloc<StopIteration>();
501
2
    }
502
8
    T ret = L_->slab_->items_[i_];
503
8
    Next();
504
8
    return ret;
505
10
  }
_ZN8ListIterIiE8iterNextEv
Line
Count
Source
498
6
  T iterNext() {
499
6
    if (Done()) {
500
1
      throw Alloc<StopIteration>();
501
1
    }
502
5
    T ret = L_->slab_->items_[i_];
503
5
    Next();
504
5
    return ret;
505
6
  }
506
507
  // only for use with generators
508
1
  List<T>* GetList() {
509
1
    return L_;
510
1
  }
511
512
 private:
513
  List<T>* L_;
514
  int i_;
515
};
516
517
// list(it) returns the iterator's backing list
518
template <typename T>
519
1
List<T>* list(ListIter<T> it) {
520
1
  return list(it.GetList());
521
1
}
522
523
// TODO: Does using pointers rather than indices make this more efficient?
524
template <class T>
525
class ReverseListIter {
526
 public:
527
116
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
116
  }
_ZN15ReverseListIterIP6BigStrEC2EP4ListIS1_E
Line
Count
Source
527
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
1
  }
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEEC2EP4ListIS4_E
Line
Count
Source
527
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
1
  }
_ZN15ReverseListIterIPN11pretty_asdl11MeasuredDocEEC2EP4ListIS2_E
Line
Count
Source
527
114
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
528
114
  }
529
652
  void Next() {
530
652
    i_--;
531
652
  }
_ZN15ReverseListIterIP6BigStrE4NextEv
Line
Count
Source
529
2
  void Next() {
530
2
    i_--;
531
2
  }
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4NextEv
Line
Count
Source
529
2
  void Next() {
530
2
    i_--;
531
2
  }
_ZN15ReverseListIterIPN11pretty_asdl11MeasuredDocEE4NextEv
Line
Count
Source
529
648
  void Next() {
530
648
    i_--;
531
648
  }
532
768
  bool Done() {
533
768
    return i_ < 0;
534
768
  }
_ZN15ReverseListIterIP6BigStrE4DoneEv
Line
Count
Source
532
3
  bool Done() {
533
3
    return i_ < 0;
534
3
  }
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE4DoneEv
Line
Count
Source
532
3
  bool Done() {
533
3
    return i_ < 0;
534
3
  }
_ZN15ReverseListIterIPN11pretty_asdl11MeasuredDocEE4DoneEv
Line
Count
Source
532
762
  bool Done() {
533
762
    return i_ < 0;
534
762
  }
535
652
  T Value() {
536
652
    return L_->slab_->items_[i_];
537
652
  }
_ZN15ReverseListIterIP6BigStrE5ValueEv
Line
Count
Source
535
2
  T Value() {
536
2
    return L_->slab_->items_[i_];
537
2
  }
_ZN15ReverseListIterIP6Tuple2IiP6BigStrEE5ValueEv
Line
Count
Source
535
2
  T Value() {
536
2
    return L_->slab_->items_[i_];
537
2
  }
_ZN15ReverseListIterIPN11pretty_asdl11MeasuredDocEE5ValueEv
Line
Count
Source
535
648
  T Value() {
536
648
    return L_->slab_->items_[i_];
537
648
  }
538
539
 private:
540
  List<T>* L_;
541
  int i_;
542
};
543
544
int max(List<int>* elems);
545
546
#endif  // MYCPP_GC_LIST_H