Commit 86fc7098

86fc7098f329Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Add hash delete_if/select!/reject!/filter!/keep_if iteration support

  • Add sp_StrPolyHash_delete to sp_runtime.h (mirrors StrStrHash pattern)
  • Add hash.delete_if/select!/reject!/filter!/keep_if { |k,v| } emission to emit_inline_call_x: iterates via order array, temporarily pins block param types to hash key/value types for correct codegen, refreshes the ntype cache before emission, deletes matching entries in-place.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
86fc7098f329
Parent
d2fb361c09eb

lib/sp_runtime.hmodifiedView file

@@ -3734,6 +3734,7 @@
37343734 static sp_StrArray*sp_StrPolyHash_keys(sp_StrPolyHash*h){sp_StrArray*a=sp_StrArray_new();if(!h)return a;for(mrb_int i=0;i<h->len;i++)sp_StrArray_push(a,h->order[i]);return a;}
37353735 static sp_PolyArray*sp_StrPolyHash_values(sp_StrPolyHash*h){sp_PolyArray*a=sp_PolyArray_new();for(mrb_int i=0;i<h->len;i++)sp_PolyArray_push(a,sp_StrPolyHash_get(h,h->order[i]));return a;}
37363736 static mrb_bool sp_StrPolyHash_has_value(sp_StrPolyHash*h,sp_RbVal v){if(!h)return FALSE;for(mrb_int i=0;i<h->len;i++)if(sp_poly_eq(sp_StrPolyHash_get(h,h->order[i]),v))return TRUE;return FALSE;}
3737+static void sp_StrPolyHash_delete(sp_StrPolyHash*h,const char*k){mrb_int idx=(mrb_int)(sp_str_hash(k)&h->mask);while(h->keys[idx]){if(strcmp(h->keys[idx],k)==0){h->keys[idx]=NULL;h->vals[idx]=sp_box_nil();h->len--;mrb_int j=(idx+1)&h->mask;while(h->keys[j]){mrb_int nj=(mrb_int)(sp_str_hash(h->keys[j])&h->mask);if((j>idx&&(nj<=idx||nj>j))||(j<idx&&nj<=idx&&nj>j)){h->keys[idx]=h->keys[j];h->vals[idx]=h->vals[j];h->keys[j]=NULL;h->vals[j]=sp_box_nil();idx=j;}j=(j+1)&h->mask;}{mrb_int oi=0;while(oi<=h->len){if(strcmp(h->order[oi],k)==0){while(oi<h->len){h->order[oi]=h->order[oi+1];oi++;}break;}oi++;}}return;}idx=(idx+1)&h->mask;}}
37373738 /* Hash#merge for str_poly_hash. Same shape as the
37383739 StrIntHash / SymPolyHash siblings -- copy recv's entries into a
37393740 fresh hash, then overlay other's. */