Open mithro opened 5 years ago
What if the strings don't fit into an idstring table? Do we fall back to std::string?
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;
FYI - @hzeller
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
The metadata dictionary currently uses a key of
std::string
. The value used for the key is frequently repeated (IEtype
orfasm
).Use something like the idstring for the key instead.