Skip to content

Commit

Permalink
shape.h: Make attr_index_t uint8_t
Browse files Browse the repository at this point in the history
Given `SHAPE_MAX_NUM_IVS 80`, we transition to TOO_COMPLEX
way before we could overflow a 8bit counter.

This reduce the size of `rb_shape_t` from 32B to 24B.

If we decide to raise `SHAPE_MAX_NUM_IVS` we can always increase
that type again.
  • Loading branch information
byroot committed Oct 10, 2023
1 parent 5cc44f4 commit e10d52b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
1 change: 1 addition & 0 deletions shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ Init_default_shapes(void)
hash_fallback_shape->size_pool_index = 0;
RUBY_ASSERT(OBJ_TOO_COMPLEX_SHAPE_ID == (GET_SHAPE_TREE()->next_shape_id - 1));
RUBY_ASSERT(rb_shape_id(hash_fallback_shape) == OBJ_TOO_COMPLEX_SHAPE_ID);
fprintf(stderr, "sizeof(rb_shape_t) => %lu\n", sizeof(rb_shape_t));
}

void
Expand Down
5 changes: 2 additions & 3 deletions shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
#if (SIZEOF_UINT64_T <= SIZEOF_VALUE)
#define SIZEOF_SHAPE_T 4
#define SHAPE_IN_BASIC_FLAGS 1
typedef uint32_t attr_index_t;
#else
#define SIZEOF_SHAPE_T 2
#define SHAPE_IN_BASIC_FLAGS 0
typedef uint16_t attr_index_t;
#endif
typedef uint8_t attr_index_t;

#define MAX_IVARS (attr_index_t)(-1)

Expand Down Expand Up @@ -44,7 +43,7 @@ struct rb_shape {
struct rb_id_table * edges; // id_table from ID (ivar) to next shape
ID edge_name; // ID (ivar) for transition from parent to rb_shape
attr_index_t next_iv_index;
uint32_t capacity; // Total capacity of the object with this shape
attr_index_t capacity; // Total capacity of the object with this shape
uint8_t type;
uint8_t size_pool_index;
shape_id_t parent_id;
Expand Down

0 comments on commit e10d52b

Please sign in to comment.