old implementation use only a global static array for storing ScopeTracker which have the advantage to be fast, but you can't use cleanup in a function that have move than SCOPE_TCK_STORE_SIZE scopes. I don't want to use only dynarray_* as it would slow down tcc for every functions, so I keep both stores.
Unified · Split
| @@ -40,10 +40,13 @@ ST_DATA Sym *global_label_stack; · 39 unmodified lines | |||
| 40 | ST_DATA Sym *local_label_stack; | 40 | ST_DATA Sym *local_label_stack; |
| 41 | 41 | ||
| 42 | static int local_scope; | 42 | static int local_scope; |
| 43 | #define SCOPE_TCK_STORE_SIZE 1024 | 43 | #define SCOPE_TCK_STORE_SIZE 512 |
| 44 | ST_DATA ScopeTacker *scope_tracker; | 44 | ST_DATA ScopeTacker *scope_tracker; |
| 45 | static ScopeTacker scope_tck_store[SCOPE_TCK_STORE_SIZE]; | 45 | static ScopeTacker scope_tck_store[SCOPE_TCK_STORE_SIZE]; |
| 46 | static int scope_tck_idx; | 46 | static int scope_tck_store_len; |
| 47 | |||
| 48 | static ScopeTacker **scope_tck_2nd_store; | ||
| 49 | static int scope_tck_2nd_store_len; | ||
| 47 | 50 | ||
| 48 | static int in_sizeof; | 51 | static int in_sizeof; |
| 49 | static int section_sym; | 52 | static int section_sym; |
| @@ -141,15 +144,15 @@ static void incr_local_scope(void) · 91 unmodified lines | |||
| 141 | ScopeTacker *tmp = scope_tracker; | 144 | ScopeTacker *tmp = scope_tracker; |
| 142 | 145 | ||
| 143 | ++local_scope; | 146 | ++local_scope; |
| 144 | /* if we have more scopes that SCOPE_TCK_STORE_SIZE */ | 147 | if (scope_tck_store_len >= SCOPE_TCK_STORE_SIZE) { |
| 145 | /* cleanup will not work at all, but it should be a very rare case */ | 148 | scope_tracker = tcc_malloc(sizeof(ScopeTacker)); |
| 146 | /* and I don't want to add too much complexiy for handeling case */ | 149 | dynarray_add(&scope_tck_2nd_store, |
| 147 | /* that should not happen */ | 150 | &scope_tck_2nd_store_len, scope_tracker); |
| 148 | if (scope_tck_idx < SCOPE_TCK_STORE_SIZE) { | 151 | } else { |
| 149 | scope_tracker = &scope_tck_store[scope_tck_idx]; | 152 | scope_tracker = &scope_tck_store[scope_tck_store_len]; |
| 150 | scope_tracker->prev = tmp; | 153 | ++scope_tck_store_len; |
| 151 | ++scope_tck_idx; | ||
| 152 | } | 154 | } |
| 155 | scope_tracker->prev = tmp; | ||
| 153 | } | 156 | } |
| 154 | 157 | ||
| 155 | static void decr_local_scope(void) | 158 | static void decr_local_scope(void) |
| @@ -175,7 +178,9 @@ static void reset_local_scope(void) · 19 unmodified lines | |||
| 175 | } | 178 | } |
| 176 | scope_tracker = NULL; | 179 | scope_tracker = NULL; |
| 177 | local_scope = 0; | 180 | local_scope = 0; |
| 178 | scope_tck_idx = 0; | 181 | scope_tck_store_len = 0; |
| 182 | if (scope_tck_2nd_store_len) | ||
| 183 | dynarray_reset(&scope_tck_2nd_store, &scope_tck_2nd_store_len); | ||
| 179 | } | 184 | } |
| 180 | 185 | ||
| 181 | int is_scope_a_parent_of(ScopeTacker *parent, ScopeTacker *child) | 186 | int is_scope_a_parent_of(ScopeTacker *parent, ScopeTacker *child) |