cpp

Coverage Report

Created: 2023-03-07 20:24

/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 layout-compatible with List (unit tests assert this), and it can
15
// be a true C global (incurs zero startup time)
16
17
template <typename T, int N>
18
class GlobalList {
19
 public:
20
  ObjHeader header_;
21
  int len_;
22
  int capacity_;
23
  GlobalSlab<T, N>* slab_;
24
};
25
26
template <typename T>
27
class List {
28
  // Relate slab size to number of items (capacity)
29
  // 8 / 4 = 2 items, or 8 / 8 = 1 item
30
  static const int kCapacityAdjust = kSlabHeaderSize / sizeof(T);
31
  static_assert(kSlabHeaderSize % sizeof(T) == 0,
32
                "Slab header size should be multiple of item size");
33
34
  // Relates to minimum Slab size.
35
  // Smallest non-empty List<T*>  should have about 4 items, or 3 without header
36
  // Smallest non-empty List<int> should have about 8 items, or 7 without header
37
  static const int kMinItems = 32 / sizeof(T);
38
  static_assert(32 % sizeof(T) == 0,
39
                "An integral number of items should fit in 32 bytes");
40
41
 public:
42
929
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
929
  }
_ZN4ListIP3StrEC2Ev
Line
Count
Source
42
165
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
165
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEEC2Ev
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEEC2Ev
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEEC2Ev
_ZN4ListIiEC2Ev
Line
Count
Source
42
670
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
670
  }
_ZN4ListIP6Tuple2IiP3StrEEC2Ev
Line
Count
Source
42
9
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
9
  }
_ZN4ListIP6Tuple2IP3StriEEC2Ev
Line
Count
Source
42
1
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
1
  }
_ZN4ListIPN10hnode_asdl5fieldEEC2Ev
Line
Count
Source
42
37
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEEC2Ev
Line
Count
Source
42
37
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
37
  }
_ZN4ListIbEC2Ev
Line
Count
Source
42
3
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
3
  }
_ZN4ListIP6Tuple2IiiEEC2Ev
Line
Count
Source
42
4
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
4
  }
_ZN4ListIdEC2Ev
Line
Count
Source
42
2
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
2
  }
_ZN4ListIPN4pyos11PasswdEntryEEC2Ev
Line
Count
Source
42
1
  List() : header_(obj_header()), len_(0), capacity_(0), slab_(nullptr) {
43
1
  }
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEEC2Ev
44
45
  // Implements L[i]
46
  T index_(int i);
47
48
  // returns index of the element
49
  int index(T element);
50
51
  // Implements L[i] = item
52
  void set(int i, T item);
53
54
  // L[begin:]
55
  List* slice(int begin);
56
57
  // L[begin:end]
58
  List* slice(int begin, int end);
59
60
  // Should we have a separate API that doesn't return it?
61
  // https://stackoverflow.com/questions/12600330/pop-back-return-value
62
  T pop();
63
64
  // Used in osh/word_parse.py to remove from front
65
  T pop(int i);
66
67
  // Remove the first occourence of x from the list.
68
  void remove(T x);
69
70
  void clear();
71
72
  // Used in osh/string_ops.py
73
  void reverse();
74
75
  // Templated function
76
  void sort();
77
78
  // Ensure that there's space for a number of items
79
  void reserve(int n);
80
81
  // Append a single element to this list.
82
  void append(T item);
83
84
  // Extend this list with multiple elements.
85
  void extend(List<T>* other);
86
87
929
  static constexpr ObjHeader obj_header() {
88
929
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
929
  }
_ZN4ListIP3StrE10obj_headerEv
Line
Count
Source
87
165
  static constexpr ObjHeader obj_header() {
88
165
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
165
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE10obj_headerEv
_ZN4ListIiE10obj_headerEv
Line
Count
Source
87
670
  static constexpr ObjHeader obj_header() {
88
670
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
670
  }
_ZN4ListIP6Tuple2IiP3StrEE10obj_headerEv
Line
Count
Source
87
9
  static constexpr ObjHeader obj_header() {
88
9
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
9
  }
_ZN4ListIP6Tuple2IP3StriEE10obj_headerEv
Line
Count
Source
87
1
  static constexpr ObjHeader obj_header() {
88
1
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
1
  }
_ZN4ListIPN10hnode_asdl5fieldEE10obj_headerEv
Line
Count
Source
87
37
  static constexpr ObjHeader obj_header() {
88
37
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEE10obj_headerEv
Line
Count
Source
87
37
  static constexpr ObjHeader obj_header() {
88
37
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
37
  }
_ZN4ListIbE10obj_headerEv
Line
Count
Source
87
3
  static constexpr ObjHeader obj_header() {
88
3
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
3
  }
_ZN4ListIP6Tuple2IiiEE10obj_headerEv
Line
Count
Source
87
4
  static constexpr ObjHeader obj_header() {
88
4
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
4
  }
_ZN4ListIdE10obj_headerEv
Line
Count
Source
87
2
  static constexpr ObjHeader obj_header() {
88
2
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
2
  }
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10assoc_pairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13compound_wordEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5redirEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8env_pairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11assign_pairEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6if_armEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8case_armEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9name_typeEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12place_expr_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5paramEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11type_expr_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7variantEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12class_item_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11import_nameEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12UntypedParamEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10TypedParamEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13comprehensionEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9named_argEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11string_lineEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl10assign_argEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10obj_headerEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl7value_tEE10obj_headerEv
_ZN4ListIPN4pyos11PasswdEntryEE10obj_headerEv
Line
Count
Source
87
1
  static constexpr ObjHeader obj_header() {
88
1
    return ObjHeader::ClassFixed(field_mask(), sizeof(List<T>));
89
1
  }
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE10obj_headerEv
90
91
  GC_OBJ(header_);
92
93
  int len_;       // number of entries
94
  int capacity_;  // max entries before resizing
95
96
  // The container may be resized, so this field isn't in-line.
97
  Slab<T>* slab_;
98
99
  // A list has one Slab pointer which we need to follow.
100
931
  static constexpr uint16_t field_mask() {
101
931
    return maskbit(offsetof(List, slab_));
102
931
  }
_ZN4ListIP3StrE10field_maskEv
Line
Count
Source
100
165
  static constexpr uint16_t field_mask() {
101
165
    return maskbit(offsetof(List, slab_));
102
165
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE10field_maskEv
_ZN4ListIiE10field_maskEv
Line
Count
Source
100
672
  static constexpr uint16_t field_mask() {
101
672
    return maskbit(offsetof(List, slab_));
102
672
  }
_ZN4ListIP6Tuple2IiP3StrEE10field_maskEv
Line
Count
Source
100
9
  static constexpr uint16_t field_mask() {
101
9
    return maskbit(offsetof(List, slab_));
102
9
  }
_ZN4ListIP6Tuple2IP3StriEE10field_maskEv
Line
Count
Source
100
1
  static constexpr uint16_t field_mask() {
101
1
    return maskbit(offsetof(List, slab_));
102
1
  }
_ZN4ListIPN10hnode_asdl5fieldEE10field_maskEv
Line
Count
Source
100
37
  static constexpr uint16_t field_mask() {
101
37
    return maskbit(offsetof(List, slab_));
102
37
  }
_ZN4ListIPN10hnode_asdl7hnode_tEE10field_maskEv
Line
Count
Source
100
37
  static constexpr uint16_t field_mask() {
101
37
    return maskbit(offsetof(List, slab_));
102
37
  }
_ZN4ListIbE10field_maskEv
Line
Count
Source
100
3
  static constexpr uint16_t field_mask() {
101
3
    return maskbit(offsetof(List, slab_));
102
3
  }
_ZN4ListIP6Tuple2IiiEE10field_maskEv
Line
Count
Source
100
4
  static constexpr uint16_t field_mask() {
101
4
    return maskbit(offsetof(List, slab_));
102
4
  }
_ZN4ListIdE10field_maskEv
Line
Count
Source
100
2
  static constexpr uint16_t field_mask() {
101
2
    return maskbit(offsetof(List, slab_));
102
2
  }
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10assoc_pairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13compound_wordEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11word_part_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9command_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6word_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5redirEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8env_pairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11assign_pairEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6if_armEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl8case_armEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9name_typeEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12place_expr_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5paramEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11type_expr_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl7variantEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12class_item_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11import_nameEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl12UntypedParamEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10TypedParamEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl5TokenEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl6expr_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl13comprehensionEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl20class_literal_term_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl17char_class_term_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl4re_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl9named_argEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl11string_lineEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN11syntax_asdl10SourceLineEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl10assign_argEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl12part_value_tEE10field_maskEv
Unexecuted instantiation: _ZN4ListIPN12runtime_asdl7value_tEE10field_maskEv
_ZN4ListIPN4pyos11PasswdEntryEE10field_maskEv
Line
Count
Source
100
1
  static constexpr uint16_t field_mask() {
101
1
    return maskbit(offsetof(List, slab_));
102
1
  }
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE10field_maskEv
103
104
  DISALLOW_COPY_AND_ASSIGN(List)
105
106
 private:
107
930
  int RoundCapacity(int n) {
108
930
    if (n < kMinItems) {
109
854
      return kMinItems;
110
854
    }
111
76
    return RoundUp(n);
112
930
  }
_ZN4ListIP3StrE13RoundCapacityEi
Line
Count
Source
107
183
  int RoundCapacity(int n) {
108
183
    if (n < kMinItems) {
109
138
      return kMinItems;
110
138
    }
111
45
    return RoundUp(n);
112
183
  }
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE13RoundCapacityEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE13RoundCapacityEi
_ZN4ListIiE13RoundCapacityEi
Line
Count
Source
107
685
  int RoundCapacity(int n) {
108
685
    if (n < kMinItems) {
109
663
      return kMinItems;
110
663
    }
111
22
    return RoundUp(n);
112
685
  }
_ZN4ListIP6Tuple2IiP3StrEE13RoundCapacityEi
Line
Count
Source
107
9
  int RoundCapacity(int n) {
108
9
    if (n < kMinItems) {
109
7
      return kMinItems;
110
7
    }
111
2
    return RoundUp(n);
112
9
  }
_ZN4ListIP6Tuple2IP3StriEE13RoundCapacityEi
Line
Count
Source
107
1
  int RoundCapacity(int n) {
108
1
    if (n < kMinItems) {
109
1
      return kMinItems;
110
1
    }
111
0
    return RoundUp(n);
112
1
  }
_ZN4ListIPN10hnode_asdl5fieldEE13RoundCapacityEi
Line
Count
Source
107
37
  int RoundCapacity(int n) {
108
37
    if (n < kMinItems) {
109
37
      return kMinItems;
110
37
    }
111
0
    return RoundUp(n);
112
37
  }
_ZN4ListIbE13RoundCapacityEi
Line
Count
Source
107
3
  int RoundCapacity(int n) {
108
3
    if (n < kMinItems) {
109
3
      return kMinItems;
110
3
    }
111
0
    return RoundUp(n);
112
3
  }
_ZN4ListIP6Tuple2IiiEE13RoundCapacityEi
Line
Count
Source
107
4
  int RoundCapacity(int n) {
108
4
    if (n < kMinItems) {
109
4
      return kMinItems;
110
4
    }
111
0
    return RoundUp(n);
112
4
  }
_ZN4ListIdE13RoundCapacityEi
Line
Count
Source
107
2
  int RoundCapacity(int n) {
108
2
    if (n < kMinItems) {
109
0
      return kMinItems;
110
0
    }
111
2
    return RoundUp(n);
112
2
  }
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE13RoundCapacityEi
_ZN4ListIPN4pyos11PasswdEntryEE13RoundCapacityEi
Line
Count
Source
107
6
  int RoundCapacity(int n) {
108
6
    if (n < kMinItems) {
109
1
      return kMinItems;
110
1
    }
111
5
    return RoundUp(n);
112
6
  }
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE13RoundCapacityEi
113
};
114
115
// "Constructors" as free functions since we can't allocate within a
116
// constructor.  Allocation may cause garbage collection, which interferes with
117
// placement new.
118
119
// This is not really necessary, only syntactic sugar.
120
template <typename T>
121
650
List<T>* NewList() {
122
650
  return Alloc<List<T>>();
123
650
}
_Z7NewListIP3StrEP4ListIT_Ev
Line
Count
Source
121
25
List<T>* NewList() {
122
25
  return Alloc<List<T>>();
123
25
}
_Z7NewListIiEP4ListIT_Ev
Line
Count
Source
121
621
List<T>* NewList() {
122
621
  return Alloc<List<T>>();
123
621
}
_Z7NewListIPN4pyos11PasswdEntryEEP4ListIT_Ev
Line
Count
Source
121
1
List<T>* NewList() {
122
1
  return Alloc<List<T>>();
123
1
}
_Z7NewListIP6Tuple2IiP3StrEEP4ListIT_Ev
Line
Count
Source
121
3
List<T>* NewList() {
122
3
  return Alloc<List<T>>();
123
3
}
124
125
// Literal ['foo', 'bar']
126
// This seems to allow better template argument type deduction than a
127
// constructor.
128
template <typename T>
129
92
List<T>* NewList(std::initializer_list<T> init) {
130
92
  auto self = Alloc<List<T>>();
131
132
92
  int n = init.size();
133
92
  self->reserve(n);
134
135
92
  int i = 0;
136
168
  for (auto item : init) {
137
168
    self->set(i, item);
138
168
    ++i;
139
168
  }
140
92
  self->len_ = n;
141
92
  return self;
142
92
}
_Z7NewListIP3StrEP4ListIT_ESt16initializer_listIS3_E
Line
Count
Source
129
61
List<T>* NewList(std::initializer_list<T> init) {
130
61
  auto self = Alloc<List<T>>();
131
132
61
  int n = init.size();
133
61
  self->reserve(n);
134
135
61
  int i = 0;
136
69
  for (auto item : init) {
137
69
    self->set(i, item);
138
69
    ++i;
139
69
  }
140
61
  self->len_ = n;
141
61
  return self;
142
61
}
_Z7NewListIiEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
129
26
List<T>* NewList(std::initializer_list<T> init) {
130
26
  auto self = Alloc<List<T>>();
131
132
26
  int n = init.size();
133
26
  self->reserve(n);
134
135
26
  int i = 0;
136
87
  for (auto item : init) {
137
87
    self->set(i, item);
138
87
    ++i;
139
87
  }
140
26
  self->len_ = n;
141
26
  return self;
142
26
}
_Z7NewListIP6Tuple2IP3StriEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
129
1
List<T>* NewList(std::initializer_list<T> init) {
130
1
  auto self = Alloc<List<T>>();
131
132
1
  int n = init.size();
133
1
  self->reserve(n);
134
135
1
  int i = 0;
136
2
  for (auto item : init) {
137
2
    self->set(i, item);
138
2
    ++i;
139
2
  }
140
1
  self->len_ = n;
141
1
  return self;
142
1
}
_Z7NewListIP6Tuple2IiP3StrEEP4ListIT_ESt16initializer_listIS6_E
Line
Count
Source
129
1
List<T>* NewList(std::initializer_list<T> init) {
130
1
  auto self = Alloc<List<T>>();
131
132
1
  int n = init.size();
133
1
  self->reserve(n);
134
135
1
  int i = 0;
136
2
  for (auto item : init) {
137
2
    self->set(i, item);
138
2
    ++i;
139
2
  }
140
1
  self->len_ = n;
141
1
  return self;
142
1
}
_Z7NewListIbEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
129
1
List<T>* NewList(std::initializer_list<T> init) {
130
1
  auto self = Alloc<List<T>>();
131
132
1
  int n = init.size();
133
1
  self->reserve(n);
134
135
1
  int i = 0;
136
2
  for (auto item : init) {
137
2
    self->set(i, item);
138
2
    ++i;
139
2
  }
140
1
  self->len_ = n;
141
1
  return self;
142
1
}
_Z7NewListIdEP4ListIT_ESt16initializer_listIS1_E
Line
Count
Source
129
2
List<T>* NewList(std::initializer_list<T> init) {
130
2
  auto self = Alloc<List<T>>();
131
132
2
  int n = init.size();
133
2
  self->reserve(n);
134
135
2
  int i = 0;
136
6
  for (auto item : init) {
137
6
    self->set(i, item);
138
6
    ++i;
139
6
  }
140
2
  self->len_ = n;
141
2
  return self;
142
2
}
Unexecuted instantiation: _Z7NewListIPN10hnode_asdl7hnode_tEEP4ListIT_ESt16initializer_listIS4_E
143
144
// ['foo'] * 3
145
template <typename T>
146
9
List<T>* NewList(T item, int times) {
147
9
  auto self = Alloc<List<T>>();
148
149
9
  self->reserve(times);
150
9
  self->len_ = times;
151
36
  for (int i = 0; i < times; ++i) {
152
27
    self->set(i, item);
153
27
  }
154
9
  return self;
155
9
}
_Z7NewListIP3StrEP4ListIT_ES3_i
Line
Count
Source
146
3
List<T>* NewList(T item, int times) {
147
3
  auto self = Alloc<List<T>>();
148
149
3
  self->reserve(times);
150
3
  self->len_ = times;
151
12
  for (int i = 0; i < times; ++i) {
152
9
    self->set(i, item);
153
9
  }
154
3
  return self;
155
3
}
_Z7NewListIbEP4ListIT_ES1_i
Line
Count
Source
146
2
List<T>* NewList(T item, int times) {
147
2
  auto self = Alloc<List<T>>();
148
149
2
  self->reserve(times);
150
2
  self->len_ = times;
151
8
  for (int i = 0; i < times; ++i) {
152
6
    self->set(i, item);
153
6
  }
154
2
  return self;
155
2
}
_Z7NewListIiEP4ListIT_ES1_i
Line
Count
Source
146
4
List<T>* NewList(T item, int times) {
147
4
  auto self = Alloc<List<T>>();
148
149
4
  self->reserve(times);
150
4
  self->len_ = times;
151
16
  for (int i = 0; i < times; ++i) {
152
12
    self->set(i, item);
153
12
  }
154
4
  return self;
155
4
}
156
157
template <typename T>
158
6.71k
void List<T>::append(T item) {
159
6.71k
  reserve(len_ + 1);
160
6.71k
  slab_->items_[len_] = item;
161
6.71k
  ++len_;
162
6.71k
}
_ZN4ListIP3StrE6appendES1_
Line
Count
Source
158
428
void List<T>::append(T item) {
159
428
  reserve(len_ + 1);
160
428
  slab_->items_[len_] = item;
161
428
  ++len_;
162
428
}
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE6appendES2_
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE6appendES2_
_ZN4ListIiE6appendEi
Line
Count
Source
158
6.12k
void List<T>::append(T item) {
159
6.12k
  reserve(len_ + 1);
160
6.12k
  slab_->items_[len_] = item;
161
6.12k
  ++len_;
162
6.12k
}
_ZN4ListIP6Tuple2IiP3StrEE6appendES4_
Line
Count
Source
158
20
void List<T>::append(T item) {
159
20
  reserve(len_ + 1);
160
20
  slab_->items_[len_] = item;
161
20
  ++len_;
162
20
}
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StriEE6appendES4_
_ZN4ListIPN10hnode_asdl5fieldEE6appendES2_
Line
Count
Source
158
65
void List<T>::append(T item) {
159
65
  reserve(len_ + 1);
160
65
  slab_->items_[len_] = item;
161
65
  ++len_;
162
65
}
_ZN4ListIP6Tuple2IiiEE6appendES2_
Line
Count
Source
158
8
void List<T>::append(T item) {
159
8
  reserve(len_ + 1);
160
8
  slab_->items_[len_] = item;
161
8
  ++len_;
162
8
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE6appendES2_
_ZN4ListIPN4pyos11PasswdEntryEE6appendES2_
Line
Count
Source
158
75
void List<T>::append(T item) {
159
75
  reserve(len_ + 1);
160
75
  slab_->items_[len_] = item;
161
75
  ++len_;
162
75
}
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE6appendES4_
163
164
template <typename T>
165
4.14k
int len(const List<T>* L) {
166
4.14k
  return L->len_;
167
4.14k
}
_Z3lenIiEiPK4ListIT_E
Line
Count
Source
165
3.90k
int len(const List<T>* L) {
166
3.90k
  return L->len_;
167
3.90k
}
_Z3lenIP3StrEiPK4ListIT_E
Line
Count
Source
165
231
int len(const List<T>* L) {
166
231
  return L->len_;
167
231
}
Unexecuted instantiation: _Z3lenIPN10classes_gc10OpaqueBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN10classes_gc12PointersBaseEEiPK4ListIT_E
Unexecuted instantiation: _Z3lenIPN10classes_gc14BaseWithMethodEEiPK4ListIT_E
_Z3lenIP6Tuple2IiP3StrEEiPK4ListIT_E
Line
Count
Source
165
7
int len(const List<T>* L) {
166
7
  return L->len_;
167
7
}
_Z3lenIP6Tuple2IiiEEiPK4ListIT_E
Line
Count
Source
165
2
int len(const List<T>* L) {
166
2
  return L->len_;
167
2
}
_Z3lenIbEiPK4ListIT_E
Line
Count
Source
165
2
int len(const List<T>* L) {
166
2
  return L->len_;
167
2
}
_Z3lenIdEiPK4ListIT_E
Line
Count
Source
165
4
int len(const List<T>* L) {
166
4
  return L->len_;
167
4
}
168
169
template <typename T>
170
List<T>* list_repeat(T item, int times);
171
172
template <typename T>
173
inline bool list_contains(List<T>* haystack, T needle);
174
175
template <typename K, typename V>
176
class Dict;  // forward decl
177
178
template <typename V>
179
List<Str*>* sorted(Dict<Str*, V>* d);
180
181
template <typename T>
182
List<T>* sorted(List<T>* l);
183
184
// L[begin:]
185
// TODO: Implement this in terms of slice(begin, end)
186
template <typename T>
187
606
List<T>* List<T>::slice(int begin) {
188
606
  if (begin < 0) {
189
0
    begin = len_ + begin;
190
0
  }
191
192
606
  DCHECK(begin >= 0);
193
194
0
  List<T>* result = nullptr;
195
606
  result = NewList<T>();
196
197
3.02k
  for (int i = begin; i < len_; i++) {
198
2.41k
    result->append(slab_->items_[i]);
199
2.41k
  }
200
201
606
  return result;
202
606
}
_ZN4ListIP3StrE5sliceEi
Line
Count
Source
187
3
List<T>* List<T>::slice(int begin) {
188
3
  if (begin < 0) {
189
0
    begin = len_ + begin;
190
0
  }
191
192
3
  DCHECK(begin >= 0);
193
194
0
  List<T>* result = nullptr;
195
3
  result = NewList<T>();
196
197
9
  for (int i = begin; i < len_; i++) {
198
6
    result->append(slab_->items_[i]);
199
6
  }
200
201
3
  return result;
202
3
}
_ZN4ListIiE5sliceEi
Line
Count
Source
187
603
List<T>* List<T>::slice(int begin) {
188
603
  if (begin < 0) {
189
0
    begin = len_ + begin;
190
0
  }
191
192
603
  DCHECK(begin >= 0);
193
194
0
  List<T>* result = nullptr;
195
603
  result = NewList<T>();
196
197
3.01k
  for (int i = begin; i < len_; i++) {
198
2.40k
    result->append(slab_->items_[i]);
199
2.40k
  }
200
201
603
  return result;
202
603
}
203
204
// L[begin:end]
205
template <typename T>
206
3
List<T>* List<T>::slice(int begin, int end) {
207
3
  if (begin < 0) {
208
2
    begin = len_ + begin;
209
2
  }
210
3
  if (end < 0) {
211
3
    end = len_ + end;
212
3
  }
213
214
3
  DCHECK(end <= len_);
215
3
  DCHECK(begin >= 0);
216
3
  DCHECK(end >= 0);
217
218
0
  List<T>* result = NewList<T>();
219
9
  for (int i = begin; i < end; i++) {
220
6
    result->append(slab_->items_[i]);
221
6
  }
222
223
3
  return result;
224
3
}
225
226
// Ensure that there's space for a number of items
227
template <typename T>
228
6.83k
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
6.83k
  if (capacity_ >= n) {
233
5.90k
    return;
234
5.90k
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
930
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
930
  auto new_slab = NewSlab<T>(capacity_);
246
247
930
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
57
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
57
  }
251
930
  slab_ = new_slab;
252
930
}
_ZN4ListIP3StrE7reserveEi
Line
Count
Source
228
494
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
494
  if (capacity_ >= n) {
233
311
    return;
234
311
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
183
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
183
  auto new_slab = NewSlab<T>(capacity_);
246
247
183
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
32
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
32
  }
251
183
  slab_ = new_slab;
252
183
}
Unexecuted instantiation: _ZN4ListIPN10classes_gc10OpaqueBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc12PointersBaseEE7reserveEi
Unexecuted instantiation: _ZN4ListIPN10classes_gc14BaseWithMethodEE7reserveEi
_ZN4ListIiE7reserveEi
Line
Count
Source
228
6.16k
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
6.16k
  if (capacity_ >= n) {
233
5.48k
    return;
234
5.48k
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
685
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
685
  auto new_slab = NewSlab<T>(capacity_);
246
247
685
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
18
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
18
  }
251
685
  slab_ = new_slab;
252
685
}
_ZN4ListIP6Tuple2IiP3StrEE7reserveEi
Line
Count
Source
228
21
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
21
  if (capacity_ >= n) {
233
12
    return;
234
12
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
9
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
9
  auto new_slab = NewSlab<T>(capacity_);
246
247
9
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
2
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
2
  }
251
9
  slab_ = new_slab;
252
9
}
_ZN4ListIP6Tuple2IP3StriEE7reserveEi
Line
Count
Source
228
1
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
1
  if (capacity_ >= n) {
233
0
    return;
234
0
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
1
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
1
  auto new_slab = NewSlab<T>(capacity_);
246
247
1
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
0
  }
251
1
  slab_ = new_slab;
252
1
}
_ZN4ListIPN10hnode_asdl5fieldEE7reserveEi
Line
Count
Source
228
65
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
65
  if (capacity_ >= n) {
233
28
    return;
234
28
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
37
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
37
  auto new_slab = NewSlab<T>(capacity_);
246
247
37
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
0
  }
251
37
  slab_ = new_slab;
252
37
}
_ZN4ListIbE7reserveEi
Line
Count
Source
228
3
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
3
  if (capacity_ >= n) {
233
0
    return;
234
0
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
3
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
3
  auto new_slab = NewSlab<T>(capacity_);
246
247
3
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
0
  }
251
3
  slab_ = new_slab;
252
3
}
_ZN4ListIP6Tuple2IiiEE7reserveEi
Line
Count
Source
228
8
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
8
  if (capacity_ >= n) {
233
4
    return;
234
4
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
4
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
4
  auto new_slab = NewSlab<T>(capacity_);
246
247
4
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
0
  }
251
4
  slab_ = new_slab;
252
4
}
_ZN4ListIdE7reserveEi
Line
Count
Source
228
2
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
2
  if (capacity_ >= n) {
233
0
    return;
234
0
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
2
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
2
  auto new_slab = NewSlab<T>(capacity_);
246
247
2
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
0
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
0
  }
251
2
  slab_ = new_slab;
252
2
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE7reserveEi
_ZN4ListIPN4pyos11PasswdEntryEE7reserveEi
Line
Count
Source
228
75
void List<T>::reserve(int n) {
229
  // log("reserve capacity = %d, n = %d", capacity_, n);
230
231
  // Don't do anything if there's already enough space.
232
75
  if (capacity_ >= n) {
233
69
    return;
234
69
  }
235
236
  // Slabs should be a total of 2^N bytes.  kCapacityAdjust is the number of
237
  // items that the 8 byte header takes up: 1 for List<T*>, and 2 for
238
  // List<int>.
239
  //
240
  // Example: the user reserves space for 3 integers.  The minimum number of
241
  // items would be 5, which is rounded up to 8.  Subtract 2 again, giving 6,
242
  // which leads to 8 + 6*4 = 32 byte Slab.
243
244
6
  capacity_ = RoundCapacity(n + kCapacityAdjust) - kCapacityAdjust;
245
6
  auto new_slab = NewSlab<T>(capacity_);
246
247
6
  if (len_ > 0) {
248
    // log("Copying %d bytes", len_ * sizeof(T));
249
5
    memcpy(new_slab->items_, slab_->items_, len_ * sizeof(T));
250
5
  }
251
6
  slab_ = new_slab;
252
6
}
Unexecuted instantiation: _ZN4ListIP6Tuple2IP3StrbEE7reserveEi
253
254
// Implements L[i] = item
255
template <typename T>
256
247
void List<T>::set(int i, T item) {
257
247
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
247
  DCHECK(i >= 0);
262
247
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
247
}
_ZN4ListIP3StrE3setEiS1_
Line
Count
Source
256
90
void List<T>::set(int i, T item) {
257
90
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
90
  DCHECK(i >= 0);
262
90
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
90
}
_ZN4ListIiE3setEii
Line
Count
Source
256
139
void List<T>::set(int i, T item) {
257
139
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
139
  DCHECK(i >= 0);
262
139
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
139
}
_ZN4ListIP6Tuple2IP3StriEE3setEiS4_
Line
Count
Source
256
2
void List<T>::set(int i, T item) {
257
2
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
2
  DCHECK(i >= 0);
262
2
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
2
}
_ZN4ListIP6Tuple2IiP3StrEE3setEiS4_
Line
Count
Source
256
2
void List<T>::set(int i, T item) {
257
2
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
2
  DCHECK(i >= 0);
262
2
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
2
}
_ZN4ListIbE3setEib
Line
Count
Source
256
8
void List<T>::set(int i, T item) {
257
8
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
8
  DCHECK(i >= 0);
262
8
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
8
}
_ZN4ListIdE3setEid
Line
Count
Source
256
6
void List<T>::set(int i, T item) {
257
6
  if (i < 0) {
258
0
    i = len_ + i;
259
0
  }
260
261
6
  DCHECK(i >= 0);
262
6
  DCHECK(i < capacity_);
263
264
0
  slab_->items_[i] = item;
265
6
}
Unexecuted instantiation: _ZN4ListIPN10hnode_asdl7hnode_tEE3setEiS2_
266
267
// Implements L[i]
268
template <typename T>
269
861
T List<T>::index_(int i) {
270
861
  if (i < 0) {
271
4
    int j = len_ + i;
272
4
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
4
    return slab_->items_[j];
276
4
  }
277
278
857
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
857
  return slab_->items_[i];
282
857
}
_ZN4ListIiE6index_Ei
Line
Count
Source
269
171
T List<T>::index_(int i) {
270
171
  if (i < 0) {
271
1
    int j = len_ + i;
272
1
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
1
    return slab_->items_[j];
276
1
  }
277
278
170
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
170
  return slab_->items_[i];
282
170
}
_ZN4ListIP3StrE6index_Ei
Line
Count
Source
269
673
T List<T>::index_(int i) {
270
673
  if (i < 0) {
271
3
    int j = len_ + i;
272
3
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
3
    return slab_->items_[j];
276
3
  }
277
278
670
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
670
  return slab_->items_[i];
282
670
}
_ZN4ListIbE6index_Ei
Line
Count
Source
269
4
T List<T>::index_(int i) {
270
4
  if (i < 0) {
271
0
    int j = len_ + i;
272
0
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
0
    return slab_->items_[j];
276
0
  }
277
278
4
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
4
  return slab_->items_[i];
282
4
}
_ZN4ListIdE6index_Ei
Line
Count
Source
269
8
T List<T>::index_(int i) {
270
8
  if (i < 0) {
271
0
    int j = len_ + i;
272
0
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
0
    return slab_->items_[j];
276
0
  }
277
278
8
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
8
  return slab_->items_[i];
282
8
}
_ZN4ListIP6Tuple2IiP3StrEE6index_Ei
Line
Count
Source
269
5
T List<T>::index_(int i) {
270
5
  if (i < 0) {
271
0
    int j = len_ + i;
272
0
    if (j >= len_ || j < 0) {
273
0
      throw Alloc<IndexError>();
274
0
    }
275
0
    return slab_->items_[j];
276
0
  }
277
278
5
  if (i >= len_ || i < 0) {
279
0
    throw Alloc<IndexError>();
280
0
  }
281
5
  return slab_->items_[i];
282
5
}
283
284
// L.index(i) -- Python method
285
template <typename T>
286
8
int List<T>::index(T value) {
287
8
  int element_count = len(this);
288
18
  for (int i = 0; i < element_count; i++) {
289
16
    if (are_equal(slab_->items_[i], value)) {
290
6
      return i;
291
6
    }
292
16
  }
293
2
  throw Alloc<ValueError>();
294
8
}
295
296
// Should we have a separate API that doesn't return it?
297
// https://stackoverflow.com/questions/12600330/pop-back-return-value
298
template <typename T>
299
7
T List<T>::pop() {
300
7
  if (len_ == 0) {
301
0
    throw Alloc<IndexError>();
302
0
  }
303
7
  len_--;
304
7
  T result = slab_->items_[len_];
305
7
  slab_->items_[len_] = 0;  // zero for GC scan
306
7
  return result;
307
7
}
_ZN4ListIP3StrE3popEv
Line
Count
Source
299
5
T List<T>::pop() {
300
5
  if (len_ == 0) {
301
0
    throw Alloc<IndexError>();
302
0
  }
303
5
  len_--;
304
5
  T result = slab_->items_[len_];
305
5
  slab_->items_[len_] = 0;  // zero for GC scan
306
5
  return result;
307
5
}
_ZN4ListIiE3popEv
Line
Count
Source
299
2
T List<T>::pop() {
300
2
  if (len_ == 0) {
301
0
    throw Alloc<IndexError>();
302
0
  }
303
2
  len_--;
304
2
  T result = slab_->items_[len_];
305
2
  slab_->items_[len_] = 0;  // zero for GC scan
306
2
  return result;
307
2
}
308
309
// Used in osh/word_parse.py to remove from front
310
template <typename T>
311
10
T List<T>::pop(int i) {
312
10
  if (len_ < i) {
313
0
    throw Alloc<IndexError>();
314
0
  }
315
316
10
  T result = index_(i);
317
10
  len_--;
318
319
  // Shift everything by one
320
10
  memmove(slab_->items_ + i, slab_->items_ + (i + 1), len_ * sizeof(T));
321
322
  /*
323
  for (int j = 0; j < len_; j++) {
324
    slab_->items_[j] = slab_->items_[j+1];
325
  }
326
  */
327
328
10
  slab_->items_[len_] = 0;  // zero for GC scan
329
10
  return result;
330
10
}
331
332
template <typename T>
333
6
void List<T>::remove(T x) {
334
6
  int idx = this->index(x);
335
6
  this->pop(idx);  // unused
336
6
}
337
338
template <typename T>
339
5
void List<T>::clear() {
340
5
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
341
5
  len_ = 0;
342
5
}
_ZN4ListIiE5clearEv
Line
Count
Source
339
4
void List<T>::clear() {
340
4
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
341
4
  len_ = 0;
342
4
}
_ZN4ListIP3StrE5clearEv
Line
Count
Source
339
1
void List<T>::clear() {
340
1
  memset(slab_->items_, 0, len_ * sizeof(T));  // zero for GC scan
341
1
  len_ = 0;
342
1
}
343
344
// Used in osh/string_ops.py
345
template <typename T>
346
8
void List<T>::reverse() {
347
16
  for (int i = 0; i < len_ / 2; ++i) {
348
    // log("swapping %d and %d", i, n-i);
349
8
    T tmp = slab_->items_[i];
350
8
    int j = len_ - 1 - i;
351
8
    slab_->items_[i] = slab_->items_[j];
352
8
    slab_->items_[j] = tmp;
353
8
  }
354
8
}
Unexecuted instantiation: _ZN4ListIP3StrE7reverseEv
_ZN4ListIiE7reverseEv
Line
Count
Source
346
8
void List<T>::reverse() {
347
16
  for (int i = 0; i < len_ / 2; ++i) {
348
    // log("swapping %d and %d", i, n-i);
349
8
    T tmp = slab_->items_[i];
350
8
    int j = len_ - 1 - i;
351
8
    slab_->items_[i] = slab_->items_[j];
352
8
    slab_->items_[j] = tmp;
353
8
  }
354
8
}
355
356
// Extend this list with multiple elements.
357
template <typename T>
358
13
void List<T>::extend(List<T>* other) {
359
13
  int n = other->len_;
360
13
  int new_len = len_ + n;
361
13
  reserve(new_len);
362
363
54
  for (int i = 0; i < n; ++i) {
364
41
    set(len_ + i, other->slab_->items_[i]);
365
41
  }
366
13
  len_ = new_len;
367
13
}
_ZN4ListIiE6extendEPS0_
Line
Count
Source
358
11
void List<T>::extend(List<T>* other) {
359
11
  int n = other->len_;
360
11
  int new_len = len_ + n;
361
11
  reserve(new_len);
362
363
46
  for (int i = 0; i < n; ++i) {
364
35
    set(len_ + i, other->slab_->items_[i]);
365
35
  }
366
11
  len_ = new_len;
367
11
}
_ZN4ListIP3StrE6extendEPS2_
Line
Count
Source
358
2
void List<T>::extend(List<T>* other) {
359
2
  int n = other->len_;
360
2
  int new_len = len_ + n;
361
2
  reserve(new_len);
362
363
8
  for (int i = 0; i < n; ++i) {
364
6
    set(len_ + i, other->slab_->items_[i]);
365
6
  }
366
2
  len_ = new_len;
367
2
}
368
369
34
inline bool _cmp(Str* a, Str* b) {
370
34
  return mylib::str_cmp(a, b) < 0;
371
34
}
372
373
template <typename T>
374
8
void List<T>::sort() {
375
8
  std::sort(slab_->items_, slab_->items_ + len_, _cmp);
376
8
}
377
378
// TODO: mycpp can just generate the constructor instead?
379
// e.g. [None] * 3
380
template <typename T>
381
5
List<T>* list_repeat(T item, int times) {
382
5
  return NewList<T>(item, times);
383
5
}
_Z11list_repeatIP3StrEP4ListIT_ES3_i
Line
Count
Source
381
3
List<T>* list_repeat(T item, int times) {
382
3
  return NewList<T>(item, times);
383
3
}
_Z11list_repeatIbEP4ListIT_ES1_i
Line
Count
Source
381
2
List<T>* list_repeat(T item, int times) {
382
2
  return NewList<T>(item, times);
383
2
}
384
385
// e.g. 'a' in ['a', 'b', 'c']
386
template <typename T>
387
22
inline bool list_contains(List<T>* haystack, T needle) {
388
22
  int n = len(haystack);
389
51
  for (int i = 0; i < n; ++i) {
390
42
    if (are_equal(haystack->index_(i), needle)) {
391
13
      return true;
392
13
    }
393
42
  }
394
9
  return false;
395
22
}
_Z13list_containsIiEbP4ListIT_ES1_
Line
Count
Source
387
6
inline bool list_contains(List<T>* haystack, T needle) {
388
6
  int n = len(haystack);
389
13
  for (int i = 0; i < n; ++i) {
390
11
    if (are_equal(haystack->index_(i), needle)) {
391
4
      return true;
392
4
    }
393
11
  }
394
2
  return false;
395
6
}
_Z13list_containsIP3StrEbP4ListIT_ES3_
Line
Count
Source
387
12
inline bool list_contains(List<T>* haystack, T needle) {
388
12
  int n = len(haystack);
389
28
  for (int i = 0; i < n; ++i) {
390
23
    if (are_equal(haystack->index_(i), needle)) {
391
7
      return true;
392
7
    }
393
23
  }
394
5
  return false;
395
12
}
_Z13list_containsIdEbP4ListIT_ES1_
Line
Count
Source
387
4
inline bool list_contains(List<T>* haystack, T needle) {
388
4
  int n = len(haystack);
389
10
  for (int i = 0; i < n; ++i) {
390
8
    if (are_equal(haystack->index_(i), needle)) {
391
2
      return true;
392
2
    }
393
8
  }
394
2
  return false;
395
4
}
396
397
template <typename V>
398
2
List<Str*>* sorted(Dict<Str*, V>* d) {
399
2
  auto keys = d->keys();
400
2
  keys->sort();
401
2
  return keys;
402
2
}
403
404
template <typename T>
405
2
List<T>* sorted(List<T>* l) {
406
2
  auto ret = list(l);
407
2
  ret->sort();
408
2
  return ret;
409
2
}
410
411
// list(L) copies the list
412
template <typename T>
413
7
List<T>* list(List<T>* other) {
414
7
  auto result = NewList<T>();
415
7
  result->extend(other);
416
7
  return result;
417
7
}
_Z4listIiEP4ListIT_ES3_
Line
Count
Source
413
5
List<T>* list(List<T>* other) {
414
5
  auto result = NewList<T>();
415
5
  result->extend(other);
416
5
  return result;
417
5
}
_Z4listIP3StrEP4ListIT_ES5_
Line
Count
Source
413
2
List<T>* list(List<T>* other) {
414
2
  auto result = NewList<T>();
415
2
  result->extend(other);
416
2
  return result;
417
2
}
418
419
#define GLOBAL_LIST(T, N, name, array)                               \
420
  GlobalSlab<T, N> _slab_##name = {                                  \
421
      {kIsHeader, 0, kZeroMask, HeapTag::Global, kIsGlobal}, array}; \
422
  GlobalList<T, N> _list_##name = {                                  \
423
      {kIsHeader, 0, kZeroMask, HeapTag::Global, kIsGlobal},         \
424
      N,                                                             \
425
      N,                                                             \
426
      &_slab_##name};                                                \
427
  List<T>* name = reinterpret_cast<List<T>*>(&_list_##name);
428
429
template <class T>
430
class ListIter {
431
 public:
432
155
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
155
  }
_ZN8ListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
432
40
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
40
  }
_ZN8ListIterIiEC2EP4ListIiE
Line
Count
Source
432
20
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
20
  }
_ZN8ListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
432
6
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
6
  }
_ZN8ListIterIP6Tuple2IP3StriEEC2EP4ListIS4_E
Line
Count
Source
432
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
1
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEEC2EP4ListIS2_E
_ZN8ListIterIPN10hnode_asdl5fieldEEC2EP4ListIS2_E
Line
Count
Source
432
82
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
82
  }
_ZN8ListIterIbEC2EP4ListIbE
Line
Count
Source
432
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
1
  }
_ZN8ListIterIP6Tuple2IiiEEC2EP4ListIS2_E
Line
Count
Source
432
4
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
4
  }
_ZN8ListIterIPN4pyos11PasswdEntryEEC2EP4ListIS2_E
Line
Count
Source
432
1
  explicit ListIter(List<T>* L) : L_(L), i_(0) {
433
    // Cheney only: L_ could be moved during iteration.
434
    // gHeap.PushRoot(reinterpret_cast<RawObject**>(&L_));
435
1
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_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_asdl9named_argEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10assoc_pairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEEC2EP4ListIS2_E
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEEC2EP4ListIS2_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
436
437
158
  ~ListIter() {
438
    // gHeap.PopRoot();
439
158
  }
_ZN8ListIterIP3StrED2Ev
Line
Count
Source
437
40
  ~ListIter() {
438
    // gHeap.PopRoot();
439
40
  }
_ZN8ListIterIiED2Ev
Line
Count
Source
437
23
  ~ListIter() {
438
    // gHeap.PopRoot();
439
23
  }
_ZN8ListIterIP6Tuple2IiP3StrEED2Ev
Line
Count
Source
437
6
  ~ListIter() {
438
    // gHeap.PopRoot();
439
6
  }
_ZN8ListIterIP6Tuple2IP3StriEED2Ev
Line
Count
Source
437
1
  ~ListIter() {
438
    // gHeap.PopRoot();
439
1
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEED2Ev
_ZN8ListIterIPN10hnode_asdl5fieldEED2Ev
Line
Count
Source
437
82
  ~ListIter() {
438
    // gHeap.PopRoot();
439
82
  }
_ZN8ListIterIbED2Ev
Line
Count
Source
437
1
  ~ListIter() {
438
    // gHeap.PopRoot();
439
1
  }
_ZN8ListIterIP6Tuple2IiiEED2Ev
Line
Count
Source
437
4
  ~ListIter() {
438
    // gHeap.PopRoot();
439
4
  }
_ZN8ListIterIPN4pyos11PasswdEntryEED2Ev
Line
Count
Source
437
1
  ~ListIter() {
438
    // gHeap.PopRoot();
439
1
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10assoc_pairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEED2Ev
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEED2Ev
440
400
  void Next() {
441
400
    i_++;
442
400
  }
_ZN8ListIterIP3StrE4NextEv
Line
Count
Source
440
148
  void Next() {
441
148
    i_++;
442
148
  }
_ZN8ListIterIiE4NextEv
Line
Count
Source
440
59
  void Next() {
441
59
    i_++;
442
59
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
440
18
  void Next() {
441
18
    i_++;
442
18
  }
_ZN8ListIterIP6Tuple2IP3StriEE4NextEv
Line
Count
Source
440
2
  void Next() {
441
2
    i_++;
442
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4NextEv
_ZN8ListIterIPN10hnode_asdl5fieldEE4NextEv
Line
Count
Source
440
123
  void Next() {
441
123
    i_++;
442
123
  }
_ZN8ListIterIbE4NextEv
Line
Count
Source
440
2
  void Next() {
441
2
    i_++;
442
2
  }
_ZN8ListIterIP6Tuple2IiiEE4NextEv
Line
Count
Source
440
8
  void Next() {
441
8
    i_++;
442
8
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE4NextEv
Line
Count
Source
440
40
  void Next() {
441
40
    i_++;
442
40
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10assoc_pairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4NextEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4NextEv
443
552
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
552
    return i_ >= static_cast<int>(L_->len_);
446
552
  }
_ZN8ListIterIP3StrE4DoneEv
Line
Count
Source
443
188
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
188
    return i_ >= static_cast<int>(L_->len_);
446
188
  }
_ZN8ListIterIiE4DoneEv
Line
Count
Source
443
76
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
76
    return i_ >= static_cast<int>(L_->len_);
446
76
  }
_ZN8ListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
443
24
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
24
    return i_ >= static_cast<int>(L_->len_);
446
24
  }
_ZN8ListIterIP6Tuple2IP3StriEE4DoneEv
Line
Count
Source
443
3
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
3
    return i_ >= static_cast<int>(L_->len_);
446
3
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE4DoneEv
_ZN8ListIterIPN10hnode_asdl5fieldEE4DoneEv
Line
Count
Source
443
205
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
205
    return i_ >= static_cast<int>(L_->len_);
446
205
  }
_ZN8ListIterIbE4DoneEv
Line
Count
Source
443
3
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
3
    return i_ >= static_cast<int>(L_->len_);
446
3
  }
_ZN8ListIterIP6Tuple2IiiEE4DoneEv
Line
Count
Source
443
12
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
12
    return i_ >= static_cast<int>(L_->len_);
446
12
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE4DoneEv
Line
Count
Source
443
41
  bool Done() {
444
    // "unsigned size_t was a mistake"
445
41
    return i_ >= static_cast<int>(L_->len_);
446
41
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10assoc_pairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE4DoneEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE4DoneEv
447
420
  T Value() {
448
420
    return L_->slab_->items_[i_];
449
420
  }
_ZN8ListIterIP3StrE5ValueEv
Line
Count
Source
447
149
  T Value() {
448
149
    return L_->slab_->items_[i_];
449
149
  }
_ZN8ListIterIiE5ValueEv
Line
Count
Source
447
54
  T Value() {
448
54
    return L_->slab_->items_[i_];
449
54
  }
_ZN8ListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
447
10
  T Value() {
448
10
    return L_->slab_->items_[i_];
449
10
  }
_ZN8ListIterIP6Tuple2IP3StriEE5ValueEv
Line
Count
Source
447
2
  T Value() {
448
2
    return L_->slab_->items_[i_];
449
2
  }
Unexecuted instantiation: _ZN8ListIterIPN10hnode_asdl7hnode_tEE5ValueEv
_ZN8ListIterIPN10hnode_asdl5fieldEE5ValueEv
Line
Count
Source
447
146
  T Value() {
448
146
    return L_->slab_->items_[i_];
449
146
  }
_ZN8ListIterIbE5ValueEv
Line
Count
Source
447
2
  T Value() {
448
2
    return L_->slab_->items_[i_];
449
2
  }
_ZN8ListIterIP6Tuple2IiiEE5ValueEv
Line
Count
Source
447
16
  T Value() {
448
16
    return L_->slab_->items_[i_];
449
16
  }
_ZN8ListIterIPN4pyos11PasswdEntryEE5ValueEv
Line
Count
Source
447
41
  T Value() {
448
41
    return L_->slab_->items_[i_];
449
41
  }
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl10assign_argEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl12part_value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN12runtime_asdl7value_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11word_part_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5TokenEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6word_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9named_argEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10assoc_pairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13compound_wordEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11string_lineEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9command_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5redirEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10SourceLineEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8env_pairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11assign_pairEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl6if_armEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl8case_armEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl9name_typeEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12place_expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl5paramEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11type_expr_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl7variantEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12class_item_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl11import_nameEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl12UntypedParamEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl10TypedParamEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl13comprehensionEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl20class_literal_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl17char_class_term_tEE5ValueEv
Unexecuted instantiation: _ZN8ListIterIPN11syntax_asdl4re_tEE5ValueEv
450
16
  T iterNext() {
451
16
    if (Done()) {
452
3
      throw Alloc<StopIteration>();
453
3
    }
454
13
    T ret = L_->slab_->items_[i_];
455
13
    Next();
456
13
    return ret;
457
16
  }
_ZN8ListIterIP6Tuple2IiP3StrEE8iterNextEv
Line
Count
Source
450
10
  T iterNext() {
451
10
    if (Done()) {
452
2
      throw Alloc<StopIteration>();
453
2
    }
454
8
    T ret = L_->slab_->items_[i_];
455
8
    Next();
456
8
    return ret;
457
10
  }
_ZN8ListIterIiE8iterNextEv
Line
Count
Source
450
6
  T iterNext() {
451
6
    if (Done()) {
452
1
      throw Alloc<StopIteration>();
453
1
    }
454
5
    T ret = L_->slab_->items_[i_];
455
5
    Next();
456
5
    return ret;
457
6
  }
458
459
  // only for use with generators
460
3
  List<T>* GetList() {
461
3
    return L_;
462
3
  }
463
464
 private:
465
  List<T>* L_;
466
  int i_;
467
};
468
469
// list(it) returns the iterator's backing list
470
template <typename T>
471
3
List<T>* list(ListIter<T> it) {
472
3
  return list(it.GetList());
473
3
}
474
475
// TODO: Does using pointers rather than indices make this more efficient?
476
template <class T>
477
class ReverseListIter {
478
 public:
479
4
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
480
4
  }
_ZN15ReverseListIterIP3StrEC2EP4ListIS1_E
Line
Count
Source
479
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
480
1
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEEC2EP4ListIS4_E
Line
Count
Source
479
1
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
480
1
  }
_ZN15ReverseListIterIiEC2EP4ListIiE
Line
Count
Source
479
2
  explicit ReverseListIter(List<T>* L) : L_(L), i_(L_->len_ - 1) {
480
2
  }
481
10
  void Next() {
482
10
    i_--;
483
10
  }
_ZN15ReverseListIterIP3StrE4NextEv
Line
Count
Source
481
2
  void Next() {
482
2
    i_--;
483
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4NextEv
Line
Count
Source
481
2
  void Next() {
482
2
    i_--;
483
2
  }
_ZN15ReverseListIterIiE4NextEv
Line
Count
Source
481
6
  void Next() {
482
6
    i_--;
483
6
  }
484
14
  bool Done() {
485
14
    return i_ < 0;
486
14
  }
_ZN15ReverseListIterIP3StrE4DoneEv
Line
Count
Source
484
3
  bool Done() {
485
3
    return i_ < 0;
486
3
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE4DoneEv
Line
Count
Source
484
3
  bool Done() {
485
3
    return i_ < 0;
486
3
  }
_ZN15ReverseListIterIiE4DoneEv
Line
Count
Source
484
8
  bool Done() {
485
8
    return i_ < 0;
486
8
  }
487
10
  T Value() {
488
10
    return L_->slab_->items_[i_];
489
10
  }
_ZN15ReverseListIterIP3StrE5ValueEv
Line
Count
Source
487
2
  T Value() {
488
2
    return L_->slab_->items_[i_];
489
2
  }
_ZN15ReverseListIterIP6Tuple2IiP3StrEE5ValueEv
Line
Count
Source
487
2
  T Value() {
488
2
    return L_->slab_->items_[i_];
489
2
  }
_ZN15ReverseListIterIiE5ValueEv
Line
Count
Source
487
6
  T Value() {
488
6
    return L_->slab_->items_[i_];
489
6
  }
490
491
 private:
492
  List<T>* L_;
493
  int i_;
494
};
495
496
int max(List<int>* elems);
497
498
#endif  // MYCPP_GC_LIST_H