mithro / duck2-gsoc

Repository to track things that duck2 will work on for Google Summer of Code
0 stars 0 forks source link

See if replacing the key std::string with an "idstring like class" #20

Open mithro opened 5 years ago

mithro commented 5 years ago

The metadata dictionary currently uses a key of std::string. The value used for the key is frequently repeated (IE type or fasm).

Use something like the idstring for the key instead.

duck2 commented 5 years ago

What if the strings don't fit into an idstring table? Do we fall back to std::string?

mithro commented 5 years ago

I was suggesting something like;

std::map<int, std::string> id_string_table;

const char* get_string(const char* p) {
  // hash p
  int hash = std::hash(p);

  // Check if p is in id_string_table
  if (m.find(hash) == m.end())
    // Add to the map
   id_string_table.add(hash, std::string(p));

  return m.find(hash).c_str();  
}

If we run out of space in that, we have more serious problem :-P

Maybe even use the same type of istr_dptr_t tricks that idstring uses.

typedef union {
    struct {
#if BYTE_ORDER == LITTLE_ENDIAN
        uint8_t length;
#endif
        char internal[ISTR_DPTR_INTERNAL_MAXLEN];

#if BYTE_ORDER == BIG_ENDIAN
        uint8_t length;
#endif
    };
    const char* external;
} istr_dptr_t;
mithro commented 5 years ago

FYI - @hzeller

hzeller commented 5 years ago

Note, std::string already does similar tricks with using an internal buffer up to some size and does external allocation if needed. So there might not be too much gain with the istr_dptr_t itself.

But storing unified strings as int16 can really pay off. So some wrapper around the int16 pointing to a istr_dptr_table_t