Skip to content

Commit fe0d1b0

Browse files
committed
Refactor[MQBU]: Remove unnecessary buffer from mqbu_storagekey
This patch removes a statically allocated buffer `k_NULL_KEY_BUFFER` containing five null bytes from `mqbu_storagekey`. This buffer is only used in the default constructor for `StorageKey`, where we copy the five null bytes into the `StorageKey`'s internal buffer. In place of this, we `memset` the internal buffer to `\0`. Note that elsewhere we rely on `k_NULL_KEY_BUFFER[0] == '\0'` (see src/groups/mqb/mqbu/mqbu_storagekey.h:312), so we can't freely change this constant later on. Signed-off-by: Patrick M. Niedzielski <patrick@pniedzielski.net>
1 parent 2ef4ce9 commit fe0d1b0

2 files changed

Lines changed: 1 addition & 5 deletions

File tree

src/groups/mqb/mqbu/mqbu_storagekey.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ BSLMF_ASSERT(StorageKey::e_KEY_LENGTH_BINARY == sizeof(StorageKey));
2929
// class StorageKey
3030
// ----------------
3131

32-
const char* StorageKey::k_NULL_KEY_BUFFER("\0\0\0\0\0");
3332
const StorageKey StorageKey::k_NULL_KEY;
3433

3534
// ------------------------

src/groups/mqb/mqbu/mqbu_storagekey.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ class StorageKey {
7979
private:
8080
// PRIVATE CONSTANTS
8181

82-
// This binary buffer can be used to construct an empty storage key.
83-
static const char* k_NULL_KEY_BUFFER;
84-
8582
private:
8683
// DATA
8784
char d_buffer[e_KEY_LENGTH_BINARY];
@@ -279,7 +276,7 @@ class StorageKeyHashAlgo {
279276
// CREATORS
280277
inline StorageKey::StorageKey()
281278
{
282-
bsl::memcpy(d_buffer, k_NULL_KEY_BUFFER, StorageKey::e_KEY_LENGTH_BINARY);
279+
bsl::memset(d_buffer, '\0', StorageKey::e_KEY_LENGTH_BINARY);
283280
}
284281

285282
inline StorageKey::StorageKey(const BinaryRepresentation&, const void* data)

0 commit comments

Comments
 (0)