Skip to content

Commit

Permalink
table: reduce code repetition with pointer
Browse files Browse the repository at this point in the history
Create a pointer to the actual heap value structure
so its fields can be accessed directly.
The compiler will most likely eliminate it anyway.
  • Loading branch information
matheusmoreira committed Dec 15, 2023
1 parent 2d5bcbc commit 3010c1d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/lone/value/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ struct lone_value lone_table_create(struct lone_lisp *lone, size_t capacity, str

static double lone_table_load_factor(struct lone_value table, unsigned char added)
{
double count = (double) (table.as.heap_value->as.table.count + added);
double capacity = (double) table.as.heap_value->as.table.capacity;
struct lone_table *actual = &table.as.heap_value->as.table;

double count = (double) (actual->count + added);
double capacity = (double) actual->capacity;

return count / capacity;
}
Expand Down

0 comments on commit 3010c1d

Please sign in to comment.