summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-14 20:44:04 +0100
committerTyge Løvset <[email protected]>2021-12-14 20:44:04 +0100
commit7f5a269d5a13ba39da7c2fa8e9bf45e77c5755c6 (patch)
treea5c8514ded9ebe61884ff718f397cf556256c5f6 /include
parent6749cc21a2045d307c239d82891cb860687dfd2a (diff)
downloadSTC-modified-7f5a269d5a13ba39da7c2fa8e9bf45e77c5755c6.tar.gz
STC-modified-7f5a269d5a13ba39da7c2fa8e9bf45e77c5755c6.zip
Fixed silly bug in cpque_X_pop(). Thanks to matthieugras. Added cpque_X_shrink_to_fit().
Fixed memory leak in example box2.c
Diffstat (limited to 'include')
-rw-r--r--include/stc/cpque.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index 86bab2ec..6b09e1d5 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -51,6 +51,9 @@ STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) {
return t ? (self->data = t, self->capacity = n) : 0;
}
+STC_INLINE void _cx_memb(_shrink_to_fit)(_cx_self* self)
+ { _cx_memb(_reserve)(self, self->size); }
+
STC_INLINE _cx_self _cx_memb(_with_capacity)(size_t cap) {
_cx_self out = {0}; _cx_memb(_reserve)(&out, cap);
return out;
@@ -136,9 +139,9 @@ STC_DEF _cx_self _cx_memb(_clone)(_cx_self q) {
STC_DEF void
_cx_memb(_erase_at)(_cx_self* self, size_t idx) {
- size_t n = _cx_memb(_size)(*self) - 1;
+ i_valdel(&self->data[idx]);
+ size_t n = --self->size;
self->data[idx] = self->data[n];
- _cx_memb(_pop_back)(self);
_cx_memb(_sift_down_)(self->data - 1, idx + 1, n);
}