diff options
| author | Tyge Løvset <[email protected]> | 2022-04-21 13:47:54 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-04-21 13:47:54 +0200 |
| commit | d122c77b5a755cd5b3211c26346a84bb2b27cdce (patch) | |
| tree | a66aba11b04670c84cca9034e7266014e2052e8f /include/stc/carc.h | |
| parent | 91385d449d03145cfe8cc91f2704d4b24c63d37e (diff) | |
| download | STC-modified-d122c77b5a755cd5b3211c26346a84bb2b27cdce.tar.gz STC-modified-d122c77b5a755cd5b3211c26346a84bb2b27cdce.zip | |
Switched to use i_key as primary template type parameter for all containers. Only maps will actually use i_val.
Users can still specify i_val for non-maps, so there are no usability changes, other than the option to use i_key always, which makes the implementation and switching between container types simpler.
Diffstat (limited to 'include/stc/carc.h')
| -rw-r--r-- | include/stc/carc.h | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/include/stc/carc.h b/include/stc/carc.h index 7f9c4390..54ba3159 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -35,8 +35,8 @@ void Person_drop(Person* p) { }
#define i_tag person
-#define i_val Person
-#define i_valdrop Person_drop
+#define i_key Person
+#define i_keydrop Person_drop
#include <stc/carc.h>
int main() {
@@ -75,7 +75,7 @@ int main() { #define _i_prefix carc_
#endif
#include "template.h"
-typedef i_valraw _cx_raw;
+typedef i_keyraw _cx_raw;
#if !c_option(c_no_atomic)
#define _i_atomic_inc(v) c_atomic_inc(v)
@@ -85,9 +85,9 @@ typedef i_valraw _cx_raw; #define _i_atomic_dec_and_test(v) !(--*(v))
#endif
#if !c_option(c_is_fwd)
-_cx_deftypes(_c_carc_types, _cx_self, i_val);
+_cx_deftypes(_c_carc_types, _cx_self, i_key);
#endif
-_cx_carc_rep { long counter; i_val value; };
+_cx_carc_rep { long counter; i_key value; };
STC_INLINE _cx_self
_cx_memb(_init)(void) { return c_make(_cx_self){NULL, NULL}; }
@@ -103,14 +103,14 @@ _cx_memb(_from_ptr)(_cx_value* p) { }
STC_INLINE _cx_self
-_cx_memb(_from)(i_val val) { // c++: std::make_shared<i_val>(val)
+_cx_memb(_from)(i_key val) { // c++: std::make_shared<i_key>(val)
_cx_self ptr; _cx_carc_rep *rep = c_alloc(_cx_carc_rep);
*(ptr.use_count = &rep->counter) = 1;
*(ptr.get = &rep->value) = val;
return ptr;
}
-STC_INLINE i_val _cx_memb(_toraw)(const _cx_self* self) {
+STC_INLINE i_key _cx_memb(_toraw)(const _cx_self* self) {
return *self->get;
}
@@ -124,7 +124,7 @@ _cx_memb(_move)(_cx_self* self) { STC_INLINE void
_cx_memb(_drop)(_cx_self* self) {
if (self->use_count && _i_atomic_dec_and_test(self->use_count)) {
- i_valdrop(self->get);
+ i_keydrop(self->get);
if (self->get != &((_cx_carc_rep *)self->use_count)->value)
c_free(self->get);
c_free(self->use_count);
@@ -138,17 +138,17 @@ _cx_memb(_reset)(_cx_self* self) { }
STC_INLINE void
-_cx_memb(_reset_from)(_cx_self* self, i_val val) {
+_cx_memb(_reset_from)(_cx_self* self, i_key val) {
_cx_memb(_drop)(self);
*self = _cx_memb(_from)(val);
}
#if !defined _i_no_clone
STC_INLINE _cx_self
- _cx_memb(_make)(_cx_raw raw) { return _cx_memb(_from)(i_valfrom(raw)); }
+ _cx_memb(_make)(_cx_raw raw) { return _cx_memb(_from)(i_keyfrom(raw)); }
#endif // !_i_no_clone
-// does not use i_valfrom, so we can bypass c_no_clone
+// does not use i_keyfrom, so we can bypass c_no_clone
STC_INLINE _cx_self
_cx_memb(_clone)(_cx_self ptr) {
if (ptr.use_count) _i_atomic_inc(ptr.use_count);
@@ -175,7 +175,7 @@ _cx_memb(_value_hash)(const _cx_value* x, size_t n) { #elif c_option(c_no_cmp)
return c_hash32(&x, 4);
#else
- _cx_raw rx = i_valto(x);
+ _cx_raw rx = i_keyto(x);
return i_hash((&rx), (sizeof rx));
#endif
}
@@ -185,7 +185,7 @@ _cx_memb(_value_cmp)(const _cx_value* x, const _cx_value* y) { #if c_option(c_no_cmp)
return c_default_cmp(&x, &y);
#else
- _cx_raw rx = i_valto(x), ry = i_valto(y);
+ _cx_raw rx = i_keyto(x), ry = i_keyto(y);
return i_cmp((&rx), (&ry));
#endif
}
@@ -195,7 +195,7 @@ _cx_memb(_value_eq)(const _cx_value* x, const _cx_value* y) { #if c_option(c_no_cmp)
return x == y;
#else
- _cx_raw rx = i_valto(x), ry = i_valto(y);
+ _cx_raw rx = i_keyto(x), ry = i_keyto(y);
return i_eq((&rx), (&ry));
#endif
}
|
