diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-08-04 17:31:33 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-08-04 17:31:33 -0400 |
| commit | 73000498674ea2a72204c0e137c45bdfa7afd524 (patch) | |
| tree | eff10c278e5ee932e0d2a7f410a144f875ffdea3 | |
| parent | 7fd74553f8df574740ab930491baade7223fe5c2 (diff) | |
Switch to TABLE_INCREF
| -rw-r--r-- | builtins/table.c | 6 | ||||
| -rw-r--r-- | builtins/table.h | 1 | ||||
| -rw-r--r-- | compile.c | 2 |
3 files changed, 2 insertions, 7 deletions
diff --git a/builtins/table.c b/builtins/table.c index e0c94593..f3f97ec3 100644 --- a/builtins/table.c +++ b/builtins/table.c @@ -107,12 +107,6 @@ static void maybe_copy_on_write(table_t *t, const TypeInfo *type) } } -public void Table$mark_copy_on_write(table_t *t) -{ - ARRAY_INCREF(t->entries); - if (t->bucket_info) t->bucket_info->data_refcount = TABLE_MAX_DATA_REFCOUNT; -} - // Return address of value or NULL public void *Table$get_raw(table_t t, const void *key, const TypeInfo *type) { diff --git a/builtins/table.h b/builtins/table.h index 82e12286..e136f460 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -41,6 +41,7 @@ void Table$remove(table_t *t, const void *key, const TypeInfo *type); void Table$clear(table_t *t); table_t Table$sorted(table_t t, const TypeInfo *type); void Table$mark_copy_on_write(table_t *t); +#define TABLE_INCREF(t) ({ ARRAY_INCREF((t).entries); if ((t).bucket_info) (t).bucket_info.data_refcount += ((t).bucket_info.data_refcount < TABLE_MAX_DATA_REFCOUNT); }) int32_t Table$compare(const table_t *x, const table_t *y, const TypeInfo *type); bool Table$equal(const table_t *x, const table_t *y, const TypeInfo *type); uint32_t Table$hash(const table_t *t, const TypeInfo *type); @@ -2172,7 +2172,7 @@ CORD compile(env_t *env, ast_t *ast) if (ptr->pointed->tag == ArrayType) { return CORD_all("({ array_t *arr = ", compile(env, indexing->indexed), "; ARRAY_INCREF(*arr); *arr; })"); } else if (ptr->pointed->tag == TableType) { - return CORD_all("({ table_t *t = ", compile(env, indexing->indexed), "; Table$mark_copy_on_write(t); *t; })"); + return CORD_all("({ table_t *t = ", compile(env, indexing->indexed), "; TABLE_INCREF(*t); *t; })"); } else { return CORD_all("*(", compile(env, indexing->indexed), ")"); } |
