Commit 8fe59b4
icgmilk
Replace MACROS with hashmap
Introduced 'MACROS_MAP' to replace the original 'MACROS' structure,
and refactored related logic with hashmap utilities.
To make this change improves memory flexibility and
future extensibility, I set 'MAX_ALIASES' to 128.
The original value (1024) is excessive, as uftrace analysis
shows that the number of aliases rarely exceeds 64
in practice(measured via 'uftrace record ./out/shecc ./src/main.c'),
and the total number of '#defines' in 'shecc' is typically below 70.
In shecc's hashmap implementation, a rehash is triggered when
the number of entries exceeds 75% of the capacity.
With this load factor of 0.75, a capacity of 128 supports up to 96
entries before rehashing, which comfortably covers observed
usage while providing sufficient headroom.
In contrast, a capacity of 64 only allows 48 entries, increasing
the likelihood of rehashing.
uftrace confirms this: setting 'MAX_ALIASES' to 64 triggered one
more 'hashmap_rehash' compared to 128.
Therefore, I chose 128 over 64 to avoid unnecessary rehashing while
still keeping memory usage significantly lower than
the original default.1 parent 7163605 commit 8fe59b4
2 files changed
+22
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
| 35 | + | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
| |||
557 | 556 | | |
558 | 557 | | |
559 | 558 | | |
560 | | - | |
561 | | - | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
562 | 569 | | |
563 | 570 | | |
564 | 571 | | |
565 | 572 | | |
566 | 573 | | |
567 | 574 | | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
572 | 578 | | |
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
576 | 582 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
582 | 587 | | |
583 | 588 | | |
584 | 589 | | |
| |||
974 | 979 | | |
975 | 980 | | |
976 | 981 | | |
977 | | - | |
| 982 | + | |
978 | 983 | | |
979 | 984 | | |
980 | 985 | | |
| |||
996 | 1001 | | |
997 | 1002 | | |
998 | 1003 | | |
999 | | - | |
| 1004 | + | |
1000 | 1005 | | |
1001 | 1006 | | |
1002 | 1007 | | |
| |||
0 commit comments