cpp

Coverage Report

Created: 2023-09-13 01:07

/home/andy/git/oilshell/oil/mycpp/gc_list.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef MYCPP_GC_LIST_H
2
#define MYCPP_GC_LIST_H
3
4
#include <string.h>  // memcpy
5
6
#include <algorithm>  // sort() is templated
7
8
#include "mycpp/common.h"  // DCHECK
9
#include "mycpp/comparators.h"
10
#include "mycpp/gc_alloc.h"     // Alloc
11
#include "mycpp/gc_builtins.h"  // ValueError
12
#include "mycpp/gc_slab.h"
13
14
// GlobalList is layout-compatible with List (unit tests assert this), and it
15
// can be a true C global (incurs zero startup time)
16
17
template <typename T, int N>
18
class GlobalList {
19
 public:
20
  int len_;
21
  int capacity_;
22
  GlobalSlab<T, N>* slab_;
23
};
24
25
#define GLOBAL_LIST(name, T, N, array)                                         \
26
  GcGlobal<GlobalSlab<T, N>> _slab_##name = {ObjHeader::Global(TypeTag::Slab), \
27
                                             {.items_ = array}};               \
28
  GcGlobal<GlobalList<T, N>> _list_##name = {                                  \
29
      ObjHeader::Global(TypeTag::List),                                        \
30
      {.len_ = N, .capacity_ = N, .slab_ = &_slab_##name.obj}};                \
31
  List<T>* name = reinterpret_cast<List<T>*>(&_list_##name.obj);
32
33
template <typename T>
34
class List {
35
  // Relate slab size to number of items (capacity)
36
  // 8 / 4 = 2 items, or 8 / 8 = 1 item
37
  static const int kCapacityAdjust = kSlabHeaderSize / sizeof(T);
38
  static_assert(kSlabHeaderSize % sizeof(T) == 0,
39
                "Slab header size should be multiple of item size");
40
41
  // Relates to minimum Slab size.
42
  // Smallest non-empty List<T*>  should have about 4 items, or 3 without header
43
  // Smallest non-empty List<int> should have about 8 items, or 7 without header
44
  static const int kMinItems = 32 / sizeof(T);
45
  static_assert(32 % sizeof(T) == 0,
46
                "An integral number of items should fit in 32 bytes");
47
48
 public:
49
939
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
939
  }
_ZN4ListIP3StrEC2Ev
Line
Count
Source
49
168
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
168
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEEC2Ev
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEEC2Ev
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEEC2Ev
_ZN4ListIiEC2Ev
Line
Count
Source
49
675
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
675
  }
_ZN4ListIP6Tuple2IiP3StrEEC2Ev
Line
Count
Source
49
9
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
9
  }
_ZN4ListIP6Tuple2IP3StriEEC2Ev
Line
Count
Source
49
1
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
1
  }
_ZN4ListIPN10hnode_asdl5FieldEEC2Ev
Line
Count
Source
49
37
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev
Line
Count
Source
49
37
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
37
  }
_ZN4ListIbEC2Ev
Line
Count
Source
49
3
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
3
  }
_ZN4ListIP6Tuple2IiiEEC2Ev
Line
Count
Source
49
4
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
4
  }
_ZN4ListIPiEC2Ev
Line
Count
Source
49
2
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
2
  }
_ZN4ListIdEC2Ev
Line
Count
Source
49
2
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
2
  }
_ZN4ListIPN4pyos11PasswdEntryEEC2Ev
Line
Count
Source
49
1
  List() : len_(0), capacity_(0), slab_(nullptr) {
50
1
  }
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEEC2Ev
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEEC2Ev
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEEC2Ev
51
52
  // Implements L[i]
53
  T index_(int i);
54
55
  // returns index of the element
56
  int index(T element);
57
58
  // Implements L[i] = item
59
  void set(int i, T item);
60
61
  // L[begin:]
62
  List* slice(int begin);
63
64
  // L[begin:end]
65
  List* slice(int begin, int end);
66
67
  // L[begin:end:step]
68
  List* slice(int begin, int end, int step);
69
70
  // Should we have a separate API that doesn't return it?
71
  // https://stackoverflow.com/questions/12600330/pop-back-return-value
72
  T pop();
73
74
  // Used in osh/word_parse.py to remove from front
75
  T pop(int i);
76
77
  // Remove the first occourence of x from the list.
78
  void remove(T x);
79
80
  void clear();
81
82
  // Used in osh/string_ops.py
83
  void reverse();
84
85
  // Templated function
86
  void sort();
87
88
  // Ensure that there's space for a number of items
89
  void reserve(int n);
90
91
  // Append a single element to this list.
92
  void append(T item);
93
94
  // Extend this list with multiple elements.
95
  void extend(List<T>* other);
96
97
924
  static constexpr ObjHeader obj_header() {
98
924
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
924
  }
_ZN4ListIP3StrE10obj_headerEv
Line
Count
Source
97
168
  static constexpr ObjHeader obj_header() {
98
168
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
168
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE10obj_headerEv
_ZN4ListIiE10obj_headerEv
Line
Count
Source
97
664
  static constexpr ObjHeader obj_header() {
98
664
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
664
  }
_ZN4ListIP6Tuple2IP3StriEE10obj_headerEv
Line
Count
Source
97
1
  static constexpr ObjHeader obj_header() {
98
1
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
1
  }
_ZN4ListIP6Tuple2IiP3StrEE10obj_headerEv
Line
Count
Source
97
5
  static constexpr ObjHeader obj_header() {
98
5
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
5
  }
_ZN4ListIPN10hnode_asdl5FieldEE10obj_headerEv
Line
Count
Source
97
37
  static constexpr ObjHeader obj_header() {
98
37
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv
Line
Count
Source
97
37
  static constexpr ObjHeader obj_header() {
98
37
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
37
  }
_ZN4ListIbE10obj_headerEv
Line
Count
Source
97
3
  static constexpr ObjHeader obj_header() {
98
3
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
3
  }
_ZN4ListIP6Tuple2IiiEE10obj_headerEv
Line
Count
Source
97
4
  static constexpr ObjHeader obj_header() {
98
4
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
4
  }
_ZN4ListIPiE10obj_headerEv
Line
Count
Source
97
2
  static constexpr ObjHeader obj_header() {
98
2
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
2
  }
_ZN4ListIdE10obj_headerEv
Line
Count
Source
97
2
  static constexpr ObjHeader obj_header() {
98
2
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
2
  }
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12place_expr_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7VariantEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12class_item_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10ImportNameEE10obj_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_asdl10SourceLineEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl7value_tEE10obj_headerEv
_ZN4ListIPN4pyos11PasswdEntryEE10obj_headerEv
Line
Count
Source
97
1
  static constexpr ObjHeader obj_header() {
98
1
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
99
1
  }
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE10obj_headerEv
100
101
  int len_;       // number of entries
102
  int capacity_;  // max entries before resizing
103
104
  // The container may be resized, so this field isn't in-line.
105
  Slab<T>* slab_;
106
107
  // A list has one Slab pointer which we need to follow.
108
926
  static constexpr uint32_t field_mask() {
109
926
    return maskbit(offsetof(List, slab_));
110
926
  }
_ZN4ListIP3StrE10field_maskEv
Line
Count
Source
108
168
  static constexpr uint32_t field_mask() {
109
168
    return maskbit(offsetof(List, slab_));
110
168
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE10field_maskEv
_ZN4ListIiE10field_maskEv
Line
Count
Source
108
666
  static constexpr uint32_t field_mask() {
109
666
    return maskbit(offsetof(List, slab_));
110
666
  }
_ZN4ListIP6Tuple2IP3StriEE10field_maskEv
Line
Count
Source
108
1
  static constexpr uint32_t field_mask() {
109
1
    return maskbit(offsetof(List, slab_));
110
1
  }
_ZN4ListIP6Tuple2IiP3StrEE10field_maskEv
Line
Count
Source
108
5
  static constexpr uint32_t field_mask() {
109
5
    return maskbit(offsetof(List, slab_));
110
5
  }
_ZN4ListIPN10hnode_asdl5FieldEE10field_maskEv
Line
Count
Source
108
37
  static constexpr uint32_t field_mask() {
109
37
    return maskbit(offsetof(List, slab_));
110
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv
Line
Count
Source
108
37
  static constexpr uint32_t field_mask() {
109
37
    return maskbit(offsetof(List, slab_));
110
37
  }
_ZN4ListIbE10field_maskEv
Line
Count
Source
108
3
  static constexpr uint32_t field_mask() {
109
3
    return maskbit(offsetof(List, slab_));
110
3
  }
_ZN4ListIP6Tuple2IiiEE10field_maskEv
Line
Count
Source
108
4
  static constexpr uint32_t field_mask() {
109
4
    return maskbit(offsetof(List, slab_));
110
4
  }
_ZN4ListIPiE10field_maskEv
Line
Count
Source
108
2
  static constexpr uint32_t field_mask() {
109
2
    return maskbit(offsetof(List, slab_));
110
2
  }
_ZN4ListIdE10field_maskEv
Line
Count
Source
108
2
  static constexpr uint32_t field_mask() {
109
2
    return maskbit(offsetof(List, slab_));
110
2
  }
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9AssocPairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7EnvPairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5RedirEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10AssignPairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5IfArmEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7CaseArmEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8NameTypeEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12place_expr_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5ParamEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8TypeExprEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7VariantEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12class_item_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10ImportNameEE10field_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_asdl10SourceLineEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl9AssignArgEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl7value_tEE10field_maskEv
_ZN4ListIPN4pyos11PasswdEntryEE10field_maskEv
Line
Count
Source
108
1
  static constexpr uint32_t field_mask() {
109
1
    return maskbit(offsetof(List, slab_));
110
1
  }
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE10field_maskEv
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE10field_maskEv
111
112
  DISALLOW_COPY_AND_ASSIGN(List)
113
114
 private:
115
937
  int RoundCapacity(int n) {
116
937
    if (n < kMinItems) {
117
860
      return kMinItems;
118
860
    }
119
77
    return RoundUp(n);
120
937
  }
_ZN4ListIP3StrE13RoundCapacityEi
Line
Count
Source
115
185
  int RoundCapacity(int n) {
116
185
    if (n < kMinItems) {
117
139
      return kMinItems;
118
139
    }
119
46
    return RoundUp(n);
120
185
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE13RoundCapacityEi
_ZN4ListIiE13RoundCapacityEi
Line
Count
Source
115
690
  int RoundCapacity(int n) {
116
690
    if (n < kMinItems) {
117
668
      return kMinItems;
118
668
    }
119
22
    return RoundUp(n);
120
690
  }
_ZN4ListIP6Tuple2IiP3StrEE13RoundCapacityEi
Line
Count
Source
115
9
  int RoundCapacity(int n) {
116
9
    if (n < kMinItems) {
117
7
      return kMinItems;
118
7
    }
119
2
    return RoundUp(n);
120
9
  }
_ZN4ListIP6Tuple2IP3StriEE13RoundCapacityEi
Line
Count
Source
115
1
  int RoundCapacity(int n) {
116
1
    if (n < kMinItems) {
117
1
      return kMinItems;
118
1
    }
119
0
    return RoundUp(n);
120
1
  }
_ZN4ListIPN10hnode_asdl5FieldEE13RoundCapacityEi
Line
Count
Source
115
37
  int RoundCapacity(int n) {
116
37
    if (n < kMinItems) {
117
37
      return kMinItems;
118
37
    }
119
0
    return RoundUp(n);
120
37
  }
_ZN4ListIbE13RoundCapacityEi
Line
Count
Source
115
3
  int RoundCapacity(int n) {
116
3
    if (n < kMinItems) {
117
3
      return kMinItems;
118
3
    }
119
0
    return RoundUp(n);
120
3
  }
_ZN4ListIP6Tuple2IiiEE13RoundCapacityEi
Line
Count
Source
115
4
  int RoundCapacity(int n) {
116
4
    if (n < kMinItems) {
117
4
      return kMinItems;
118
4
    }
119
0
    return RoundUp(n);
120
4
  }
_ZN4ListIdE13RoundCapacityEi
Line
Count
Source
115
2
  int RoundCapacity(int n) {
116
2
    if (n < kMinItems) {
117
0
      return kMinItems;
118
0
    }
119
2
    return RoundUp(n);
120
2
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE13RoundCapacityEi
_ZN4ListIPN4pyos11PasswdEntryEE13RoundCapacityEi
Line
Count
Source
115
6
  int RoundCapacity(int n) {
116
6
    if (n < kMinItems) {
117
1
      return kMinItems;
118
1
    }
119
5
    return RoundUp(n);
120
6
  }
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE13RoundCapacityEi
121
};
122
123
// "Constructors" as free functions since we can't allocate within a
124
// constructor.  Allocation may cause garbage collection, which interferes with
125
// placement new.
126
127
// This is not really necessary, only syntactic sugar.
128
template <typename T>
129
656
List<T>* NewList() {
130
656
  return Alloc<List<T>>();
131
656
}
_Z7NewListIP3StrEP4ListIT_Ev
Line
Count
Source
129
26
List<T>* NewList() {
130
26
  return Alloc<List<T>>();
131
26
}
_Z7NewListIiEP4ListIT_Ev
Line
Count
Source
129
624
List<T>* NewList() {
130
624
  return Alloc<List<T>>();
131
624
}
_Z7NewListIPiEP4ListIT_Ev
Line
Count
Source
129
2
List<T>* NewList() {
130
2
  return Alloc<List<T>>();
131
2
}
_Z7NewListIPN4pyos11PasswdEntryEEP4ListIT_Ev
Line
Count
Source
129
1
List<T>* NewList() {
130
1
  return Alloc<List<T>>();
131
1
}
Unexecuted instantiation: _Z7NewListIPN11syntax_asdl12CompoundWordEEP4ListIT_Ev
_Z7NewListIP6Tuple2IiP3StrEEP4ListIT_Ev
Line
Count
Source
129
3
List<T>* NewList() {
130
3
  return Alloc<List<T>>();
131
3
}
132
133
// Literal ['foo', 'bar']
134
// This seems to allow better template argument type deduction than a
135
// constructor.
136
template <typename T>
137
94
List<T>* NewList(std::initializer_list<T> init) {
138
94
  auto self = Alloc<List<T>>();
139
140
94
  int n = init.size();
141
94
  self->reserve(n);
142
143
94
  int i = 0;
144
174
  for (auto item : init) {
145
174
    self->set(i, item);
146
174
    ++i;
147
174
  }
148
94
  self->len_ = n;
149
94
  return self;
150
94
}
_Z7NewListIP3StrEP4ListIT_ESt16initializer_listIS3_E
Line
Count
Source
137
61
List<T>* NewList(std::initializer_list<T> init) {
138
61
  auto self = Alloc<List<T>>();
139
140
61
  int n = init.size();
141
61
  self->reserve(n);
142
143
61
  int i = 0;
144
69
  for (auto item : init) {
145
69
    self->set(i, item);
146
69
    ++i;
147
69
  }
148
61
  self->len_ = n;
149
61
  return self;
150
61
}
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
137
28
List<T>* NewList(std::initializer_list<T> init) {
138
28
  auto self = Alloc<List<T>>();
139
140
28
  int n = init.size();
141
28
  self->reserve(n);
142
143
28
  int i = 0;
144
93
  for (auto item : init) {
145
93
    self->set(i, item);
146
93
    ++i;
147
93
  }
148
28
  self->len_ = n;
149
28
  return self;
150
28
}
_Z7NewListIP6Tuple2IP3StriEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
137
1
List<T>* NewList(std::initializer_list<T> init) {
138
1
  auto self = Alloc<List<T>>();
139
140
1
  int n = init.size();
141
1
  self->reserve(n);
142
143
1
  int i = 0;
144
2
  for (auto item : init) {
145
2
    self->set(i, item);
146
2
    ++i;
147
2
  }
148
1
  self->len_ = n;
149
1
  return self;
150
1
}
_Z7NewListIP6Tuple2IiP3StrEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
137
1
List<T>* NewList(std::initializer_list<T> init) {
138
1
  auto self = Alloc<List<T>>();
139
140
1
  int n = init.size();
141
1
  self->reserve(n);
142
143
1
  int i = 0;
144
2
  for (auto item : init) {
145
2
    self->set(i, item);
146
2
    ++i;
147
2
  }
148
1
  self->len_ = n;
149
1
  return self;
150
1
}
_Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
137
1
List<T>* NewList(std::initializer_list<T> init) {
138
1
  auto self = Alloc<List<T>>();
139
140
1
  int n = init.size();
141
1
  self->reserve(n);
142
143
1
  int i = 0;
144
2
  for (auto item : init) {
145
2
    self->set(i, item);
146
2
    ++i;
147
2
  }
148
1
  self->len_ = n;
149
1
  return self;
150
1
}
_Z7NewListIdEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
137
2
List<T>* NewList(std::initializer_list<T> init) {
138
2
  auto self = Alloc<List<T>>();
139
140
2
  int n = init.size();
141
2
  self->reserve(n);
142
143
2
  int i = 0;
144
6
  for (auto item : init) {
145
6
    self->set(i, item);
146
6
    ++i;
147
6
  }
148
2
  self->len_ = n;
149
2
  return self;
150
2
}
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E
Unexecuted instantiation: _Z7NewListIP6Tuple2IiiEEP4ListIT_ESt16initializer_listIS4_E
151
152
// ['foo'] * 3
153
template <typename T>
154
9
List<T>* NewList(T item, int times) {
155
9
  auto self = Alloc<List<T>>();
156
157
9
  self->reserve(times);
158
9
  self->len_ = times;
159
36
  for (int i = 0; i < times; ++i) {
160
27
    self->set(i, item);
161
27
  }
162
9
  return self;
163
9
}
_Z7NewListIP3StrEP4ListIT_ES3_i
Line
Count
Source
154
3
List<T>* NewList(T item, int times) {
155
3
  auto self = Alloc<List<T>>();
156
157
3
  self->reserve(times);
158
3
  self->len_ = times;
159
12
  for (int i = 0; i < times; ++i) {
160
9
    self->set(i, item);
161
9
  }
162
3
  return self;
163
3
}
_Z7NewListIbEP4ListIT_ES1_i
Line
Count
Source
154
2
List<T>* NewList(T item, int times) {
155
2
  auto self = Alloc<List<T>>();
156
157
2
  self->reserve(times);
158
2
  self->len_ = times;
159
8
  for (int i = 0; i < times; ++i) {
160
6
    self->set(i, item);
161
6
  }
162
2
  return self;
163
2
}
_Z7NewListIiEP4ListIT_ES1_i
Line
Count
Source
154
4
List<T>* NewList(T item, int times) {
155
4
  auto self = Alloc<List<T>>();
156
157
4
  self->reserve(times);
158
4
  self->len_ = times;
159
16
  for (int i = 0; i < times; ++i) {
160
12
    self->set(i, item);
161
12
  }
162
4
  return self;
163
4
}
164
165
template <typename T>
166
6.73k
void List<T>::append(T item) {
167
6.73k
  reserve(len_ + 1);
168
6.73k
  slab_->items_[len_] = item;
169
6.73k
  ++len_;
170
6.73k
}
_ZN4ListIP3StrE6appendES1_
Line
Count
Source
166
435
void List<T>::append(T item) {
167
435
  reserve(len_ + 1);
168
435
  slab_->items_[len_] = item;
169
435
  ++len_;
170
435
}
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE6appendES2_
_ZN4ListIiE6appendEi
Line
Count
Source
166
6.12k
void List<T>::append(T item) {
167
6.12k
  reserve(len_ + 1);
168
6.12k
  slab_->items_[len_] = item;
169
6.12k
  ++len_;
170
6.12k
}
_ZN4ListIP6Tuple2IiP3StrEE6appendES4_
Line
Count
Source
166
20
void List<T>::append(T item) {
167
20
  reserve(len_ + 1);
168
20
  slab_->items_[len_] = item;
169
20
  ++len_;
170
20
}
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StriEE6appendES4_
_ZN4ListIPN10hnode_asdl5FieldEE6appendES2_
Line
Count
Source
166
65
void List<T>::append(T item) {
167
65
  reserve(len_ + 1);
168
65
  slab_->items_[len_] = item;
169
65
  ++len_;
170
65
}
_ZN4ListIP6Tuple2IiiEE6appendES2_
Line
Count
Source
166
8
void List<T>::append(T item) {
167
8
  reserve(len_ + 1);
168
8
  slab_->items_[len_] = item;
169
8
  ++len_;
170
8
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_
_ZN4ListIPN4pyos11PasswdEntryEE6appendES2_
Line
Count
Source
166
76
void List<T>::append(T item) {
167
76
  reserve(len_ + 1);
168
76
  slab_->items_[len_] = item;
169
76
  ++len_;
170
76
}
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE6appendES4_
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE6appendES2_
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE6appendES4_
171
172
template <typename T>
173
4.15k
int len(const List<T>* L) {
174
4.15k
  return L->len_;
175
4.15k
}
_Z3lenIiEiPK4ListIT_E
Line
Count
Source
173
3.90k
int len(const List<T>* L) {
174
3.90k
  return L->len_;
175
3.90k
}
_Z3lenIP3StrEiPK4ListIT_E
Line
Count
Source
173
231
int len(const List<T>* L) {
174
231
  return L->len_;
175
231
}
Unexecuted instantiation: _Z3lenIPN10classes_gc10OpaqueBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN10classes_gc12PointersBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN10classes_gc14BaseWithMethodEEiPK4ListIT_E
_Z3lenIP6Tuple2IiP3StrEEiPK4ListIT_E
Line
Count
Source
173
7
int len(const List<T>* L) {
174
7
  return L->len_;
175
7
}
_Z3lenIP6Tuple2IiiEEiPK4ListIT_E
Line
Count
Source
173
2
int len(const List<T>* L) {
174
2
  return L->len_;
175
2
}
_Z3lenIbEiPK4ListIT_E
Line
Count
Source
173
2
int len(const List<T>* L) {
174
2
  return L->len_;
175
2
}
_Z3lenIdEiPK4ListIT_E
Line
Count
Source
173
4
int len(const List<T>* L) {
174
4
  return L->len_;
175
4
}
176
177
template <typename T>
178
List<T>* list_repeat(T item, int times);
179
180
template <typename T>
181
inline bool list_contains(List<T>* haystack, T needle);
182
183
template <typename K, typename V>
184
class Dict;  // forward decl
185
186
template <typename V>
187
List<Str*>* sorted(Dict<Str*, V>* d);
188
189
template <typename T>
190
List<T>* sorted(List<T>* l);
191
192
// L[begin:]
193
// TODO: Implement this in terms of slice(begin, end)
194
template <typename T>
195
606
List<T>* List<T>::slice(int begin) {
196
606
  if (begin < 0) {
197
0
    begin = len_ + begin;
198
0
  }
199
200
606
  DCHECK(begin >= 0);
201
202
0
  List<T>* result = nullptr;
203
606
  result = NewList<T>();
204
205
3.02k
  for (int i = begin; i < len_; i++) {
206
2.41k
    result->append(slab_->items_[i]);
207
2.41k
  }
208
209
606
  return result;
210
606
}
_ZN4ListIP3StrE5sliceEi
Line
Count
Source
195
3
List<T>* List<T>::slice(int begin) {
196
3
  if (begin < 0) {
197
0
    begin = len_ + begin;
198
0
  }
199
200
3
  DCHECK(begin >= 0);
201
202
0
  List<T>* result = nullptr;
203
3
  result = NewList<T>();
204
205
9
  for (int i = begin; i < len_; i++) {
206
6
    result->append(slab_->items_[i]);
207
6
  }
208
209
3
  return result;
210
3
}
_ZN4ListIiE5sliceEi
Line
Count
Source
195
603
List<T>* List<T>::slice(int begin) {
196
603
  if (begin < 0) {
197
0
    begin = len_ + begin;
198
0
  }
199
200
603
  DCHECK(begin >= 0);
201
202
0
  List<T>* result = nullptr;
203
603
  result = NewList<T>();
204
205
3.01k
  for (int i = begin; i < len_; i++) {
206
2.40k
    result->append(slab_->items_[i]);
207
2.40k
  }
208
209
603
  return result;
210
603
}
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE5sliceEi
211
212
// L[begin:end]
213
template <typename T>
214
3
List<T>* List<T>::slice(int begin, int end) {
215
3
  return slice(begin, end, 1);
216
3
}
217
218
// L[begin:end:step]
219
template <typename T>
220
6
List<T>* List<T>::slice(int begin, int end, int step) {
221
6
  if (begin < 0) {
222
2
    begin = len_ + begin;
223
2
  }
224
6
  if (end < 0) {
225
3
    end = len_ + end;
226
3
  }
227
228
6
  DCHECK(end <= len_);
229
6
  DCHECK(begin >= 0);
230
6
  DCHECK(end >= 0);
231
232
0
  List<T>* result = NewList<T>();
233
  // step might be negative
234
18
  for (int i = begin; begin <= i && i < end; i += step) {
235
12
    result->append(slab_->items_[i]);
236
12
  }
237
238
6
  return result;
239
6
}
240
241
// Ensure that there's space for a number of items
242
template <typename T>
243
6.85k
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
6.85k
  if (capacity_ >= n) {
248
5.91k
    return;
249
5.91k
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
937
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
937
  auto new_slab = NewSlab<T>(capacity_);
261
262
937
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
58
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
58
  }
266
937
  slab_ = new_slab;
267
937
}
_ZN4ListIP3StrE7reserveEi
Line
Count
Source
243
501
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
501
  if (capacity_ >= n) {
248
316
    return;
249
316
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
185
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
185
  auto new_slab = NewSlab<T>(capacity_);
261
262
185
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
33
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
33
  }
266
185
  slab_ = new_slab;
267
185
}
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE7reserveEi
_ZN4ListIiE7reserveEi
Line
Count
Source
243
6.17k
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
6.17k
  if (capacity_ >= n) {
248
5.48k
    return;
249
5.48k
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
690
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
690
  auto new_slab = NewSlab<T>(capacity_);
261
262
690
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
18
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
18
  }
266
690
  slab_ = new_slab;
267
690
}
_ZN4ListIP6Tuple2IiP3StrEE7reserveEi
Line
Count
Source
243
21
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
21
  if (capacity_ >= n) {
248
12
    return;
249
12
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
9
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
9
  auto new_slab = NewSlab<T>(capacity_);
261
262
9
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
2
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
2
  }
266
9
  slab_ = new_slab;
267
9
}
_ZN4ListIP6Tuple2IP3StriEE7reserveEi
Line
Count
Source
243
1
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
1
  if (capacity_ >= n) {
248
0
    return;
249
0
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
1
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
1
  auto new_slab = NewSlab<T>(capacity_);
261
262
1
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
0
  }
266
1
  slab_ = new_slab;
267
1
}
_ZN4ListIPN10hnode_asdl5FieldEE7reserveEi
Line
Count
Source
243
65
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
65
  if (capacity_ >= n) {
248
28
    return;
249
28
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
37
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
37
  auto new_slab = NewSlab<T>(capacity_);
261
262
37
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
0
  }
266
37
  slab_ = new_slab;
267
37
}
_ZN4ListIbE7reserveEi
Line
Count
Source
243
3
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
3
  if (capacity_ >= n) {
248
0
    return;
249
0
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
3
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
3
  auto new_slab = NewSlab<T>(capacity_);
261
262
3
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
0
  }
266
3
  slab_ = new_slab;
267
3
}
_ZN4ListIP6Tuple2IiiEE7reserveEi
Line
Count
Source
243
8
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
8
  if (capacity_ >= n) {
248
4
    return;
249
4
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
4
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
4
  auto new_slab = NewSlab<T>(capacity_);
261
262
4
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
0
  }
266
4
  slab_ = new_slab;
267
4
}
_ZN4ListIdE7reserveEi
Line
Count
Source
243
2
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
2
  if (capacity_ >= n) {
248
0
    return;
249
0
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
2
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
2
  auto new_slab = NewSlab<T>(capacity_);
261
262
2
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
0
  }
266
2
  slab_ = new_slab;
267
2
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi
_ZN4ListIPN4pyos11PasswdEntryEE7reserveEi
Line
Count
Source
243
76
void List<T>::reserve(int n) {
244
  // log("reserve capacity = %d, n = %d", capacity_, n);
245
246
  // Don't do anything if there's already enough space.
247
76
  if (capacity_ >= n) {
248
70
    return;
249
70
  }
250
251
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
252
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
253
  // List<int>.
254
  //
255
  // Example: the user reserves space for 3 integers.  The minimum number of
256
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
257
  // which leads to 8 + 6*4 = 32 byte Slab.
258
259
6
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
260
6
  auto new_slab = NewSlab<T>(capacity_);
261
262
6
  if (len_ > 0) {
263
    // log("Copying %d bytes", len_ * sizeof(T));
264
5
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
265
5
  }
266
6
  slab_ = new_slab;
267
6
}
Unexecuted instantiation: _ZN4ListIPS_IP6Tuple2IiiEEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE7reserveEi
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE7reserveEi
268
269
// Implements L[i] = item
270
template <typename T>
271
253
void List<T>::set(int i, T item) {
272
253
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
253
  DCHECK(i >= 0);
277
253
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
253
}
_ZN4ListIP3StrE3setEiS1_
Line
Count
Source
271
90
void List<T>::set(int i, T item) {
272
90
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
90
  DCHECK(i >= 0);
277
90
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
90
}
_ZN4ListIiE3setEii
Line
Count
Source
271
145
void List<T>::set(int i, T item) {
272
145
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
145
  DCHECK(i >= 0);
277
145
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
145
}
_ZN4ListIP6Tuple2IP3StriEE3setEiS4_
Line
Count
Source
271
2
void List<T>::set(int i, T item) {
272
2
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
2
  DCHECK(i >= 0);
277
2
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
2
}
_ZN4ListIP6Tuple2IiP3StrEE3setEiS4_
Line
Count
Source
271
2
void List<T>::set(int i, T item) {
272
2
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
2
  DCHECK(i >= 0);
277
2
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
2
}
_ZN4ListIbE3setEib
Line
Count
Source
271
8
void List<T>::set(int i, T item) {
272
8
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
8
  DCHECK(i >= 0);
277
8
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
8
}
_ZN4ListIdE3setEid
Line
Count
Source
271
6
void List<T>::set(int i, T item) {
272
6
  if (i < 0) {
273
0
    i = len_ + i;
274
0
  }
275
276
6
  DCHECK(i >= 0);
277
6
  DCHECK(i < capacity_);
278
279
0
  slab_->items_[i] = item;
280
6
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_
Unexecuted instantiation: _ZN4ListIP6Tuple2IiiEE3setEiS2_
281
282
// Implements L[i]
283
template <typename T>
284
873
T List<T>::index_(int i) {
285
873
  if (i < 0) {
286
4
    int j = len_ + i;
287
4
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
4
    return slab_->items_[j];
291
4
  }
292
293
869
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
869
  return slab_->items_[i];
297
869
}
_ZN4ListIiE6index_Ei
Line
Count
Source
284
180
T List<T>::index_(int i) {
285
180
  if (i < 0) {
286
1
    int j = len_ + i;
287
1
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
1
    return slab_->items_[j];
291
1
  }
292
293
179
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
179
  return slab_->items_[i];
297
179
}
_ZN4ListIP3StrE6index_Ei
Line
Count
Source
284
676
T List<T>::index_(int i) {
285
676
  if (i < 0) {
286
3
    int j = len_ + i;
287
3
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
3
    return slab_->items_[j];
291
3
  }
292
293
673
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
673
  return slab_->items_[i];
297
673
}
_ZN4ListIbE6index_Ei
Line
Count
Source
284
4
T List<T>::index_(int i) {
285
4
  if (i < 0) {
286
0
    int j = len_ + i;
287
0
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
0
    return slab_->items_[j];
291
0
  }
292
293
4
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
4
  return slab_->items_[i];
297
4
}
_ZN4ListIdE6index_Ei
Line
Count
Source
284
8
T List<T>::index_(int i) {
285
8
  if (i < 0) {
286
0
    int j = len_ + i;
287
0
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
0
    return slab_->items_[j];
291
0
  }
292
293
8
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
8
  return slab_->items_[i];
297
8
}
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12CompoundWordEE6index_Ei
_ZN4ListIP6Tuple2IiP3StrEE6index_Ei
Line
Count
Source
284
5
T List<T>::index_(int i) {
285
5
  if (i < 0) {
286
0
    int j = len_ + i;
287
0
    if (j >= len_ || j < 0) {
288
0
      throw Alloc<IndexError>();
289
0
    }
290
0
    return slab_->items_[j];
291
0
  }
292
293
5
  if (i >= len_ || i < 0) {
294
0
    throw Alloc<IndexError>();
295
0
  }
296
5
  return slab_->items_[i];
297
5
}
298
299
// L.index(i) -- Python method
300
template <typename T>
301
8
int List<T>::index(T value) {
302
8
  int element_count = len(this);
303
18
  for (int i = 0; i < element_count; i++) {
304
16
    if (are_equal(slab_->items_[i], value)) {
305
6
      return i;
306
6
    }
307
16
  }
308
2
  throw Alloc<ValueError>();
309
8
}
310
311
// Should we have a separate API that doesn't return it?
312
// https://stackoverflow.com/questions/12600330/pop-back-return-value
313
template <typename T>
314
7
T List<T>::pop() {
315
7
  if (len_ == 0) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
7
  len_--;
319
7
  T result = slab_->items_[len_];
320
7
  slab_->items_[len_] = 0;  // zero for GC scan
321
7
  return result;
322
7
}
_ZN4ListIP3StrE3popEv
Line
Count
Source
314
5
T List<T>::pop() {
315
5
  if (len_ == 0) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
5
  len_--;
319
5
  T result = slab_->items_[len_];
320
5
  slab_->items_[len_] = 0;  // zero for GC scan
321
5
  return result;
322
5
}
_ZN4ListIiE3popEv
Line
Count
Source
314
2
T List<T>::pop() {
315
2
  if (len_ == 0) {
316
0
    throw Alloc<IndexError>();
317
0
  }
318
2
  len_--;
319
2
  T result = slab_->items_[len_];
320
2
  slab_->items_[len_] = 0;  // zero for GC scan
321
2
  return result;
322
2
}
323
324
// Used in osh/word_parse.py to remove from front
325
template <typename T>
326
10
T List<T>::pop(int i) {
327
10
  if (len_ < i) {
328
0
    throw Alloc<IndexError>();
329
0
  }
330
331
10
  T result = index_(i);
332
10
  len_--;
333
334
  // Shift everything by one
335
10
  memmove(slab_->items_ + i, slab_->items_ + (i + 1), len_ * sizeof(T));
336
337
  /*
338
  for (int j = 0; j < len_; j++) {
339
    slab_->items_[j] = slab_->items_[j+1];
340
  }
341
  */
342
343
10
  slab_->items_[len_] = 0;  // zero for GC scan
344
10
  return result;
345
10
}
346
347
template <typename T>
348
6
void List<T>::remove(T x) {
349
6
  int idx = this->index(x);
350
6
  this->pop(idx);  // unused
351
6
}
352
353
template <typename T>
354
7
void List<T>::clear() {
355
7
  if (slab_) {
356
4
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
357
4
  }
358
7
  len_ = 0;
359
7
}
_ZN4ListIiE5clearEv
Line
Count
Source
354
4
void List<T>::clear() {
355
4
  if (slab_) {
356
4
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
357
4
  }
358
4
  len_ = 0;
359
4
}
_ZN4ListIP3StrE5clearEv
Line
Count
Source
354
1
void List<T>::clear() {
355
1
  if (slab_) {
356
0
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
357
0
  }
358
1
  len_ = 0;
359
1
}
_ZN4ListIPiE5clearEv
Line
Count
Source
354
2
void List<T>::clear() {
355
2
  if (slab_) {
356
0
    memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
357
0
  }
358
2
  len_ = 0;
359
2
}
360
361
// Used in osh/string_ops.py
362
template <typename T>
363
8
void List<T>::reverse() {
364
16
  for (int i = 0; i < len_ / 2; ++i) {
365
    // log("swapping %d and %d", i, n-i);
366
8
    T tmp = slab_->items_[i];
367
8
    int j = len_ - 1 - i;
368
8
    slab_->items_[i] = slab_->items_[j];
369
8
    slab_->items_[j] = tmp;
370
8
  }
371
8
}
Unexecuted instantiation: _ZN4ListIP3StrE7reverseEv
_ZN4ListIiE7reverseEv
Line
Count
Source
363
8
void List<T>::reverse() {
364
16
  for (int i = 0; i < len_ / 2; ++i) {
365
    // log("swapping %d and %d", i, n-i);
366
8
    T tmp = slab_->items_[i];
367
8
    int j = len_ - 1 - i;
368
8
    slab_->items_[i] = slab_->items_[j];
369
8
    slab_->items_[j] = tmp;
370
8
  }
371
8
}
372
373
// Extend this list with multiple elements.
374
template <typename T>
375
13
void List<T>::extend(List<T>* other) {
376
13
  int n = other->len_;
377
13
  int new_len = len_ + n;
378
13
  reserve(new_len);
379
380
54
  for (int i = 0; i < n; ++i) {
381
41
    set(len_ + i, other->slab_->items_[i]);
382
41
  }
383
13
  len_ = new_len;
384
13
}
_ZN4ListIiE6extendEPS0_
Line
Count
Source
375
11
void List<T>::extend(List<T>* other) {
376
11
  int n = other->len_;
377
11
  int new_len = len_ + n;
378
11
  reserve(new_len);
379
380
46
  for (int i = 0; i < n; ++i) {
381
35
    set(len_ + i, other->slab_->items_[i]);
382
35
  }
383
11
  len_ = new_len;
384
11
}
_ZN4ListIP3StrE6extendEPS2_
Line
Count
Source
375
2
void List<T>::extend(List<T>* other) {
376
2
  int n = other->len_;
377
2
  int new_len = len_ + n;
378
2
  reserve(new_len);
379
380
8
  for (int i = 0; i < n; ++i) {
381
6
    set(len_ + i, other->slab_->items_[i]);
382
6
  }
383
2
  len_ = new_len;
384
2
}
385
386
34
inline bool _cmp(Str* a, Str* b) {
387
34
  return mylib::str_cmp(a, b) < 0;
388
34
}
389
390
template <typename T>
391
8
void List<T>::sort() {
392
8
  std::sort(slab_->items_, slab_->items_ + len_, _cmp);
393
8
}
394
395
// TODO: mycpp can just generate the constructor instead?
396
// e.g. [None] * 3
397
template <typename T>
398
5
List<T>* list_repeat(T item, int times) {
399
5
  return NewList<T>(item, times);
400
5
}
_Z11list_repeatIP3StrEP4ListIT_ES3_i
Line
Count
Source
398
3
List<T>* list_repeat(T item, int times) {
399
3
  return NewList<T>(item, times);
400
3
}
_Z11list_repeatIbEP4ListIT_ES1_i
Line
Count
Source
398
2
List<T>* list_repeat(T item, int times) {
399
2
  return NewList<T>(item, times);
400
2
}
401
402
// e.g. 'a' in ['a', 'b', 'c']
403
template <typename T>
404
24
inline bool list_contains(List<T>* haystack, T needle) {
405
24
  int n = len(haystack);
406
57
  for (int i = 0; i < n; ++i) {
407
47
    if (are_equal(haystack->index_(i), needle)) {
408
14
      return true;
409
14
    }
410
47
  }
411
10
  return false;
412
24
}
_Z13list_containsIiEbP4ListIT_ES1_
Line
Count
Source
404
8
inline bool list_contains(List<T>* haystack, T needle) {
405
8
  int n = len(haystack);
406
19
  for (int i = 0; i < n; ++i) {
407
16
    if (are_equal(haystack->index_(i), needle)) {
408
5
      return true;
409
5
    }
410
16
  }
411
3
  return false;
412
8
}
_Z13list_containsIP3StrEbP4ListIT_ES3_
Line
Count
Source
404
12
inline bool list_contains(List<T>* haystack, T needle) {
405
12
  int n = len(haystack);
406
28
  for (int i = 0; i < n; ++i) {
407
23
    if (are_equal(haystack->index_(i), needle)) {
408
7
      return true;
409
7
    }
410
23
  }
411
5
  return false;
412
12
}
_Z13list_containsIdEbP4ListIT_ES1_
Line
Count
Source
404
4
inline bool list_contains(List<T>* haystack, T needle) {
405
4
  int n = len(haystack);
406
10
  for (int i = 0; i < n; ++i) {
407
8
    if (are_equal(haystack->index_(i), needle)) {
408
2
      return true;
409
2
    }
410
8
  }
411
2
  return false;
412
4
}
413
414
template <typename V>
415
2
List<Str*>* sorted(Dict<Str*, V>* d) {
416
2
  auto keys = d->keys();
417
2
  keys->sort();
418
2
  return keys;
419
2
}
420
421
template <typename T>
422
2
List<T>* sorted(List<T>* l) {
423
2
  auto ret = list(l);
424
2
  ret->sort();
425
2
  return ret;
426
2
}
427
428
// list(L) copies the list
429
template <typename T>
430
7
List<T>* list(List<T>* other) {
431
7
  auto result = NewList<T>();
432
7
  result->extend(other);
433
7
  return result;
434
7
}
_Z4listIiEP4ListIT_ES3_
Line
Count
Source
430
5
List<T>* list(List<T>* other) {
431
5
  auto result = NewList<T>();
432
5
  result->extend(other);
433
5
  return result;
434
5
}
_Z4listIP3StrEP4ListIT_ES5_
Line
Count
Source
430
2
List<T>* list(List<T>* other) {
431
2
  auto result = NewList<T>();
432
2
  result->extend(other);
433
2
  return result;
434
2
}
435
436
template <class T>
437
class ListIter {
438
 public:
439
156
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
156
  }
_ZN8ListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
439
40
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
40
  }
_ZN8ListIterIiEC2EP4ListIiE
Line
Count
Source
439
21
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
21
  }
_ZN8ListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
439
6
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
6
  }
_ZN8ListIterIP6Tuple2IP3StriEEC2EP4ListIS4_E
Line
Count
Source
439
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
1
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E
_ZN8ListIterIPN10hnode_asdl5FieldEEC2EP4ListIS2_E
Line
Count
Source
439
82
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
82
  }
_ZN8ListIterIbEC2EP4ListIbE
Line
Count
Source
439
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
1
  }
_ZN8ListIterIP6Tuple2IiiEEC2EP4ListIS2_E
Line
Count
Source
439
4
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
4
  }
_ZN8ListIterIPN4pyos11PasswdEntryEEC2EP4ListIS2_E
Line
Count
Source
439
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
440
    // Cheney only: L_ could be moved during iteration.
441
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
442
1
  }
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEEC2EP4ListIS2_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_asdl5RedirEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7VariantEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10ImportNameEEC2EP4ListIS2_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
443
444
159
  ~ListIter() {
445
    // gHeap.PopRoot();
446
159
  }
_ZN8ListIterIP3StrED2Ev
Line
Count
Source
444
40
  ~ListIter() {
445
    // gHeap.PopRoot();
446
40
  }
_ZN8ListIterIiED2Ev
Line
Count
Source
444
24
  ~ListIter() {
445
    // gHeap.PopRoot();
446
24
  }
_ZN8ListIterIP6Tuple2IiP3StrEED2Ev
Line
Count
Source
444
6
  ~ListIter() {
445
    // gHeap.PopRoot();
446
6
  }
_ZN8ListIterIP6Tuple2IP3StriEED2Ev
Line
Count
Source
444
1
  ~ListIter() {
445
    // gHeap.PopRoot();
446
1
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev
_ZN8ListIterIPN10hnode_asdl5FieldEED2Ev
Line
Count
Source
444
82
  ~ListIter() {
445
    // gHeap.PopRoot();
446
82
  }
_ZN8ListIterIbED2Ev
Line
Count
Source
444
1
  ~ListIter() {
445
    // gHeap.PopRoot();
446
1
  }
_ZN8ListIterIP6Tuple2IiiEED2Ev
Line
Count
Source
444
4
  ~ListIter() {
445
    // gHeap.PopRoot();
446
4
  }
_ZN8ListIterIPN4pyos11PasswdEntryEED2Ev
Line
Count
Source
444
1
  ~ListIter() {
445
    // gHeap.PopRoot();
446
1
  }
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev
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_asdl5RedirEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7VariantEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10ImportNameEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEED2Ev
447
402
  void Next() {
448
402
    i_++;
449
402
  }
_ZN8ListIterIP3StrE4NextEv
Line
Count
Source
447
148
  void Next() {
448
148
    i_++;
449
148
  }
_ZN8ListIterIiE4NextEv
Line
Count
Source
447
61
  void Next() {
448
61
    i_++;
449
61
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
447
18
  void Next() {
448
18
    i_++;
449
18
  }
_ZN8ListIterIP6Tuple2IP3StriEE4NextEv
Line
Count
Source
447
2
  void Next() {
448
2
    i_++;
449
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv
_ZN8ListIterIPN10hnode_asdl5FieldEE4NextEv
Line
Count
Source
447
123
  void Next() {
448
123
    i_++;
449
123
  }
_ZN8ListIterIbE4NextEv
Line
Count
Source
447
2
  void Next() {
448
2
    i_++;
449
2
  }
_ZN8ListIterIP6Tuple2IiiEE4NextEv
Line
Count
Source
447
8
  void Next() {
448
8
    i_++;
449
8
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE4NextEv
Line
Count
Source
447
40
  void Next() {
448
40
    i_++;
449
40
  }
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv
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_asdl5RedirEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7VariantEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10ImportNameEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4NextEv
450
555
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
555
    return i_ >= static_cast<int>(L_->len_);
453
555
  }
_ZN8ListIterIP3StrE4DoneEv
Line
Count
Source
450
188
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
188
    return i_ >= static_cast<int>(L_->len_);
453
188
  }
_ZN8ListIterIiE4DoneEv
Line
Count
Source
450
79
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
79
    return i_ >= static_cast<int>(L_->len_);
453
79
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
450
24
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
24
    return i_ >= static_cast<int>(L_->len_);
453
24
  }
_ZN8ListIterIP6Tuple2IP3StriEE4DoneEv
Line
Count
Source
450
3
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
3
    return i_ >= static_cast<int>(L_->len_);
453
3
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv
_ZN8ListIterIPN10hnode_asdl5FieldEE4DoneEv
Line
Count
Source
450
205
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
205
    return i_ >= static_cast<int>(L_->len_);
453
205
  }
_ZN8ListIterIbE4DoneEv
Line
Count
Source
450
3
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
3
    return i_ >= static_cast<int>(L_->len_);
453
3
  }
_ZN8ListIterIP6Tuple2IiiEE4DoneEv
Line
Count
Source
450
12
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
12
    return i_ >= static_cast<int>(L_->len_);
453
12
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE4DoneEv
Line
Count
Source
450
41
  bool Done() {
451
    // "unsigned size_t was a mistake"
452
41
    return i_ >= static_cast<int>(L_->len_);
453
41
  }
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv
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_asdl5RedirEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7VariantEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10ImportNameEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4DoneEv
454
422
  T Value() {
455
422
    return L_->slab_->items_[i_];
456
422
  }
_ZN8ListIterIP3StrE5ValueEv
Line
Count
Source
454
149
  T Value() {
455
149
    return L_->slab_->items_[i_];
456
149
  }
_ZN8ListIterIiE5ValueEv
Line
Count
Source
454
56
  T Value() {
455
56
    return L_->slab_->items_[i_];
456
56
  }
_ZN8ListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
454
10
  T Value() {
455
10
    return L_->slab_->items_[i_];
456
10
  }
_ZN8ListIterIP6Tuple2IP3StriEE5ValueEv
Line
Count
Source
454
2
  T Value() {
455
2
    return L_->slab_->items_[i_];
456
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv
_ZN8ListIterIPN10hnode_asdl5FieldEE5ValueEv
Line
Count
Source
454
146
  T Value() {
455
146
    return L_->slab_->items_[i_];
456
146
  }
_ZN8ListIterIbE5ValueEv
Line
Count
Source
454
2
  T Value() {
455
2
    return L_->slab_->items_[i_];
456
2
  }
_ZN8ListIterIP6Tuple2IiiEE5ValueEv
Line
Count
Source
454
16
  T Value() {
455
16
    return L_->slab_->items_[i_];
456
16
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE5ValueEv
Line
Count
Source
454
41
  T Value() {
455
41
    return L_->slab_->items_[i_];
456
41
  }
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12CompoundWordEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl9AssignArgEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5loc_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv
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_asdl5RedirEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7EnvPairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10AssignPairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5IfArmEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7CaseArmEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8NameTypeEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5ParamEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8TypeExprEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7VariantEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10ImportNameEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13ComprehensionEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE5ValueEv
457
16
  T iterNext() {
458
16
    if (Done()) {
459
3
      throw Alloc<StopIteration>();
460
3
    }
461
13
    T ret = L_->slab_->items_[i_];
462
13
    Next();
463
13
    return ret;
464
16
  }
_ZN8ListIterIP6Tuple2IiP3StrEE8iterNextEv
Line
Count
Source
457
10
  T iterNext() {
458
10
    if (Done()) {
459
2
      throw Alloc<StopIteration>();
460
2
    }
461
8
    T ret = L_->slab_->items_[i_];
462
8
    Next();
463
8
    return ret;
464
10
  }
_ZN8ListIterIiE8iterNextEv
Line
Count
Source
457
6
  T iterNext() {
458
6
    if (Done()) {
459
1
      throw Alloc<StopIteration>();
460
1
    }
461
5
    T ret = L_->slab_->items_[i_];
462
5
    Next();
463
5
    return ret;
464
6
  }
465
466
  // only for use with generators
467
3
  List<T>* GetList() {
468
3
    return L_;
469
3
  }
470
471
 private:
472
  List<T>* L_;
473
  int i_;
474
};
475
476
// list(it) returns the iterator's backing list
477
template <typename T>
478
3
List<T>* list(ListIter<T> it) {
479
3
  return list(it.GetList());
480
3
}
481
482
// TODO: Does using pointers rather than indices make this more efficient?
483
template <class T>
484
class ReverseListIter {
485
 public:
486
4
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
487
4
  }
_ZN15ReverseListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
486
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
487
1
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
486
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
487
1
  }
_ZN15ReverseListIterIiEC2EP4ListIiE
Line
Count
Source
486
2
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
487
2
  }
488
10
  void Next() {
489
10
    i_--;
490
10
  }
_ZN15ReverseListIterIP3StrE4NextEv
Line
Count
Source
488
2
  void Next() {
489
2
    i_--;
490
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
488
2
  void Next() {
489
2
    i_--;
490
2
  }
_ZN15ReverseListIterIiE4NextEv
Line
Count
Source
488
6
  void Next() {
489
6
    i_--;
490
6
  }
491
14
  bool Done() {
492
14
    return i_ < 0;
493
14
  }
_ZN15ReverseListIterIP3StrE4DoneEv
Line
Count
Source
491
3
  bool Done() {
492
3
    return i_ < 0;
493
3
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
491
3
  bool Done() {
492
3
    return i_ < 0;
493
3
  }
_ZN15ReverseListIterIiE4DoneEv
Line
Count
Source
491
8
  bool Done() {
492
8
    return i_ < 0;
493
8
  }
494
10
  T Value() {
495
10
    return L_->slab_->items_[i_];
496
10
  }
_ZN15ReverseListIterIP3StrE5ValueEv
Line
Count
Source
494
2
  T Value() {
495
2
    return L_->slab_->items_[i_];
496
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
494
2
  T Value() {
495
2
    return L_->slab_->items_[i_];
496
2
  }
_ZN15ReverseListIterIiE5ValueEv
Line
Count
Source
494
6
  T Value() {
495
6
    return L_->slab_->items_[i_];
496
6
  }
497
498
 private:
499
  List<T>* L_;
500
  int i_;
501
};
502
503
int max(List<int>* elems);
504
505
#endif  // MYCPP_GC_LIST_H