Commit 63849dd1
63849dd18466Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 7 months ago · 3 files · +1 added · ~2 modified
Description
fix(codegen): FloatArray slicing via a[range] and a[start, len]
Same fix as the IntArray and StrArray slice support, applied to FloatArray. sp_FloatArray_slice mirrors sp_IntArray_slice with mrb_float storage.
Refs #37.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 63849dd18466
- Parent
- 26c7367ad43a
lib/sp_runtime.hmodifiedView file
@@ -213,6 +213,9 @@
213213
static inline mrb_int sp_FloatArray_length(sp_FloatArray*a){return a->len;}214214
static inline mrb_bool sp_FloatArray_empty(sp_FloatArray*a){return a->len==0;}215215
static inline mrb_float sp_FloatArray_get(sp_FloatArray*a,mrb_int i){if(i<0)i+=a->len;return a->data[i];}216+
/* a[start, len] / a[start..end] for FloatArray. Same negative-start217+
* and length-clamping semantics as sp_IntArray_slice. */218+
static sp_FloatArray*sp_FloatArray_slice(sp_FloatArray*a,mrb_int start,mrb_int len){if(start<0)start+=a->len;if(start<0)start=0;sp_FloatArray*b=sp_FloatArray_new();if(start>=a->len||len<=0)return b;if(start+len>a->len)len=a->len-start;if(len>b->cap){sp_gc_hdr*h=(sp_gc_hdr*)((char*)b-sizeof(sp_gc_hdr));sp_gc_bytes-=sizeof(mrb_float)*b->cap;h->size-=sizeof(mrb_float)*b->cap;b->cap=len;b->data=(mrb_float*)realloc(b->data,sizeof(mrb_float)*b->cap);h->size+=sizeof(mrb_float)*b->cap;sp_gc_bytes+=sizeof(mrb_float)*b->cap;}memcpy(b->data,a->data+start,sizeof(mrb_float)*len);b->len=len;return b;}216219
static inline void sp_FloatArray_set(sp_FloatArray*a,mrb_int i,mrb_float v){if(i<0)i+=a->len;while(i>=a->cap){a->cap=a->cap*2+1;a->data=(mrb_float*)realloc(a->data,sizeof(mrb_float)*a->cap);}while(i>=a->len){a->data[a->len]=0.0;a->len++;}a->data[i]=v;}217220
218221
/* ---- PtrArray: array of void* pointers ---- */spinel_codegen.rbmodifiedView file
Loading diff…
test/bm_float_array_range.rbaddedView file
Loading diff…