list.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. /**************************************************************************/
  2. /* list.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef LIST_H
  31. #define LIST_H
  32. #include "core/error/error_macros.h"
  33. #include "core/os/memory.h"
  34. #include "core/templates/sort_array.h"
  35. #include <initializer_list>
  36. /**
  37. * Generic Templatized Linked List Implementation.
  38. * The implementation differs from the STL one because
  39. * a compatible preallocated linked list can be written
  40. * using the same API, or features such as erasing an element
  41. * from the iterator.
  42. */
  43. template <typename T, typename A = DefaultAllocator>
  44. class List {
  45. struct _Data;
  46. public:
  47. class Element {
  48. private:
  49. friend class List<T, A>;
  50. T value;
  51. Element *next_ptr = nullptr;
  52. Element *prev_ptr = nullptr;
  53. _Data *data = nullptr;
  54. public:
  55. /**
  56. * Get NEXT Element iterator, for constant lists.
  57. */
  58. _FORCE_INLINE_ const Element *next() const {
  59. return next_ptr;
  60. }
  61. /**
  62. * Get NEXT Element iterator,
  63. */
  64. _FORCE_INLINE_ Element *next() {
  65. return next_ptr;
  66. }
  67. /**
  68. * Get PREV Element iterator, for constant lists.
  69. */
  70. _FORCE_INLINE_ const Element *prev() const {
  71. return prev_ptr;
  72. }
  73. /**
  74. * Get PREV Element iterator,
  75. */
  76. _FORCE_INLINE_ Element *prev() {
  77. return prev_ptr;
  78. }
  79. /**
  80. * * operator, for using as *iterator, when iterators are defined on stack.
  81. */
  82. _FORCE_INLINE_ const T &operator*() const {
  83. return value;
  84. }
  85. /**
  86. * operator->, for using as iterator->, when iterators are defined on stack, for constant lists.
  87. */
  88. _FORCE_INLINE_ const T *operator->() const {
  89. return &value;
  90. }
  91. /**
  92. * * operator, for using as *iterator, when iterators are defined on stack,
  93. */
  94. _FORCE_INLINE_ T &operator*() {
  95. return value;
  96. }
  97. /**
  98. * operator->, for using as iterator->, when iterators are defined on stack, for constant lists.
  99. */
  100. _FORCE_INLINE_ T *operator->() {
  101. return &value;
  102. }
  103. /**
  104. * get the value stored in this element.
  105. */
  106. _FORCE_INLINE_ T &get() {
  107. return value;
  108. }
  109. /**
  110. * get the value stored in this element, for constant lists
  111. */
  112. _FORCE_INLINE_ const T &get() const {
  113. return value;
  114. }
  115. /**
  116. * set the value stored in this element.
  117. */
  118. _FORCE_INLINE_ void set(const T &p_value) {
  119. value = (T &)p_value;
  120. }
  121. void erase() {
  122. data->erase(this);
  123. }
  124. void transfer_to_back(List<T, A> *p_dst_list);
  125. _FORCE_INLINE_ Element() {}
  126. };
  127. typedef T ValueType;
  128. struct ConstIterator {
  129. _FORCE_INLINE_ const T &operator*() const {
  130. return E->get();
  131. }
  132. _FORCE_INLINE_ const T *operator->() const { return &E->get(); }
  133. _FORCE_INLINE_ ConstIterator &operator++() {
  134. E = E->next();
  135. return *this;
  136. }
  137. _FORCE_INLINE_ ConstIterator &operator--() {
  138. E = E->prev();
  139. return *this;
  140. }
  141. _FORCE_INLINE_ bool operator==(const ConstIterator &b) const { return E == b.E; }
  142. _FORCE_INLINE_ bool operator!=(const ConstIterator &b) const { return E != b.E; }
  143. _FORCE_INLINE_ ConstIterator(const Element *p_E) { E = p_E; }
  144. _FORCE_INLINE_ ConstIterator() {}
  145. _FORCE_INLINE_ ConstIterator(const ConstIterator &p_it) { E = p_it.E; }
  146. private:
  147. const Element *E = nullptr;
  148. };
  149. struct Iterator {
  150. _FORCE_INLINE_ T &operator*() const {
  151. return E->get();
  152. }
  153. _FORCE_INLINE_ T *operator->() const { return &E->get(); }
  154. _FORCE_INLINE_ Iterator &operator++() {
  155. E = E->next();
  156. return *this;
  157. }
  158. _FORCE_INLINE_ Iterator &operator--() {
  159. E = E->prev();
  160. return *this;
  161. }
  162. _FORCE_INLINE_ bool operator==(const Iterator &b) const { return E == b.E; }
  163. _FORCE_INLINE_ bool operator!=(const Iterator &b) const { return E != b.E; }
  164. Iterator(Element *p_E) { E = p_E; }
  165. Iterator() {}
  166. Iterator(const Iterator &p_it) { E = p_it.E; }
  167. operator ConstIterator() const {
  168. return ConstIterator(E);
  169. }
  170. private:
  171. Element *E = nullptr;
  172. };
  173. _FORCE_INLINE_ Iterator begin() {
  174. return Iterator(front());
  175. }
  176. _FORCE_INLINE_ Iterator end() {
  177. return Iterator(nullptr);
  178. }
  179. #if 0
  180. //to use when replacing find()
  181. _FORCE_INLINE_ Iterator find(const K &p_key) {
  182. return Iterator(find(p_key));
  183. }
  184. #endif
  185. _FORCE_INLINE_ ConstIterator begin() const {
  186. return ConstIterator(front());
  187. }
  188. _FORCE_INLINE_ ConstIterator end() const {
  189. return ConstIterator(nullptr);
  190. }
  191. #if 0
  192. //to use when replacing find()
  193. _FORCE_INLINE_ ConstIterator find(const K &p_key) const {
  194. return ConstIterator(find(p_key));
  195. }
  196. #endif
  197. private:
  198. struct _Data {
  199. Element *first = nullptr;
  200. Element *last = nullptr;
  201. int size_cache = 0;
  202. bool erase(Element *p_I) {
  203. ERR_FAIL_NULL_V(p_I, false);
  204. ERR_FAIL_COND_V(p_I->data != this, false);
  205. if (first == p_I) {
  206. first = p_I->next_ptr;
  207. }
  208. if (last == p_I) {
  209. last = p_I->prev_ptr;
  210. }
  211. if (p_I->prev_ptr) {
  212. p_I->prev_ptr->next_ptr = p_I->next_ptr;
  213. }
  214. if (p_I->next_ptr) {
  215. p_I->next_ptr->prev_ptr = p_I->prev_ptr;
  216. }
  217. memdelete_allocator<Element, A>(p_I);
  218. size_cache--;
  219. return true;
  220. }
  221. };
  222. _Data *_data = nullptr;
  223. public:
  224. /**
  225. * return a const iterator to the beginning of the list.
  226. */
  227. _FORCE_INLINE_ const Element *front() const {
  228. return _data ? _data->first : nullptr;
  229. }
  230. /**
  231. * return an iterator to the beginning of the list.
  232. */
  233. _FORCE_INLINE_ Element *front() {
  234. return _data ? _data->first : nullptr;
  235. }
  236. /**
  237. * return a const iterator to the last member of the list.
  238. */
  239. _FORCE_INLINE_ const Element *back() const {
  240. return _data ? _data->last : nullptr;
  241. }
  242. /**
  243. * return an iterator to the last member of the list.
  244. */
  245. _FORCE_INLINE_ Element *back() {
  246. return _data ? _data->last : nullptr;
  247. }
  248. /**
  249. * store a new element at the end of the list
  250. */
  251. Element *push_back(const T &value) {
  252. if (!_data) {
  253. _data = memnew_allocator(_Data, A);
  254. _data->first = nullptr;
  255. _data->last = nullptr;
  256. _data->size_cache = 0;
  257. }
  258. Element *n = memnew_allocator(Element, A);
  259. n->value = (T &)value;
  260. n->prev_ptr = _data->last;
  261. n->next_ptr = nullptr;
  262. n->data = _data;
  263. if (_data->last) {
  264. _data->last->next_ptr = n;
  265. }
  266. _data->last = n;
  267. if (!_data->first) {
  268. _data->first = n;
  269. }
  270. _data->size_cache++;
  271. return n;
  272. }
  273. void pop_back() {
  274. if (_data && _data->last) {
  275. erase(_data->last);
  276. }
  277. }
  278. /**
  279. * store a new element at the beginning of the list
  280. */
  281. Element *push_front(const T &value) {
  282. if (!_data) {
  283. _data = memnew_allocator(_Data, A);
  284. _data->first = nullptr;
  285. _data->last = nullptr;
  286. _data->size_cache = 0;
  287. }
  288. Element *n = memnew_allocator(Element, A);
  289. n->value = (T &)value;
  290. n->prev_ptr = nullptr;
  291. n->next_ptr = _data->first;
  292. n->data = _data;
  293. if (_data->first) {
  294. _data->first->prev_ptr = n;
  295. }
  296. _data->first = n;
  297. if (!_data->last) {
  298. _data->last = n;
  299. }
  300. _data->size_cache++;
  301. return n;
  302. }
  303. void pop_front() {
  304. if (_data && _data->first) {
  305. erase(_data->first);
  306. }
  307. }
  308. Element *insert_after(Element *p_element, const T &p_value) {
  309. CRASH_COND(p_element && (!_data || p_element->data != _data));
  310. if (!p_element) {
  311. return push_back(p_value);
  312. }
  313. Element *n = memnew_allocator(Element, A);
  314. n->value = (T &)p_value;
  315. n->prev_ptr = p_element;
  316. n->next_ptr = p_element->next_ptr;
  317. n->data = _data;
  318. if (!p_element->next_ptr) {
  319. _data->last = n;
  320. } else {
  321. p_element->next_ptr->prev_ptr = n;
  322. }
  323. p_element->next_ptr = n;
  324. _data->size_cache++;
  325. return n;
  326. }
  327. Element *insert_before(Element *p_element, const T &p_value) {
  328. CRASH_COND(p_element && (!_data || p_element->data != _data));
  329. if (!p_element) {
  330. return push_back(p_value);
  331. }
  332. Element *n = memnew_allocator(Element, A);
  333. n->value = (T &)p_value;
  334. n->prev_ptr = p_element->prev_ptr;
  335. n->next_ptr = p_element;
  336. n->data = _data;
  337. if (!p_element->prev_ptr) {
  338. _data->first = n;
  339. } else {
  340. p_element->prev_ptr->next_ptr = n;
  341. }
  342. p_element->prev_ptr = n;
  343. _data->size_cache++;
  344. return n;
  345. }
  346. /**
  347. * find an element in the list,
  348. */
  349. template <typename T_v>
  350. Element *find(const T_v &p_val) {
  351. Element *it = front();
  352. while (it) {
  353. if (it->value == p_val) {
  354. return it;
  355. }
  356. it = it->next();
  357. }
  358. return nullptr;
  359. }
  360. /**
  361. * erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
  362. */
  363. bool erase(Element *p_I) {
  364. if (_data && p_I) {
  365. bool ret = _data->erase(p_I);
  366. if (_data->size_cache == 0) {
  367. memdelete_allocator<_Data, A>(_data);
  368. _data = nullptr;
  369. }
  370. return ret;
  371. }
  372. return false;
  373. }
  374. /**
  375. * erase the first element in the list, that contains value
  376. */
  377. bool erase(const T &value) {
  378. Element *I = find(value);
  379. return erase(I);
  380. }
  381. /**
  382. * return whether the list is empty
  383. */
  384. _FORCE_INLINE_ bool is_empty() const {
  385. return (!_data || !_data->size_cache);
  386. }
  387. /**
  388. * clear the list
  389. */
  390. void clear() {
  391. while (front()) {
  392. erase(front());
  393. }
  394. }
  395. _FORCE_INLINE_ int size() const {
  396. return _data ? _data->size_cache : 0;
  397. }
  398. void swap(Element *p_A, Element *p_B) {
  399. ERR_FAIL_COND(!p_A || !p_B);
  400. ERR_FAIL_COND(p_A->data != _data);
  401. ERR_FAIL_COND(p_B->data != _data);
  402. if (p_A == p_B) {
  403. return;
  404. }
  405. Element *A_prev = p_A->prev_ptr;
  406. Element *A_next = p_A->next_ptr;
  407. Element *B_prev = p_B->prev_ptr;
  408. Element *B_next = p_B->next_ptr;
  409. if (A_prev) {
  410. A_prev->next_ptr = p_B;
  411. } else {
  412. _data->first = p_B;
  413. }
  414. if (B_prev) {
  415. B_prev->next_ptr = p_A;
  416. } else {
  417. _data->first = p_A;
  418. }
  419. if (A_next) {
  420. A_next->prev_ptr = p_B;
  421. } else {
  422. _data->last = p_B;
  423. }
  424. if (B_next) {
  425. B_next->prev_ptr = p_A;
  426. } else {
  427. _data->last = p_A;
  428. }
  429. p_A->prev_ptr = A_next == p_B ? p_B : B_prev;
  430. p_A->next_ptr = B_next == p_A ? p_B : B_next;
  431. p_B->prev_ptr = B_next == p_A ? p_A : A_prev;
  432. p_B->next_ptr = A_next == p_B ? p_A : A_next;
  433. }
  434. /**
  435. * copy the list
  436. */
  437. void operator=(const List &p_list) {
  438. clear();
  439. const Element *it = p_list.front();
  440. while (it) {
  441. push_back(it->get());
  442. it = it->next();
  443. }
  444. }
  445. void operator=(List &&p_list) {
  446. if (unlikely(this == &p_list)) {
  447. return;
  448. }
  449. clear();
  450. _data = p_list._data;
  451. p_list._data = nullptr;
  452. }
  453. // Random access to elements, use with care,
  454. // do not use for iteration.
  455. T &get(int p_index) {
  456. CRASH_BAD_INDEX(p_index, size());
  457. Element *I = front();
  458. int c = 0;
  459. while (c < p_index) {
  460. I = I->next();
  461. c++;
  462. }
  463. return I->get();
  464. }
  465. // Random access to elements, use with care,
  466. // do not use for iteration.
  467. const T &get(int p_index) const {
  468. CRASH_BAD_INDEX(p_index, size());
  469. const Element *I = front();
  470. int c = 0;
  471. while (c < p_index) {
  472. I = I->next();
  473. c++;
  474. }
  475. return I->get();
  476. }
  477. void move_to_back(Element *p_I) {
  478. ERR_FAIL_COND(p_I->data != _data);
  479. if (!p_I->next_ptr) {
  480. return;
  481. }
  482. if (_data->first == p_I) {
  483. _data->first = p_I->next_ptr;
  484. }
  485. if (_data->last == p_I) {
  486. _data->last = p_I->prev_ptr;
  487. }
  488. if (p_I->prev_ptr) {
  489. p_I->prev_ptr->next_ptr = p_I->next_ptr;
  490. }
  491. p_I->next_ptr->prev_ptr = p_I->prev_ptr;
  492. _data->last->next_ptr = p_I;
  493. p_I->prev_ptr = _data->last;
  494. p_I->next_ptr = nullptr;
  495. _data->last = p_I;
  496. }
  497. void reverse() {
  498. int s = size() / 2;
  499. Element *F = front();
  500. Element *B = back();
  501. for (int i = 0; i < s; i++) {
  502. SWAP(F->value, B->value);
  503. F = F->next();
  504. B = B->prev();
  505. }
  506. }
  507. void move_to_front(Element *p_I) {
  508. ERR_FAIL_COND(p_I->data != _data);
  509. if (!p_I->prev_ptr) {
  510. return;
  511. }
  512. if (_data->first == p_I) {
  513. _data->first = p_I->next_ptr;
  514. }
  515. if (_data->last == p_I) {
  516. _data->last = p_I->prev_ptr;
  517. }
  518. p_I->prev_ptr->next_ptr = p_I->next_ptr;
  519. if (p_I->next_ptr) {
  520. p_I->next_ptr->prev_ptr = p_I->prev_ptr;
  521. }
  522. _data->first->prev_ptr = p_I;
  523. p_I->next_ptr = _data->first;
  524. p_I->prev_ptr = nullptr;
  525. _data->first = p_I;
  526. }
  527. void move_before(Element *value, Element *where) {
  528. if (value->prev_ptr) {
  529. value->prev_ptr->next_ptr = value->next_ptr;
  530. } else {
  531. _data->first = value->next_ptr;
  532. }
  533. if (value->next_ptr) {
  534. value->next_ptr->prev_ptr = value->prev_ptr;
  535. } else {
  536. _data->last = value->prev_ptr;
  537. }
  538. value->next_ptr = where;
  539. if (!where) {
  540. value->prev_ptr = _data->last;
  541. _data->last = value;
  542. return;
  543. }
  544. value->prev_ptr = where->prev_ptr;
  545. if (where->prev_ptr) {
  546. where->prev_ptr->next_ptr = value;
  547. } else {
  548. _data->first = value;
  549. }
  550. where->prev_ptr = value;
  551. }
  552. /**
  553. * simple insertion sort
  554. */
  555. void sort() {
  556. sort_custom<Comparator<T>>();
  557. }
  558. template <typename C>
  559. void sort_custom_inplace() {
  560. if (size() < 2) {
  561. return;
  562. }
  563. Element *from = front();
  564. Element *current = from;
  565. Element *to = from;
  566. while (current) {
  567. Element *next = current->next_ptr;
  568. if (from != current) {
  569. current->prev_ptr = nullptr;
  570. current->next_ptr = from;
  571. Element *find = from;
  572. C less;
  573. while (find && less(find->value, current->value)) {
  574. current->prev_ptr = find;
  575. current->next_ptr = find->next_ptr;
  576. find = find->next_ptr;
  577. }
  578. if (current->prev_ptr) {
  579. current->prev_ptr->next_ptr = current;
  580. } else {
  581. from = current;
  582. }
  583. if (current->next_ptr) {
  584. current->next_ptr->prev_ptr = current;
  585. } else {
  586. to = current;
  587. }
  588. } else {
  589. current->prev_ptr = nullptr;
  590. current->next_ptr = nullptr;
  591. }
  592. current = next;
  593. }
  594. _data->first = from;
  595. _data->last = to;
  596. }
  597. template <typename C>
  598. struct AuxiliaryComparator {
  599. C compare;
  600. _FORCE_INLINE_ bool operator()(const Element *a, const Element *b) const {
  601. return compare(a->value, b->value);
  602. }
  603. };
  604. template <typename C>
  605. void sort_custom() {
  606. //this version uses auxiliary memory for speed.
  607. //if you don't want to use auxiliary memory, use the in_place version
  608. int s = size();
  609. if (s < 2) {
  610. return;
  611. }
  612. Element **aux_buffer = memnew_arr(Element *, s);
  613. int idx = 0;
  614. for (Element *E = front(); E; E = E->next_ptr) {
  615. aux_buffer[idx] = E;
  616. idx++;
  617. }
  618. SortArray<Element *, AuxiliaryComparator<C>> sort;
  619. sort.sort(aux_buffer, s);
  620. _data->first = aux_buffer[0];
  621. aux_buffer[0]->prev_ptr = nullptr;
  622. aux_buffer[0]->next_ptr = aux_buffer[1];
  623. _data->last = aux_buffer[s - 1];
  624. aux_buffer[s - 1]->prev_ptr = aux_buffer[s - 2];
  625. aux_buffer[s - 1]->next_ptr = nullptr;
  626. for (int i = 1; i < s - 1; i++) {
  627. aux_buffer[i]->prev_ptr = aux_buffer[i - 1];
  628. aux_buffer[i]->next_ptr = aux_buffer[i + 1];
  629. }
  630. memdelete_arr(aux_buffer);
  631. }
  632. const void *id() const {
  633. return (void *)_data;
  634. }
  635. /**
  636. * copy constructor for the list
  637. */
  638. List(const List &p_list) {
  639. const Element *it = p_list.front();
  640. while (it) {
  641. push_back(it->get());
  642. it = it->next();
  643. }
  644. }
  645. List(List &&p_list) {
  646. _data = p_list._data;
  647. p_list._data = nullptr;
  648. }
  649. List() {}
  650. List(std::initializer_list<T> p_init) {
  651. for (const T &E : p_init) {
  652. push_back(E);
  653. }
  654. }
  655. ~List() {
  656. clear();
  657. if (_data) {
  658. ERR_FAIL_COND(_data->size_cache);
  659. memdelete_allocator<_Data, A>(_data);
  660. }
  661. }
  662. };
  663. template <typename T, typename A>
  664. void List<T, A>::Element::transfer_to_back(List<T, A> *p_dst_list) {
  665. // Detach from current.
  666. if (data->first == this) {
  667. data->first = data->first->next_ptr;
  668. }
  669. if (data->last == this) {
  670. data->last = data->last->prev_ptr;
  671. }
  672. if (prev_ptr) {
  673. prev_ptr->next_ptr = next_ptr;
  674. }
  675. if (next_ptr) {
  676. next_ptr->prev_ptr = prev_ptr;
  677. }
  678. data->size_cache--;
  679. // Attach to the back of the new one.
  680. if (!p_dst_list->_data) {
  681. p_dst_list->_data = memnew_allocator(_Data, A);
  682. p_dst_list->_data->first = this;
  683. p_dst_list->_data->last = nullptr;
  684. p_dst_list->_data->size_cache = 0;
  685. prev_ptr = nullptr;
  686. } else {
  687. p_dst_list->_data->last->next_ptr = this;
  688. prev_ptr = p_dst_list->_data->last;
  689. }
  690. p_dst_list->_data->last = this;
  691. next_ptr = nullptr;
  692. data = p_dst_list->_data;
  693. p_dst_list->_data->size_cache++;
  694. }
  695. #endif // LIST_H