summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-21 10:39:25 +0100
committerTyge Løvset <[email protected]>2021-12-21 10:39:25 +0100
commit99f677c8bdee5c243c1415ffc00cf7bae76f80b4 (patch)
tree4dbfcc0781c43250d258abf20df7b8245410c67c
parent85d01062dc86821513bf9c306231aceca5bab222 (diff)
downloadSTC-modified-99f677c8bdee5c243c1415ffc00cf7bae76f80b4.tar.gz
STC-modified-99f677c8bdee5c243c1415ffc00cf7bae76f80b4.zip
Fixed and simplified cbox and csptr.
-rw-r--r--include/stc/cbox.h22
-rw-r--r--include/stc/csptr.h42
2 files changed, 20 insertions, 44 deletions
diff --git a/include/stc/cbox.h b/include/stc/cbox.h
index 764761fe..f33e89bd 100644
--- a/include/stc/cbox.h
+++ b/include/stc/cbox.h
@@ -83,7 +83,7 @@ STC_INLINE _cx_self
_cx_memb(_init)(void) { return c_make(_cx_self){NULL}; }
STC_INLINE _cx_self
-_cx_memb(_with)(i_val* p) { return c_make(_cx_self){p}; }
+_cx_memb(_from_ptr)(i_val* p) { return c_make(_cx_self){p}; }
STC_INLINE _cx_self
_cx_memb(_new)(i_val val) {
@@ -107,12 +107,6 @@ _cx_memb(_reset)(_cx_self* self) {
_cx_memb(_drop)(self); self->get = NULL;
}
-// take ownership of *p
-STC_INLINE void
-_cx_memb(_reset_with)(_cx_self* self, _cx_value* p) {
- _cx_memb(_drop)(self); self->get = p;
-}
-
// take ownership of val
STC_INLINE void
_cx_memb(_reset_new)(_cx_self* self, i_val val) {
@@ -125,10 +119,6 @@ _cx_memb(_reset_new)(_cx_self* self, i_val val) {
_cx_memb(_from)(i_valraw raw) {
return c_make(_cx_self){c_new(i_val, i_valfrom(raw))};
}
- STC_INLINE i_valraw
- _cx_memb(_toraw)(const _cx_self* self) {
- return i_valto(self->get);
- }
STC_INLINE _cx_self
_cx_memb(_clone)(_cx_self other) {
@@ -139,8 +129,8 @@ _cx_memb(_reset_new)(_cx_self* self, i_val val) {
STC_INLINE void
_cx_memb(_copy)(_cx_self* self, _cx_self other) {
if (self->get == other.get) return;
- if (other.get) _cx_memb(_reset_new)(self, *other.get);
- else _cx_memb(_reset)(self);
+ _cx_memb(_reset)(self);
+ *self = _cx_memb(_clone)(other);
}
#endif
@@ -157,7 +147,8 @@ _cx_memb(_hash)(const _cx_self* self, size_t n) {
#elif c_option(c_no_cmp)
return c_hash32(&self->get, 4);
#else
- return i_hash(self->get, sizeof *self->get);
+ i_valraw rx = i_valto(self->get);
+ return i_hash(&rx, sizeof rx);
#endif
}
@@ -166,7 +157,8 @@ _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x->get, &y->get);
#else
- return i_cmp(x->get, y->get);
+ i_valraw rx = i_valto(x->get), ry = i_valto(x->get);
+ return i_cmp(&rx, &ry);
#endif
}
diff --git a/include/stc/csptr.h b/include/stc/csptr.h
index cf1a5b12..4c35c06b 100644
--- a/include/stc/csptr.h
+++ b/include/stc/csptr.h
@@ -97,33 +97,19 @@ STC_INLINE long
_cx_memb(_use_count)(_cx_self ptr) { return ptr.use_count ? *ptr.use_count : 0; }
STC_INLINE _cx_self
-_cx_memb(_with)(_cx_value* p) {
+_cx_memb(_from_ptr)(_cx_value* p) {
_cx_self ptr = {p};
if (p) *(ptr.use_count = c_alloc(long)) = 1;
return ptr;
}
STC_INLINE _cx_self
-_cx_memb(_view)(const _cx_value* p) {
- _cx_self ptr = {(_cx_value*) p};
- return ptr;
-}
-
-STC_INLINE _cx_self
_cx_memb(_new)(i_val val) {
_cx_self ptr; _cx_csptr_rep *rep = c_alloc(_cx_csptr_rep);
*(ptr.use_count = &rep->counter) = 1;
*(ptr.get = &rep->value) = val;
return ptr;
}
-STC_INLINE _cx_self _cx_memb(_make)(i_val val) // [deprecated]
- { return _cx_memb(_new)(val); }
-
-STC_INLINE _cx_self // does not use i_valfrom, so we can bypass c_no_clone
-_cx_memb(_clone)(_cx_self ptr) {
- if (ptr.use_count) _i_atomic_inc(ptr.use_count);
- return ptr;
-}
STC_INLINE _cx_self
_cx_memb(_move)(_cx_self* self) {
@@ -149,12 +135,6 @@ _cx_memb(_reset)(_cx_self* self) {
}
STC_INLINE void
-_cx_memb(_reset_with)(_cx_self* self, _cx_value* p) {
- _cx_memb(_drop)(self);
- *self = _cx_memb(_with)(p);
-}
-
-STC_INLINE void
_cx_memb(_reset_new)(_cx_self* self, i_val val) {
_cx_memb(_drop)(self);
*self = _cx_memb(_new)(val);
@@ -163,14 +143,16 @@ _cx_memb(_reset_new)(_cx_self* self, i_val val) {
#if !c_option(c_no_clone)
STC_INLINE _cx_self _cx_memb(_from)(i_valraw raw) {
return _cx_memb(_new)(i_valfrom(raw));
- }
-
- STC_INLINE i_valraw
- _cx_memb(_toraw)(const _cx_self* self) {
- return i_valto(self->get);
- }
+}
#endif
+// does not use i_valfrom, 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);
+ return ptr;
+}
+
STC_INLINE void
_cx_memb(_copy)(_cx_self* self, _cx_self ptr) {
if (ptr.use_count) _i_atomic_inc(ptr.use_count);
@@ -190,7 +172,8 @@ _cx_memb(_hash)(const _cx_self* self, size_t n) {
#elif c_option(c_no_cmp)
return c_hash32(&self->get, 4);
#else
- return i_hash(self->get, sizeof *self->get);
+ i_valraw rx = i_valto(self->get);
+ return i_hash(&rx, sizeof rx);
#endif
}
@@ -199,7 +182,8 @@ _cx_memb(_cmp)(const _cx_self* x, const _cx_self* y) {
#if c_option(c_no_cmp)
return c_default_cmp(&x->get, &y->get);
#else
- return i_cmp(x->get, y->get);
+ i_valraw rx = i_valto(x->get), ry = i_valto(x->get);
+ return i_cmp(&rx, &ry);
#endif
}