From 70bc8cc6c219667dcae85bbf78bc0bc00e05c76e Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 12 Oct 2022 18:27:23 +0900 Subject: Adjust indents [ci skip] --- shape.c | 126 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 51 deletions(-) (limited to 'shape.c') diff --git a/shape.c b/shape.c index 0f48fa1a86..80d135b897 100644 --- a/shape.c +++ b/shape.c @@ -10,7 +10,8 @@ * Shape getters */ static rb_shape_t* -rb_shape_get_root_shape(void) { +rb_shape_get_root_shape(void) +{ return GET_VM()->root_shape; } @@ -21,12 +22,14 @@ rb_shape_id(rb_shape_t * shape) } static rb_shape_t* -rb_shape_get_frozen_root_shape(void) { +rb_shape_get_frozen_root_shape(void) +{ return GET_VM()->frozen_root_shape; } bool -rb_shape_root_shape_p(rb_shape_t* shape) { +rb_shape_root_shape_p(rb_shape_t* shape) +{ return shape == rb_shape_get_root_shape(); } @@ -90,7 +93,8 @@ rb_shape_get_shape(VALUE obj) } static rb_shape_t * -rb_shape_lookup_id(rb_shape_t* shape, ID id, enum shape_type shape_type) { +rb_shape_lookup_id(rb_shape_t* shape, ID id, enum shape_type shape_type) +{ while (shape->parent_id != INVALID_SHAPE_ID) { if (shape->edge_name == id) { // If the shape type is different, we don't @@ -136,25 +140,25 @@ get_next_shape_internal(rb_shape_t* shape, ID id, VALUE obj, enum shape_type sha new_shape->type = (uint8_t)shape_type; - switch(shape_type) { - case SHAPE_IVAR: - new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count + 1; + switch (shape_type) { + case SHAPE_IVAR: + new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count + 1; - // Check if we should update max_iv_count on the object's class - if (BUILTIN_TYPE(obj) == T_OBJECT) { - VALUE klass = rb_obj_class(obj); - if (new_shape->iv_count > RCLASS_EXT(klass)->max_iv_count) { - RCLASS_EXT(klass)->max_iv_count = new_shape->iv_count; - } + // Check if we should update max_iv_count on the object's class + if (BUILTIN_TYPE(obj) == T_OBJECT) { + VALUE klass = rb_obj_class(obj); + if (new_shape->iv_count > RCLASS_EXT(klass)->max_iv_count) { + RCLASS_EXT(klass)->max_iv_count = new_shape->iv_count; } - break; - case SHAPE_IVAR_UNDEF: - case SHAPE_FROZEN: - new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count; - break; - case SHAPE_ROOT: - rb_bug("Unreachable"); - break; + } + break; + case SHAPE_IVAR_UNDEF: + case SHAPE_FROZEN: + new_shape->iv_count = rb_shape_get_shape_by_id(new_shape->parent_id)->iv_count; + break; + case SHAPE_ROOT: + rb_bug("Unreachable"); + break; } rb_id_table_insert(shape->edges, id, (VALUE)new_shape); @@ -199,13 +203,13 @@ rb_shape_transition_shape_frozen(VALUE obj) rb_shape_t* next_shape; if (shape == rb_shape_get_root_shape()) { - switch(BUILTIN_TYPE(obj)) { - case T_OBJECT: - case T_CLASS: - case T_MODULE: - break; - default: - return; + switch (BUILTIN_TYPE(obj)) { + case T_OBJECT: + case T_CLASS: + case T_MODULE: + break; + default: + return; } next_shape = rb_shape_get_frozen_root_shape(); } @@ -239,22 +243,23 @@ rb_shape_get_next(rb_shape_t* shape, VALUE obj, ID id) } bool -rb_shape_get_iv_index(rb_shape_t * shape, ID id, attr_index_t *value) { +rb_shape_get_iv_index(rb_shape_t * shape, ID id, attr_index_t *value) +{ while (shape->parent_id != INVALID_SHAPE_ID) { if (shape->edge_name == id) { enum shape_type shape_type; shape_type = (enum shape_type)shape->type; - switch(shape_type) { - case SHAPE_IVAR: - RUBY_ASSERT(shape->iv_count > 0); - *value = shape->iv_count - 1; - return true; - case SHAPE_IVAR_UNDEF: - case SHAPE_ROOT: - return false; - case SHAPE_FROZEN: - rb_bug("Ivar should not exist on frozen transition\n"); + switch (shape_type) { + case SHAPE_IVAR: + RUBY_ASSERT(shape->iv_count > 0); + *value = shape->iv_count - 1; + return true; + case SHAPE_IVAR_UNDEF: + case SHAPE_ROOT: + return false; + case SHAPE_FROZEN: + rb_bug("Ivar should not exist on frozen transition\n"); } } shape = rb_shape_get_shape_by_id(shape->parent_id); @@ -313,14 +318,16 @@ static const rb_data_type_t shape_data_type = { }; static VALUE -rb_wrapped_shape_id(VALUE self) { +rb_wrapped_shape_id(VALUE self) +{ rb_shape_t * shape; TypedData_Get_Struct(self, rb_shape_t, &shape_data_type, shape); return INT2NUM(rb_shape_id(shape)); } static VALUE -rb_shape_type(VALUE self) { +rb_shape_type(VALUE self) +{ rb_shape_t * shape; TypedData_Get_Struct(self, rb_shape_t, &shape_data_type, shape); return INT2NUM(shape->type); @@ -339,16 +346,20 @@ rb_shape_parent_id(VALUE self) } } -static VALUE parse_key(ID key) { +static VALUE +parse_key(ID key) +{ if ((key & RUBY_ID_INTERNAL) == RUBY_ID_INTERNAL) { return LONG2NUM(key); - } else { + } + else { return ID2SYM(key); } } static VALUE -rb_shape_t_to_rb_cShape(rb_shape_t *shape) { +rb_shape_t_to_rb_cShape(rb_shape_t *shape) +{ union { const rb_shape_t *in; void *out; } deconst; VALUE res; deconst.in = shape; @@ -357,7 +368,8 @@ rb_shape_t_to_rb_cShape(rb_shape_t *shape) { return res; } -static enum rb_id_table_iterator_result rb_edges_to_hash(ID key, VALUE value, void *ref) +static enum rb_id_table_iterator_result +rb_edges_to_hash(ID key, VALUE value, void *ref) { rb_hash_aset(*(VALUE *)ref, parse_key(key), rb_shape_t_to_rb_cShape((rb_shape_t*)value)); return ID_TABLE_CONTINUE; @@ -428,15 +440,21 @@ rb_shape_parent(VALUE self) } } -VALUE rb_shape_debug_shape(VALUE self, VALUE obj) { +VALUE +rb_shape_debug_shape(VALUE self, VALUE obj) +{ return rb_shape_t_to_rb_cShape(rb_shape_get_shape(obj)); } -VALUE rb_shape_root_shape(VALUE self) { +VALUE +rb_shape_root_shape(VALUE self) +{ return rb_shape_t_to_rb_cShape(rb_shape_get_root_shape()); } -VALUE rb_shape_frozen_root_shape(VALUE self) { +VALUE +rb_shape_frozen_root_shape(VALUE self) +{ return rb_shape_t_to_rb_cShape(rb_shape_get_frozen_root_shape()); } @@ -456,7 +474,9 @@ static VALUE edges(struct rb_id_table* edges) return hash; } -VALUE rb_obj_shape(rb_shape_t* shape) { +VALUE +rb_obj_shape(rb_shape_t* shape) +{ VALUE rb_shape = rb_hash_new(); rb_hash_aset(rb_shape, ID2SYM(rb_intern("id")), INT2NUM(rb_shape_id(shape))); @@ -473,11 +493,15 @@ VALUE rb_obj_shape(rb_shape_t* shape) { return rb_shape; } -static VALUE shape_transition_tree(VALUE self) { +static VALUE +shape_transition_tree(VALUE self) +{ return rb_obj_shape(rb_shape_get_root_shape()); } -static VALUE next_shape_id(VALUE self) { +static VALUE +next_shape_id(VALUE self) +{ return INT2NUM(GET_VM()->next_shape_id); } -- cgit v1.2.1