diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-26 14:02:48 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-26 14:02:48 -0400 |
| commit | 135e23094c42b33acdd05dd522bbe0fd691b9eee (patch) | |
| tree | 68a675393083286a79d3f66e6f57aa4ac1ebd212 /builtins | |
| parent | 59b62035c1304b4c6c39b6d546b9c5187e8d0738 (diff) | |
Improve codegen for table/array iteration by inlining the iteration
macros
Diffstat (limited to 'builtins')
| -rw-r--r-- | builtins/array.h | 7 | ||||
| -rw-r--r-- | builtins/table.h | 13 |
2 files changed, 0 insertions, 20 deletions
diff --git a/builtins/array.h b/builtins/array.h index df66e636..b538be30 100644 --- a/builtins/array.h +++ b/builtins/array.h @@ -51,13 +51,6 @@ .data_refcount=1}; }) #define $ARRAY_INCREF(arr) (arr).data_refcount |= ((arr).data_refcount << 1) | 1 #define $ARRAY_DECREF(arr) (arr).data_refcount &= 2 -#define $ARRAY_FOREACH(arr_expr, i, item_type, x, body, else_body) {\ - array_t $arr = arr_expr; \ - $ARRAY_INCREF($arr); \ - if ($arr.length == 0) else_body \ - else for (int64_t i = 1; i <= $arr.length; i++) { item_type x = *(item_type*)($arr.data + (i-1)*$arr.stride); body } \ - $ARRAY_DECREF($arr); \ - } #define Array__insert_value(arr, item_expr, index, type) ({ __typeof(item_expr) $item = item_expr; Array__insert(arr, &$item, index, type); }) void Array__insert(array_t *arr, const void *item, int64_t index, const TypeInfo *type); diff --git a/builtins/table.h b/builtins/table.h index ab0004ec..38c66427 100644 --- a/builtins/table.h +++ b/builtins/table.h @@ -26,19 +26,6 @@ if (__builtin_expect($v == NULL, 0)) \ fail_source(filename, start, end, "The key %r is not in this table\n", generic_as_text(&$k, USE_COLOR, $info->TableInfo.key)); \ *$v; }) -#define $TABLE_FOREACH(table_expr, key_type, k, value_type, v, value_offset, body, else_body) {\ - array_t $entries = (table_expr).entries; \ - if ($entries.length == 0) else_body \ - else { \ - $ARRAY_INCREF($entries); \ - for (int64_t $i = 0; $i < $entries.length; $i++) { \ - key_type k = *(key_type*)($entries.data + $i*$entries.stride); \ - value_type v = *(value_type*)($entries.data + $i*$entries.stride + value_offset); \ - body \ - } \ - $ARRAY_DECREF($entries); \ - } \ - } table_t Table_from_entries(array_t entries, const TypeInfo *type); void *Table_get(table_t t, const void *key, const TypeInfo *type); |
