From de411007bceda17457fb27ea72b4433adf744797 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 23 Dec 2021 13:21:21 +0100 Subject: Removed emplace functions if not i_valraw or i_keyraw is defined. Safety/optimize measure. --- include/stc/carc.h | 2 +- include/stc/cbox.h | 4 ++-- include/stc/cdeq.h | 12 ++++++++---- include/stc/clist.h | 17 +++++++++-------- include/stc/cmap.h | 7 ++++--- include/stc/cpque.h | 8 ++++---- include/stc/csmap.h | 7 ++++--- include/stc/cstack.h | 4 ++-- include/stc/cvec.h | 17 ++++++++++------- include/stc/template.h | 10 ++++++---- 10 files changed, 50 insertions(+), 38 deletions(-) (limited to 'include') diff --git a/include/stc/carc.h b/include/stc/carc.h index 505b47d9..b4e2e435 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -144,7 +144,7 @@ _cx_memb(_reset_from)(_cx_self* self, i_val val) { *self = _cx_memb(_from)(val); } -#if !c_option(c_no_clone) && !defined _i_valraw_default +#if !c_option(c_no_clone) && !defined _i_no_raw STC_INLINE _cx_self _cx_memb(_new)(i_valraw raw) { return _cx_memb(_from)(i_valfrom(raw)); } diff --git a/include/stc/cbox.h b/include/stc/cbox.h index fdde5e8c..7ed0d641 100644 --- a/include/stc/cbox.h +++ b/include/stc/cbox.h @@ -120,12 +120,12 @@ _cx_memb(_reset_from)(_cx_self* self, i_val val) { } #if !c_option(c_no_clone) - //#ifndef _i_valraw_default +#if !defined _i_no_raw STC_INLINE _cx_self _cx_memb(_new)(i_valraw raw) { return c_make(_cx_self){c_new(i_val, i_valfrom(raw))}; } - //#endif +#endif STC_INLINE _cx_self _cx_memb(_clone)(_cx_self other) { diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index f0866dad..97a19311 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -45,13 +45,15 @@ STC_API void _cx_memb(_clear)(_cx_self* self); STC_API void _cx_memb(_drop)(_cx_self* self); STC_API _cx_value* _cx_memb(_push_back)(_cx_self* self, i_val value); STC_API bool _cx_memb(_expand_right_half_)(_cx_self* self, size_t idx, size_t n); +STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self); #ifndef _i_queue #if !c_option(c_no_clone) -STC_API void _cx_memb(_shrink_to_fit)(_cx_self *self); STC_API _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); +#if !defined _i_no_raw STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2); +#endif #endif // !c_no_clone #if !c_option(c_no_cmp) @@ -66,8 +68,10 @@ STC_API _cx_iter _cx_memb(_insert_range_p)(_cx_self* self, _cx_value* pos #if !c_option(c_no_clone) STC_API _cx_self _cx_memb(_clone)(_cx_self cx); +#if !defined _i_no_raw STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +#endif STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { @@ -150,7 +154,7 @@ _cx_memb(_erase_range)(_cx_self* self, _cx_iter it1, _cx_iter it2) { return _cx_memb(_erase_range_p)(self, it1.ref, it2.ref); } -#if !c_option(c_no_clone) +#if !c_option(c_no_clone) && !defined _i_no_raw STC_INLINE _cx_iter _cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2) { @@ -367,7 +371,7 @@ _cx_memb(_erase_range_p)(_cx_self* self, _cx_value* p1, _cx_value* p2) { } #if !c_option(c_no_clone) - +#if !defined _i_no_raw STC_DEF _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { pos = _cx_memb(_insert_space_)(self, pos, p2 - p1); @@ -375,7 +379,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, co for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } - +#endif STC_DEF _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2) { diff --git a/include/stc/clist.h b/include/stc/clist.h index 2194067c..e2ff694e 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -109,20 +109,21 @@ STC_API _cx_node* _cx_memb(_erase_after_)(_cx_self* self, _cx_node* node); #if !c_option(c_no_clone) STC_API _cx_self _cx_memb(_clone)(_cx_self cx); -STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } -STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_front)(self, i_valfrom(raw)); } -STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw) - { return _cx_memb(_insert)(self, it, i_valfrom(raw)); } STC_INLINE i_val _cx_memb(_value_clone)(i_val val) { return i_valfrom(i_valto(&val)); } - STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->last == other.last) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } +#if !defined _i_no_raw +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +STC_INLINE _cx_value* _cx_memb(_emplace_front)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_front)(self, i_valfrom(raw)); } +STC_INLINE _cx_iter _cx_memb(_emplace)(_cx_self* self, _cx_iter it, i_valraw raw) + { return _cx_memb(_insert)(self, it, i_valfrom(raw)); } +#endif #endif STC_INLINE _cx_self _cx_memb(_init)(void) { return c_make(_cx_self){NULL}; } STC_INLINE bool _cx_memb(_reserve)(_cx_self* self, size_t n) { return true; } @@ -190,7 +191,7 @@ _cx_memb(_get_mut)(_cx_self* self, i_valraw val) { STC_DEF _cx_self _cx_memb(_clone)(_cx_self cx) { _cx_self out = _cx_memb(_init)(); - c_foreach (it, _cx_self, cx) _cx_memb(_emplace_back)(&out, i_valto(it.ref)); + c_foreach (it, _cx_self, cx) _cx_memb(_push_back)(&out, i_valfrom(i_valto(it.ref))); return out; } #endif diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 87ed7c6c..2d0b11fc 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -111,7 +111,7 @@ STC_INLINE bool _cx_memb(_contains)(const _cx_self* self, i_keyraw rkey) { return self->size && self->_hashx[_cx_memb(_bucket_)(self, &rkey).idx]; } #ifndef _i_isset - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); #endif STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key _key, i_val _mapped); @@ -141,7 +141,7 @@ _cx_memb(_value_clone)(_cx_value _val) { _i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); ) return _val; } - +#if !defined _i_no_raw STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) { _cx_result _res = _cx_memb(_insert_entry_)(self, rkey); @@ -151,6 +151,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped) } return _res; } +#endif #endif // !c_no_clone STC_INLINE _cx_raw @@ -273,7 +274,7 @@ STC_DEF void _cx_memb(_clear)(_cx_self* self) { else { i_keydrop(&_key); i_valdrop(&_res.ref->second); } _res.ref->second = _mapped; return _res; } - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { _cx_result _res = _cx_memb(_insert_entry_)(self, rkey); diff --git a/include/stc/cpque.h b/include/stc/cpque.h index caea1549..bf519125 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -99,12 +99,12 @@ STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } - -STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_value val) - { _cx_memb(_push)(self, i_valfrom(val)); } - STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(val); } +#if !defined _i_no_raw +STC_INLINE void _cx_memb(_emplace)(_cx_self* self, _cx_value val) + { _cx_memb(_push)(self, i_valfrom(val)); } +#endif #endif /* -------------------------- IMPLEMENTATION ------------------------- */ diff --git a/include/stc/csmap.h b/include/stc/csmap.h index 8115cf46..fb8c868e 100644 --- a/include/stc/csmap.h +++ b/include/stc/csmap.h @@ -147,7 +147,7 @@ _cx_memb(_value_drop)(_cx_value* val) { } #ifndef _i_isset - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_API _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped); #endif STC_API _cx_result _cx_memb(_insert_or_assign)(_cx_self* self, i_key key, i_val mapped); @@ -181,7 +181,7 @@ _cx_memb(_value_clone)(_cx_value _val) { _i_MAP_ONLY( _val.second = i_valfrom(i_valto(&_val.second)); ) return _val; } - +#if !defined _i_no_raw STC_INLINE _cx_result _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped)) { _cx_result res = _cx_memb(_insert_entry_)(self, rkey); @@ -191,6 +191,7 @@ _cx_memb(_emplace)(_cx_self* self, i_keyraw rkey _i_MAP_ONLY(, i_valraw rmapped) } return res; } +#endif #endif // !c_no_clone STC_INLINE _cx_result @@ -289,7 +290,7 @@ _cx_memb(_node_new_)(_cx_self* self, int level) { else { i_keydrop(&key); i_valdrop(&res.ref->second); } res.ref->second = mapped; return res; } - #if !c_option(c_no_clone) + #if !c_option(c_no_clone) && !defined _i_no_raw STC_DEF _cx_result _cx_memb(_emplace_or_assign)(_cx_self* self, i_keyraw rkey, i_valraw rmapped) { _cx_result res = _cx_memb(_insert_entry_)(self, rkey); diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 387c0126..1ceec0cb 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -95,10 +95,10 @@ STC_INLINE const _cx_value* _cx_memb(_at)(const _cx_self* self, size_t idx) { assert(idx < self->size); return self->data + idx; } #if !c_option(c_no_clone) - +#if !defined _i_no_raw STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, _cx_raw raw) { return _cx_memb(_push)(self, i_valfrom(raw)); } - +#endif STC_INLINE _cx_self _cx_memb(_clone)(_cx_self v) { _cx_self out = {(_cx_value *) c_malloc(v.size*sizeof(_cx_value)), v.size, v.size}; for (size_t i = 0; i < v.size; ++i, ++v.data) out.data[i] = i_valfrom(i_valto(v.data)); diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 3486cc37..1faa16c3 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -97,20 +97,21 @@ STC_API _cx_iter _cx_memb(_bsearch_in)(_cx_iter it1, _cx_iter it2, i_valr STC_API _cx_self _cx_memb(_clone)(_cx_self cx); STC_API _cx_iter _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, const _cx_value* p1, const _cx_value* p2); -STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, - const _cx_raw* p1, const _cx_raw* p2); STC_INLINE i_val _cx_memb(_value_clone)(_cx_value val) { return i_valfrom(i_valto(&val)); } STC_INLINE i_val _cx_memb(_value_fromraw)(i_valraw raw) { return i_valfrom(raw); } -STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } -STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, i_valraw raw) - { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE void _cx_memb(_copy)(_cx_self *self, _cx_self other) { if (self->data == other.data) return; _cx_memb(_drop)(self); *self = _cx_memb(_clone)(other); } +#if !defined _i_no_raw +STC_API _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, + const _cx_raw* p1, const _cx_raw* p2); +STC_INLINE _cx_value* _cx_memb(_emplace_back)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } +STC_INLINE _cx_value* _cx_memb(_emplace)(_cx_self* self, i_valraw raw) + { return _cx_memb(_push_back)(self, i_valfrom(raw)); } STC_INLINE _cx_iter _cx_memb(_emplace_n)(_cx_self* self, const size_t idx, const _cx_raw arr[], const size_t n) { return _cx_memb(_emplace_range_p)(self, self->data + idx, arr, arr + n); @@ -124,6 +125,7 @@ _cx_memb(_emplace_range)(_cx_self* self, _cx_iter it, _cx_iter it1, _cx_iter it2 return _cx_memb(_clone_range_p)(self, it.ref, it1.ref, it2.ref); } #endif +#endif STC_INLINE size_t _cx_memb(_size)(_cx_self cx) { return cvec_rep_(&cx)->size; } STC_INLINE size_t _cx_memb(_capacity)(_cx_self cx) { return cvec_rep_(&cx)->cap; } @@ -347,7 +349,7 @@ _cx_memb(_clone_range_p)(_cx_self* self, _cx_value* pos, for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); return it; } - +#if !defined _i_no_raw STC_DEF _cx_iter _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, const _cx_raw* p1, const _cx_raw* p2) { @@ -357,6 +359,7 @@ _cx_memb(_emplace_range_p)(_cx_self* self, _cx_value* pos, return it; } #endif +#endif #if !c_option(c_no_cmp) diff --git a/include/stc/template.h b/include/stc/template.h index 5efe3772..7d5c70b9 100644 --- a/include/stc/template.h +++ b/include/stc/template.h @@ -165,7 +165,7 @@ #define i_keyfrom c_default_clone #endif #ifndef i_keyraw - #define _i_keyraw_default + #define _i_no_keyraw #define i_keyraw i_key #define i_keyto c_default_toraw #endif @@ -191,7 +191,9 @@ #define i_valfrom c_default_clone #endif #ifndef i_valraw - #define _i_valraw_default + #if !defined i_key || defined _i_no_keyraw + #define _i_no_raw + #endif #define i_valraw i_val #define i_valto c_default_toraw #endif @@ -236,8 +238,8 @@ #undef i_keydrop #undef _i_prefix -#undef _i_valraw_default -#undef _i_keyraw_default +#undef _i_no_raw +#undef _i_no_keyraw #undef _i_has_internal_clone #undef _i_template #endif -- cgit v1.2.3