mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-set: remove unused object allocation
AI added this allocation to avoid memory leaks, but actually this extra allocation does nothing useful. We see more room for AI improvement.
This commit is contained in:
@@ -71,23 +71,13 @@ set_init(mrb_state *mrb, mrb_value self)
|
||||
return self;
|
||||
}
|
||||
|
||||
/*
|
||||
* To avoid memory leaks if an exception is raised during merge or __init_with_block,
|
||||
* we'll use a temporary set to validate the operation first.
|
||||
* This ensures that if an exception occurs, it happens on the temporary set,
|
||||
* and our main set's khash will be properly freed when the object is GC'd.
|
||||
*/
|
||||
mrb_value temp_set = mrb_obj_new(mrb, mrb_obj_class(mrb, self), 0, NULL);
|
||||
|
||||
if (!mrb_nil_p(block)) {
|
||||
/* Block given - validate with the temporary set first */
|
||||
mrb_value args[1] = { enum_obj };
|
||||
mrb_funcall_with_block(mrb, temp_set, MRB_SYM(__init_with_block), 1, args, block);
|
||||
/* If we get here, no exception was raised, so we can safely proceed with our main set */
|
||||
mrb_funcall_with_block(mrb, self, MRB_SYM(__init_with_block), 1, args, block);
|
||||
} else {
|
||||
/* No block - validate merge with the temporary set first */
|
||||
mrb_funcall_id(mrb, temp_set, MRB_SYM(merge), 1, enum_obj);
|
||||
}
|
||||
else {
|
||||
/* If we get here, no exception was raised, so we can safely proceed with our main set */
|
||||
mrb_funcall_id(mrb, self, MRB_SYM(merge), 1, enum_obj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user