Commit 5ba02252
5ba02252d2e5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 7 files · +5 added · ~2 modified
Description
Merge pull request #94 from mame/fix/ptr-array-followups
fix(codegen): ptr_array follow-ups — shuffle, +, concat, each_with_object, flat_map
Details
- Commit
- 5ba02252d2e5
- Parent
- ad9c4fd529b4
- Merge parent
- 7d38b433b776
lib/sp_runtime.hmodifiedView file
@@ -251,6 +251,9 @@
251251
static inline mrb_int sp_PtrArray_length(sp_PtrArray*a){return a->len;}252252
static inline mrb_bool sp_PtrArray_empty(sp_PtrArray*a){return a->len==0;}253253
static void sp_PtrArray_reverse_bang(sp_PtrArray*a){for(mrb_int i=0,j=a->len-1;i<j;i++,j--){void*t=a->data[i];a->data[i]=a->data[j];a->data[j]=t;}}254+
static sp_PtrArray*sp_PtrArray_dup(sp_PtrArray*a){sp_PtrArray*b=sp_PtrArray_new_scan(a->scan_elem);for(mrb_int i=0;i<a->len;i++)sp_PtrArray_push(b,a->data[i]);return b;}255+
static void sp_PtrArray_shuffle_bang(sp_PtrArray*a){for(mrb_int i=a->len-1;i>0;i--){mrb_int j=(mrb_int)(rand()%(i+1));void*t=a->data[i];a->data[i]=a->data[j];a->data[j]=t;}}256+
static sp_PtrArray*sp_PtrArray_shuffle(sp_PtrArray*a){sp_PtrArray*b=sp_PtrArray_dup(a);sp_PtrArray_shuffle_bang(b);return b;}254257
255258
/* Small-array optimization: keep the first SP_STRARR_INLINE elements256259
* inside the struct so empty/short StrArrays skip the data malloc.spinel_codegen.rbmodifiedView file
Loading diff…
test/array_concat_ptr.rbaddedView file
Loading diff…
test/array_each_with_object_ptr.rbaddedView file
Loading diff…
test/array_flat_map_ptr.rbaddedView file
Loading diff…
test/array_plus_ptr.rbaddedView file
Loading diff…
test/array_shuffle_ptr.rbaddedView file
Loading diff…