Remove unused HashKey constructor and reorder for consistency

One of the HashKey constructors was only used in the old CompHash code.
This aso reorders some constructors and the destructor for readability.
This commit is contained in:
Christian Kreibich 2021-09-16 17:19:55 -07:00
parent 4d58b98c70
commit 10e8d36340
2 changed files with 13 additions and 36 deletions

View file

@ -161,17 +161,11 @@ HashKey::HashKey(const String* s)
key = (char*)s->Bytes();
}
HashKey::HashKey(int copy_key, void* arg_key, size_t arg_size)
HashKey::HashKey(const void* bytes, size_t arg_size)
{
size = write_size = arg_size;
if ( copy_key )
{
key = new char[size]; // s == 0 is okay, returns non-nil
memcpy(key, arg_key, size);
}
else
key = (char*)arg_key;
key = CopyKey((char*)bytes, size);
is_our_dynamic = true;
}
HashKey::HashKey(const void* arg_key, size_t arg_size, hash_t arg_hash)
@ -189,13 +183,6 @@ HashKey::HashKey(const void* arg_key, size_t arg_size, hash_t arg_hash, bool /*
key = (char*)arg_key;
}
HashKey::HashKey(const void* bytes, size_t arg_size)
{
size = write_size = arg_size;
key = CopyKey((char*)bytes, size);
is_our_dynamic = true;
}
hash_t HashKey::Hash() const
{
if ( hash == 0 )

View file

@ -243,34 +243,24 @@ public:
explicit HashKey(const char* s); // No copying, no ownership
explicit HashKey(const String* s); // No copying, no ownership
~HashKey()
{
if ( is_our_dynamic )
delete[](char*) key;
}
// Create a HashKey given all of its components. "key" is assumed
// to be dynamically allocated and to now belong to this HashKey
// (to delete upon destruct'ing). If "copy_key" is true, it's
// first copied.
//
// The calling sequence here is unusual (normally key would be
// first) to avoid possible ambiguities with the next constructor,
// which is the more commonly used one.
HashKey(int copy_key, void* key, size_t size);
// Same, but automatically copies the key.
HashKey(const void* key, size_t size, hash_t hash);
// Builds a key from the given chunk of bytes.
// Builds a key from the given chunk of bytes. Copies the data.
HashKey(const void* bytes, size_t size);
// Create a HashKey given all of its components. Copies the key.
HashKey(const void* key, size_t size, hash_t hash);
// Create a Hashkey given all of its components *without*
// copying the key and *without* taking ownership. Note that
// "dont_copy" is a type placeholder to differentiate this member
// function from the one above; its value is not used.
HashKey(const void* key, size_t size, hash_t hash, bool dont_copy);
~HashKey()
{
if ( is_our_dynamic )
delete[](char*) key;
}
// Hands over the key to the caller. This means that if the
// key is our dynamic, we give it to the caller and mark it
// as not our dynamic. If initially it's not our dynamic,