summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-06 11:40:41 +0100
committerTyge Løvset <[email protected]>2023-01-06 11:40:41 +0100
commit7abea5ab04bffebbedfad7bd8d9c5c26170d19af (patch)
tree25f1aa511aa27198c31b7bad13ae137dd52828ad /include
parentdd1ac09cd54e2632ec9d272ec578cde67a5edd01 (diff)
downloadSTC-modified-7abea5ab04bffebbedfad7bd8d9c5c26170d19af.tar.gz
STC-modified-7abea5ab04bffebbedfad7bd8d9c5c26170d19af.zip
Removed swap() function from all containers. Use safe c_SWAP() macro instead.
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h5
-rw-r--r--include/stc/cdeq.h1
-rw-r--r--include/stc/cmap.h3
-rw-r--r--include/stc/csmap.h1
-rw-r--r--include/stc/cvec.h1
5 files changed, 4 insertions, 7 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 220b0037..6bc5a2a5 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -85,8 +85,9 @@
#define c_FREE(p) free(p)
#endif
-#define c_DELETE(T, ptr) do { T *_c_p = ptr; T##_drop(_c_p); c_FREE(_c_p); } while (0)
-#define c_SWAP(T, x, y) do { T _c_t = x; x = y; y = _c_t; } while (0)
+#define c_DELETE(T, ptr) do { T *_tp = ptr; T##_drop(_tp); c_FREE(_tp); } while (0)
+#define c_SWAP(T, xp, yp) do { T *_xp = xp, *_yp = yp, \
+ _tv = *_xp; *_xp = *_yp; *_yp = _tv; } while (0)
#define c_ARRAYLEN(a) (sizeof (a)/sizeof *(a))
// x and y are i_keyraw* type, defaults to i_key*:
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 47d336f1..1fe52548 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -90,7 +90,6 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* self) { return self->_le
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { return self->_cap; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return !self->_len; }
STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* pval) { return i_keyto(pval); }
-STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); }
STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; }
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
{ return self->data + self->_len - 1; }
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 20375051..df3ce6fc 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -115,7 +115,6 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* map) { return map->size;
STC_INLINE size_t _cx_memb(_bucket_count)(_cx_self* map) { return map->bucket_count; }
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* map)
{ return (size_t)((float)map->bucket_count * (i_max_load_factor)); }
-STC_INLINE void _cx_memb(_swap)(_cx_self *map1, _cx_self *map2) {c_SWAP(_cx_self, *map1, *map2); }
STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey)
{ return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; }
@@ -416,7 +415,7 @@ _cx_memb(_reserve)(_cx_self* self, const size_t _newcap) {
m.table[b.idx] = *e;
m._hashx[b.idx] = (uint8_t)b.hx;
}
- c_SWAP(_cx_self, *self, m);
+ c_SWAP(_cx_self, self, &m);
}
c_FREE(m._hashx);
c_FREE(m.table);
diff --git a/include/stc/csmap.h b/include/stc/csmap.h
index 0af55b2b..e5df0fe2 100644
--- a/include/stc/csmap.h
+++ b/include/stc/csmap.h
@@ -120,7 +120,6 @@ STC_API void _cx_memb(_next)(_cx_iter* it);
STC_INLINE bool _cx_memb(_empty)(const _cx_self* cx) { return cx->size == 0; }
STC_INLINE size_t _cx_memb(_size)(const _cx_self* cx) { return cx->size; }
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* cx) { return cx->cap; }
-STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); }
STC_INLINE _cx_iter _cx_memb(_find)(const _cx_self* self, _cx_rawkey rkey)
{ _cx_iter it; _cx_memb(_find_it)(self, rkey, &it); return it; }
STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, _cx_rawkey rkey)
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index 64876b9b..fbacd305 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -128,7 +128,6 @@ STC_INLINE size_t _cx_memb(_size)(const _cx_self* self) { return self->_le
STC_INLINE size_t _cx_memb(_capacity)(const _cx_self* self) { return self->_cap; }
STC_INLINE bool _cx_memb(_empty)(const _cx_self* self) { return !self->_len; }
STC_INLINE _cx_raw _cx_memb(_value_toraw)(const _cx_value* val) { return i_keyto(val); }
-STC_INLINE void _cx_memb(_swap)(_cx_self* a, _cx_self* b) { c_SWAP(_cx_self, *a, *b); }
STC_INLINE _cx_value* _cx_memb(_front)(const _cx_self* self) { return self->data; }
STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
{ return self->data + self->_len - 1; }