mirror of
https://github.com/ruby/ruby.git
synced 2026-08-03 13:08:59 +08:00
Refactor rb_obj_copy_ivar
Share more code with `rb_copy_generic_ivar`.
This commit is contained in:
parent
6c23075086
commit
24337e3cbe
Notes:
git
2026-07-14 21:50:53 +00:00
1
depend
1
depend
@ -16680,7 +16680,6 @@ shape.$(OBJEXT): $(top_srcdir)/internal/object.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/sanitizers.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/serial.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/set_table.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/st.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/string.h
|
||||
shape.$(OBJEXT): $(top_srcdir)/internal/struct.h
|
||||
|
||||
@ -49,7 +49,7 @@ VALUE rb_mod_set_temporary_name(VALUE, VALUE);
|
||||
|
||||
void rb_obj_replace_fields(VALUE obj, VALUE fields_obj);
|
||||
void rb_obj_copy_ivs_to_hash_table(VALUE obj, st_table *table);
|
||||
void rb_evict_ivars_to_hash(VALUE obj);
|
||||
VALUE rb_obj_complex_fields_build(VALUE obj);
|
||||
VALUE rb_obj_field_get(VALUE obj, shape_id_t target_shape_id);
|
||||
void rb_ivar_set_internal(VALUE obj, ID id, VALUE val);
|
||||
void rb_ivar_foreach_buffered(VALUE obj, int (*func)(ID name, VALUE val, st_data_t arg), st_data_t arg);
|
||||
|
||||
5
object.c
5
object.c
@ -342,10 +342,7 @@ rb_obj_copy_ivar(VALUE dest, VALUE obj)
|
||||
|
||||
shape_id_t dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
|
||||
if (UNLIKELY(rb_shape_complex_p(dest_shape_id))) {
|
||||
VALUE fields_obj = rb_imemo_fields_new_complex(dest, dest_shape_id, rb_ivar_count(obj), false);
|
||||
st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
|
||||
rb_obj_copy_ivs_to_hash_table(obj, table);
|
||||
rb_obj_replace_fields(dest, fields_obj);
|
||||
rb_obj_replace_fields(dest, rb_obj_complex_fields_build(obj));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
19
shape.c
19
shape.c
@ -9,7 +9,6 @@
|
||||
#include "internal/object.h"
|
||||
#include "internal/symbol.h"
|
||||
#include "internal/variable.h"
|
||||
#include "internal/st.h"
|
||||
#include "variable.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
@ -1155,24 +1154,6 @@ rb_shape_copy_fields(VALUE dest, VALUE *dest_buf, shape_id_t dest_shape_id, VALU
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_shape_copy_complex_ivars(VALUE dest, VALUE src)
|
||||
{
|
||||
RUBY_ASSERT(IMEMO_TYPE_P(src, imemo_fields));
|
||||
RUBY_ASSERT(IMEMO_TYPE_P(dest, imemo_fields));
|
||||
|
||||
shape_id_t dest_shape_id = RBASIC_SHAPE_ID(src);
|
||||
st_table *dest_table = rb_imemo_fields_complex_tbl(dest);
|
||||
st_replace(dest_table, rb_imemo_fields_complex_tbl(src));
|
||||
|
||||
if (rb_shape_has_object_id(dest_shape_id)) {
|
||||
st_data_t stkey = (st_data_t)id_object_id;
|
||||
st_delete(dest_table, &stkey, NULL);
|
||||
}
|
||||
|
||||
RBASIC_SET_SHAPE_ID(dest, ROOT_COMPLEX_SHAPE_ID);
|
||||
}
|
||||
|
||||
size_t
|
||||
rb_shape_edges_count(shape_id_t shape_id)
|
||||
{
|
||||
|
||||
1
shape.h
1
shape.h
@ -267,7 +267,6 @@ shape_id_t rb_shape_transition_add_ivar_no_warnings(shape_id_t shape_id, ID id,
|
||||
shape_id_t rb_shape_object_id(shape_id_t original_shape_id);
|
||||
shape_id_t rb_shape_rebuild(shape_id_t initial_shape_id, shape_id_t dest_shape_id);
|
||||
void rb_shape_copy_fields(VALUE dest, VALUE *dest_buf, shape_id_t dest_shape_id, VALUE *src_buf, shape_id_t src_shape_id);
|
||||
void rb_shape_copy_complex_ivars(VALUE dest, VALUE src);
|
||||
|
||||
static inline bool
|
||||
rb_shape_frozen_p(shape_id_t shape_id)
|
||||
|
||||
20
variable.c
20
variable.c
@ -1623,20 +1623,13 @@ rb_evict_fields_to_hash(VALUE obj)
|
||||
return new_shape_id;
|
||||
}
|
||||
|
||||
void
|
||||
rb_evict_ivars_to_hash(VALUE obj)
|
||||
VALUE
|
||||
rb_obj_complex_fields_build(VALUE obj)
|
||||
{
|
||||
RUBY_ASSERT(RB_TYPE_P(obj, T_OBJECT));
|
||||
RUBY_ASSERT(!rb_obj_shape_complex_p(obj));
|
||||
|
||||
shape_id_t new_shape_id = rb_obj_shape_transition_complex(obj);
|
||||
VALUE fields_obj = rb_imemo_fields_new_complex(obj, new_shape_id, rb_ivar_count(obj), false);
|
||||
VALUE fields_obj = rb_imemo_fields_new_complex(obj, ROOT_COMPLEX_SHAPE_ID, rb_ivar_count(obj), false);
|
||||
st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
|
||||
rb_obj_copy_ivs_to_hash_table(obj, table);
|
||||
ROBJECT_SET_EXTENDED(obj, fields_obj);
|
||||
RBASIC_SET_FULL_SHAPE_ID(obj, rb_shape_transition_extended(new_shape_id));
|
||||
|
||||
RUBY_ASSERT(rb_obj_shape_complex_p(obj));
|
||||
return fields_obj;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@ -2290,10 +2283,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
|
||||
shape_id_t dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
|
||||
|
||||
if (UNLIKELY(rb_shape_complex_p(dest_shape_id))) {
|
||||
new_fields_obj = rb_imemo_fields_new_complex(dest, dest_shape_id, rb_ivar_count(obj), false);
|
||||
st_table *table = rb_imemo_fields_complex_tbl(new_fields_obj);
|
||||
rb_obj_copy_ivs_to_hash_table(obj, table);
|
||||
rb_obj_replace_fields(dest, new_fields_obj);
|
||||
rb_obj_replace_fields(dest, rb_obj_complex_fields_build(obj));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user