justinethier / cyclone

:cyclone: A brand-new compiler that allows practical application development using R7RS Scheme. We provide modern features and a stable system capable of generating fast native binaries.
http://justinethier.github.io/cyclone/
MIT License
823 stars 42 forks source link

Optimize memory allocation for symbols #515

Open justinethier opened 9 months ago

justinethier commented 9 months ago

It seems like the strdup and memcpy are doing the same work twice for name. Is there a more efficient way to implement this, in terms of both CPU and memory?

static object add_symbol_by_name(const char *name)                                                                                            
{                                                                                
  symbol_type sym = { {0}, symbol_tag, _strdup(name)};                           
  symbol_type *psym = malloc(sizeof(symbol_type));                                                                                            
  memcpy(psym, &sym, sizeof(symbol_type));                                       
  return add_symbol(psym);                                                       
}