Xavier Noria
2005-11-01 18:57:36 UTC
I founded nothing about slices in perlguts, perlxs*, or perlapi
(where are they documented?), so I wrote this little utility to take
a slice from AV* data using the indices in AV* indices (integers),
and put the result in AV* out (indices and out are guaranteed to have
the same length):
void __slice(AV* indices, AV* data, AV* out) {
int i;
I32 last_index;
I32 index;
SV* val;
last_index = av_len(indices);
for (i = 0; i <= last_index; ++i) {
index = SvIVX(*av_fetch(indices, i, 0));
val = *av_fetch(data, index, 0);
av_store(out, i, newSVsv(val));
}
}
I am just starting to play around with the C API. Is this code right
as far as XS is concerned? Is there a better idiom?
-- fxn
(where are they documented?), so I wrote this little utility to take
a slice from AV* data using the indices in AV* indices (integers),
and put the result in AV* out (indices and out are guaranteed to have
the same length):
void __slice(AV* indices, AV* data, AV* out) {
int i;
I32 last_index;
I32 index;
SV* val;
last_index = av_len(indices);
for (i = 0; i <= last_index; ++i) {
index = SvIVX(*av_fetch(indices, i, 0));
val = *av_fetch(data, index, 0);
av_store(out, i, newSVsv(val));
}
}
I am just starting to play around with the C API. Is this code right
as far as XS is concerned? Is there a better idiom?
-- fxn