diff options
| author | Tyge Løvset <[email protected]> | 2021-12-14 20:44:04 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-12-14 20:44:04 +0100 |
| commit | 7f5a269d5a13ba39da7c2fa8e9bf45e77c5755c6 (patch) | |
| tree | a5c8514ded9ebe61884ff718f397cf556256c5f6 | |
| parent | 6749cc21a2045d307c239d82891cb860687dfd2a (diff) | |
| download | STC-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
| -rw-r--r-- | docs/cpque_api.md | 1 | ||||
| -rw-r--r-- | examples/box2.c | 16 | ||||
| -rw-r--r-- | include/stc/cpque.h | 7 |
3 files changed, 15 insertions, 9 deletions
diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 8f01e4c9..ddc0532c 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -27,6 +27,7 @@ cpque_X cpque_X_clone(cpque_X pq); void cpque_X_clear(cpque_X* self); bool cpque_X_reserve(cpque_X* self, size_t n); +void cpque_X_shrink_to_fit(cpque_X* self); void cpque_X_copy(cpque_X* self, cpque_X other); void cpque_X_del(cpque_X* self); // destructor diff --git a/examples/box2.c b/examples/box2.c index 79304609..d65ae717 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -19,16 +19,18 @@ struct { #define i_val Point
#define i_opt c_no_compare
-#include <stc/cbox.h>
-
-#define i_val cbox_Point
-#define i_opt c_no_compare
-#define i_tag BoxPoint
-#include <stc/cbox.h>
+#include <stc/cbox.h> // cbox_Box
#define i_val Rectangle
#define i_opt c_no_compare
-#include <stc/cbox.h>
+#include <stc/cbox.h> // cbox_Rectangle
+
+// Box in box:
+#define i_val cbox_Point
+#define i_del(b) cbox_Point_del(b)
+#define i_opt c_no_compare|c_no_clone
+#define i_tag BoxPoint
+#include <stc/cbox.h> // cbox_BoxPoint
Point origin(void) {
return (Point){ .x=0.0, .y=0.0 };
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);
}
|
