diff options
| author | Tyge Løvset <[email protected]> | 2021-09-08 08:37:17 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-09-08 08:37:17 +0200 |
| commit | f16e08017abfc44864b37a42c42951f0fd885f5f (patch) | |
| tree | 40c7aac6edac21d361d7b98abad48bdd63c1c199 /include | |
| parent | 318c2700120ed089b73c8c1fc00cace7ec388c5f (diff) | |
| download | STC-modified-f16e08017abfc44864b37a42c42951f0fd885f5f.tar.gz STC-modified-f16e08017abfc44864b37a42c42951f0fd885f5f.zip | |
Made clone more robust in cstack, cpque
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/cpque.h | 5 | ||||
| -rw-r--r-- | include/stc/cstack.h | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/include/stc/cpque.h b/include/stc/cpque.h index 8fed94da..3f3bc515 100644 --- a/include/stc/cpque.h +++ b/include/stc/cpque.h @@ -110,12 +110,13 @@ cx_memb(_make_heap)(Self* self) { cx_memb(_sift_down_)(arr, k, n);
}
-STC_DEF Self cx_memb(_clone)(Self q) {
+STC_INLINE Self cx_memb(_clone)(Self q) {
Self out = {(cx_value_t *) c_malloc(q.size*sizeof(cx_value_t)), q.size, q.size};
- for (cx_value_t *a = out.data, *b = a + q.size; a != b; ++a) *a = i_valfrom(i_valto(q.data++));
+ for (size_t i = 0; i < q.size; ++i, ++q.data) out.data[i] = i_valfrom(i_valto(q.data));
return out;
}
+
STC_DEF void
cx_memb(_erase_at)(Self* self, size_t idx) {
size_t n = cx_memb(_size)(*self) - 1;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h index cec90776..f68a01d7 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -73,7 +73,7 @@ STC_INLINE void cx_memb(_emplace)(Self* self, cx_rawvalue_t raw) STC_INLINE Self cx_memb(_clone)(Self v) {
Self out = {(cx_value_t *) c_malloc(v.size*sizeof(cx_value_t)), v.size, v.size};
- for (cx_value_t *a = out.data, *b = a + v.size; a != b; ++a) *a = i_valfrom(i_valto(v.data++));
+ for (size_t i = 0; i < v.size; ++i, ++v.data) out.data[i] = i_valfrom(i_valto(v.data));
return out;
}
|
