@@ -51,6 +51,9 @@ type_t *TY_int;
51
51
52
52
arena_t * INSN_ARENA ;
53
53
54
+ /* HASHMAP_ARENA is responsible for hashmap_node_t allocation */
55
+ arena_t * HASHMAP_ARENA ;
56
+
54
57
/* BLOCK_ARENA is responsible for block_t / var_t allocation */
55
58
arena_t * BLOCK_ARENA ;
56
59
@@ -378,15 +381,15 @@ hashmap_node_t *hashmap_node_new(char *key, void *val)
378
381
return NULL ;
379
382
380
383
int len = strlen (key );
381
- hashmap_node_t * node = malloc ( sizeof (hashmap_node_t ));
384
+ hashmap_node_t * node = arena_alloc ( HASHMAP_ARENA , sizeof (hashmap_node_t ));
382
385
383
386
384
387
if (!node ) {
385
388
printf ("Failed to allocate hashmap_node_t\n" );
386
389
return NULL ;
387
390
}
388
391
389
- node -> key = calloc ( len + 1 , sizeof ( char ) );
392
+ node -> key = arena_alloc ( HASHMAP_ARENA , len + 1 );
390
393
391
394
if (!node -> key ) {
392
395
printf ("Failed to allocate hashmap_node_t key with size %d\n" , len + 1 );
@@ -526,16 +529,6 @@ void hashmap_free(hashmap_t *map)
526
529
if (!map )
527
530
return ;
528
531
529
- for (int i = 0 ; i < map -> size ; i ++ ) {
530
- for (hashmap_node_t * cur = map -> buckets [i ], * next ; cur ; cur = next ) {
531
- next = cur -> next ;
532
- free (cur -> key );
533
- free (cur -> val );
534
- free (cur );
535
- cur = next ;
536
- }
537
- }
538
-
539
532
free (map -> buckets );
540
533
free (map );
541
534
}
@@ -1073,6 +1066,7 @@ void global_init(void)
1073
1066
BLOCK_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1074
1067
INSN_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1075
1068
BB_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1069
+ HASHMAP_ARENA = arena_init (DEFAULT_ARENA_SIZE );
1076
1070
PH2_IR_FLATTEN = malloc (MAX_IR_INSTR * sizeof (ph2_ir_t * ));
1077
1071
SOURCE = strbuf_create (MAX_SOURCE );
1078
1072
FUNC_MAP = hashmap_create (DEFAULT_FUNCS_SIZE );
@@ -1095,6 +1089,7 @@ void global_release(void)
1095
1089
arena_free (BLOCK_ARENA );
1096
1090
arena_free (INSN_ARENA );
1097
1091
arena_free (BB_ARENA );
1092
+ arena_free (HASHMAP_ARENA );
1098
1093
free (PH2_IR_FLATTEN );
1099
1094
strbuf_free (SOURCE );
1100
1095
hashmap_free (FUNC_MAP );
0 commit comments