HARR_FP
This commit is contained in:
parent
23737cc458
commit
586aeaea2d
@ -243,6 +243,7 @@ B result = HARR_FV(r); // sets shape to a vector
|
||||
B result = HARR_FC(r, x); // copies the shape of x, doesn't consume x
|
||||
B result = HARR_FCD(r, x); // copies the shape of x and consumes it
|
||||
usz* sh = HARR_FA(r, 4); // allocate shape for a rank 4 array. To get the result `B` object, do HARR_O(r).b later
|
||||
Arr* result = HARR_FP(r); // don't allocate/set any shape
|
||||
// If at any point you want to free the object before finishing it, do HARR_ABANDON(r)
|
||||
|
||||
// If you're sure GC cannot happen (that includes no allocating) before all items in the array are set, you can use:
|
||||
|
||||
@ -42,6 +42,7 @@ SHOULD_INLINE HArr_p m_harr_impl(usz ia) {
|
||||
#define HARR_FC(N, X) ({ assert(N##_v.c->ia == N##_len); harr_fc_impl(N##_v, X); })
|
||||
#define HARR_FCD(N, X) ({ assert(N##_v.c->ia == N##_len); harr_fcd_impl(N##_v, X); })
|
||||
#define HARR_FA(N, R) ({ assert(N##_v.c->ia == N##_len); harr_fa_impl(N##_v, R); })
|
||||
#define HARR_FP(N, R) ({ assert(N##_v.c->ia == N##_len); harr_fp_impl(N##_v, R); })
|
||||
#define HARR_ABANDON(N) harr_abandon_impl(N##_v.c)
|
||||
SHOULD_INLINE B harr_fv_impl(HArr_p p) { VTY(p.b, t_harrPartial);
|
||||
p.c->type = t_harr;
|
||||
@ -63,6 +64,11 @@ SHOULD_INLINE B harr_fcd_impl(HArr_p p, B x) { VTY(p.b, t_harrPartial);
|
||||
gsPop();
|
||||
return p.b;
|
||||
}
|
||||
SHOULD_INLINE Arr* harr_fp_impl(HArr_p p, ur r) { VTY(p.b, t_harrPartial);
|
||||
p.c->type = t_harr;
|
||||
gsPop();
|
||||
return (Arr*)p.c;
|
||||
}
|
||||
SHOULD_INLINE usz* harr_fa_impl(HArr_p p, ur r) { VTY(p.b, t_harrPartial);
|
||||
p.c->type = t_harr;
|
||||
gsPop();
|
||||
|
||||
@ -71,6 +71,7 @@ static usz* arr_shAlloc(Arr* x, ur r) { // sets rank, allocates & returns shape
|
||||
} else {
|
||||
usz* sh = x->sh = m_shArr(r)->a; // if m_shArr fails, the assumed rank≤1 guarantees the uninitialized x->sh won't break
|
||||
SPRNK(x,r);
|
||||
assert(sh!=NULL);
|
||||
return sh;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user