diff options
Diffstat (limited to 'core/list.h')
-rw-r--r-- | core/list.h | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/core/list.h b/core/list.h index 7fbf3e50fc..fc943790de 100644 --- a/core/list.h +++ b/core/list.h @@ -49,7 +49,6 @@ class List { public: class Element { - private: friend class List<T, A>; @@ -63,14 +62,12 @@ public: * Get NEXT Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *next() const { - return next_ptr; }; /** * Get NEXT Element iterator, */ _FORCE_INLINE_ Element *next() { - return next_ptr; }; @@ -78,14 +75,12 @@ public: * Get PREV Element iterator, for constant lists. */ _FORCE_INLINE_ const Element *prev() const { - return prev_ptr; }; /** * Get PREV Element iterator, */ _FORCE_INLINE_ Element *prev() { - return prev_ptr; }; @@ -99,7 +94,6 @@ public: * operator->, for using as iterator->, when iterators are defined on stack, for constant lists. */ _FORCE_INLINE_ const T *operator->() const { - return &value; }; /** @@ -135,7 +129,6 @@ public: }; void erase() { - data->erase(this); } @@ -144,13 +137,11 @@ public: private: struct _Data { - Element *first; Element *last; int size_cache; bool erase(const Element *p_I) { - ERR_FAIL_COND_V(!p_I, false); ERR_FAIL_COND_V(p_I->data != this, false); @@ -181,7 +172,6 @@ public: * return a const iterator to the beginning of the list. */ _FORCE_INLINE_ const Element *front() const { - return _data ? _data->first : nullptr; }; @@ -196,7 +186,6 @@ public: * return a const iterator to the last member of the list. */ _FORCE_INLINE_ const Element *back() const { - return _data ? _data->last : nullptr; }; @@ -204,7 +193,6 @@ public: * return an iterator to the last member of the list. */ _FORCE_INLINE_ Element *back() { - return _data ? _data->last : nullptr; }; @@ -212,9 +200,7 @@ public: * store a new element at the end of the list */ Element *push_back(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = nullptr; _data->last = nullptr; @@ -229,7 +215,6 @@ public: n->data = _data; if (_data->last) { - _data->last->next_ptr = n; } @@ -244,7 +229,6 @@ public: }; void pop_back() { - if (_data && _data->last) erase(_data->last); } @@ -253,9 +237,7 @@ public: * store a new element at the beginning of the list */ Element *push_front(const T &value) { - if (!_data) { - _data = memnew_allocator(_Data, A); _data->first = nullptr; _data->last = nullptr; @@ -269,7 +251,6 @@ public: n->data = _data; if (_data->first) { - _data->first->prev_ptr = n; } @@ -284,7 +265,6 @@ public: }; void pop_front() { - if (_data && _data->first) erase(_data->first); } @@ -346,7 +326,6 @@ public: */ template <class T_v> Element *find(const T_v &p_val) { - Element *it = front(); while (it) { if (it->value == p_val) @@ -361,7 +340,6 @@ public: * erase an element in the list, by iterator pointing to it. Return true if it was found/erased. */ bool erase(const Element *p_I) { - if (_data) { bool ret = _data->erase(p_I); @@ -380,7 +358,6 @@ public: * erase the first element in the list, that contains value */ bool erase(const T &value) { - Element *I = find(value); return erase(I); }; @@ -389,7 +366,6 @@ public: * return whether the list is empty */ _FORCE_INLINE_ bool empty() const { - return (!_data || !_data->size_cache); } @@ -397,19 +373,16 @@ public: * clear the list */ void clear() { - while (front()) { erase(front()); }; }; _FORCE_INLINE_ int size() const { - return _data ? _data->size_cache : 0; } void swap(Element *p_A, Element *p_B) { - ERR_FAIL_COND(!p_A || !p_B); ERR_FAIL_COND(p_A->data != _data); ERR_FAIL_COND(p_B->data != _data); @@ -437,18 +410,15 @@ public: * copy the list */ void operator=(const List &p_list) { - clear(); const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } } T &operator[](int p_index) { - CRASH_BAD_INDEX(p_index, size()); Element *I = front(); @@ -462,7 +432,6 @@ public: } const T &operator[](int p_index) const { - CRASH_BAD_INDEX(p_index, size()); const Element *I = front(); @@ -476,7 +445,6 @@ public: } void move_to_back(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->next_ptr) return; @@ -500,12 +468,10 @@ public: } void invert() { - int s = size() / 2; Element *F = front(); Element *B = back(); for (int i = 0; i < s; i++) { - SWAP(F->value, B->value); F = F->next(); B = B->prev(); @@ -513,7 +479,6 @@ public: } void move_to_front(Element *p_I) { - ERR_FAIL_COND(p_I->data != _data); if (!p_I->prev_ptr) return; @@ -537,7 +502,6 @@ public: } void move_before(Element *value, Element *where) { - if (value->prev_ptr) { value->prev_ptr->next_ptr = value->next_ptr; } else { @@ -572,13 +536,11 @@ public: */ void sort() { - sort_custom<Comparator<T>>(); } template <class C> void sort_custom_inplace() { - if (size() < 2) return; @@ -587,18 +549,15 @@ public: Element *to = from; while (current) { - Element *next = current->next_ptr; if (from != current) { - current->prev_ptr = nullptr; current->next_ptr = from; Element *find = from; C less; while (find && less(find->value, current->value)) { - current->prev_ptr = find; current->next_ptr = find->next_ptr; find = find->next_ptr; @@ -614,7 +573,6 @@ public: else to = current; } else { - current->prev_ptr = nullptr; current->next_ptr = nullptr; } @@ -627,17 +585,14 @@ public: template <class C> struct AuxiliaryComparator { - C compare; _FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const { - return compare(a->value, b->value); } }; template <class C> void sort_custom() { - //this version uses auxiliary memory for speed. //if you don't want to use auxiliary memory, use the in_place version @@ -649,7 +604,6 @@ public: int idx = 0; for (Element *E = front(); E; E = E->next_ptr) { - aux_buffer[idx] = E; idx++; } @@ -666,7 +620,6 @@ public: aux_buffer[s - 1]->next_ptr = nullptr; for (int i = 1; i < s - 1; i++) { - aux_buffer[i]->prev_ptr = aux_buffer[i - 1]; aux_buffer[i]->next_ptr = aux_buffer[i + 1]; } @@ -682,10 +635,8 @@ public: * copy constructor for the list */ List(const List &p_list) { - const Element *it = p_list.front(); while (it) { - push_back(it->get()); it = it->next(); } @@ -696,7 +647,6 @@ public: ~List() { clear(); if (_data) { - ERR_FAIL_COND(_data->size_cache); memdelete_allocator<_Data, A>(_data); } |