reorder take_c2
This commit is contained in:
parent
e2b45e33e1
commit
8fad76762a
@ -432,8 +432,10 @@ B drop_c1(B t, B x) { return affixes(x, 1); }
|
|||||||
|
|
||||||
extern B rt_take, rt_drop;
|
extern B rt_take, rt_drop;
|
||||||
B take_c2(B t, B w, B x) {
|
B take_c2(B t, B w, B x) {
|
||||||
if (isNum(w)) {
|
|
||||||
if (!isArr(x)) x = m_atomUnit(x);
|
if (!isArr(x)) x = m_atomUnit(x);
|
||||||
|
|
||||||
|
if (!isNum(w)) return c2(rt_take, w, x);
|
||||||
|
|
||||||
i64 wv = o2i64(w);
|
i64 wv = o2i64(w);
|
||||||
ur xr = RNK(x);
|
ur xr = RNK(x);
|
||||||
usz csz = 1;
|
usz csz = 1;
|
||||||
@ -443,23 +445,25 @@ B take_c2(B t, B w, B x) {
|
|||||||
xsh = SH(x);
|
xsh = SH(x);
|
||||||
ptr_inc(shObjS(xsh)); // we'll look at it at the end and dec there
|
ptr_inc(shObjS(xsh)); // we'll look at it at the end and dec there
|
||||||
}
|
}
|
||||||
i64 t = wv*csz; // TODO error on overflow somehow
|
i64 n = wv; // TODO error on overflow somehow
|
||||||
|
if (mulOn(n, csz)) thrOOM();
|
||||||
|
|
||||||
Arr* a;
|
Arr* a;
|
||||||
if (t>=0) {
|
if (n>=0) {
|
||||||
a = take_impl(t, x);
|
a = take_impl(n, x);
|
||||||
} else {
|
} else {
|
||||||
t = -t;
|
n = -n;
|
||||||
usz xia = IA(x);
|
usz xia = IA(x);
|
||||||
if (t>xia) {
|
if (n>xia) {
|
||||||
B xf = getFillE(x);
|
B xf = getFillE(x);
|
||||||
MAKE_MUT(r, t); mut_init(r, el_or(TI(x,elType), selfElType(xf)));
|
MAKE_MUT(r, n); mut_init(r, el_or(TI(x,elType), selfElType(xf)));
|
||||||
MUTG_INIT(r);
|
MUTG_INIT(r);
|
||||||
mut_fillG(r, 0, xf, t-xia);
|
mut_fillG(r, 0, xf, n-xia);
|
||||||
mut_copyG(r, t-xia, x, 0, xia);
|
mut_copyG(r, n-xia, x, 0, xia);
|
||||||
decG(x); dec(xf);
|
decG(x); dec(xf);
|
||||||
a = mut_fp(r);
|
a = mut_fp(r);
|
||||||
} else {
|
} else {
|
||||||
a = TI(x,slice)(x,xia-t,t);
|
a = TI(x,slice)(x,xia-n,n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xr<=1) {
|
if (xr<=1) {
|
||||||
@ -471,8 +475,6 @@ B take_c2(B t, B w, B x) {
|
|||||||
ptr_dec(shObjS(xsh));
|
ptr_dec(shObjS(xsh));
|
||||||
}
|
}
|
||||||
return taga(a);
|
return taga(a);
|
||||||
}
|
|
||||||
return c2(rt_take, w, x);
|
|
||||||
}
|
}
|
||||||
B drop_c2(B t, B w, B x) {
|
B drop_c2(B t, B w, B x) {
|
||||||
if (isNum(w) && isArr(x) && RNK(x)==1) {
|
if (isNum(w) && isArr(x) && RNK(x)==1) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user