lawrancej / CompilerKit

Compiler construction library in C.
GNU Lesser General Public License v2.1
55 stars 33 forks source link

Make Symbol a Flyweight #30

Open lawrancej opened 12 years ago

lawrancej commented 12 years ago

If we call compilerkit_symbol_new('a') twice, it allocates two objects, which wastes space. The second time compilerkit_symbol_new('a') returns, it should return the instance of symbol a allocated previously.

Modify compilerkit_symbol_new to use a statically allocated hash table to track symbol instances, keyed by the character. Also, write a test case in tests/symbol-test.c that compares the pointers returned by compilerkit_symbol_new to ensure it's doing the job correctly.

theCompanyDream commented 12 years ago

I'll give this a shot