Skip to content

Commit bb86d1b

Browse files
committed
Fixed memory alignment warnings
1 parent e148456 commit bb86d1b

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/ptrie/ptrie.h

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ void mem_assign(void* memory, const T& value)
6969

7070
/// Solves alignment warnings when writing into compressed storage
7171
template <typename T>
72-
void mem_copy(const T& value, T* memory)
72+
void mem_copy(const T* src, T* dest, size_t count)
7373
{
74-
std::memcpy(memory, &value, sizeof(T));
74+
std::memcpy((void*)dest, (void*)src, sizeof(src[0]) * count);
7575
}
7676

7777
/// type-punning uint16_t with uchar
@@ -1102,7 +1102,7 @@ void __ptrie<PTRIETLPA>::split_fwd(node_t* const node, fwdnode_t* const jumppar,
11021102
if (to_cut != 0) {
11031103
if constexpr (HAS_ENTRIES) {
11041104
auto* e = bucket.entries(bucketsize);
1105-
std::copy_n(e, bucketsize, node->_data.entries(bucketsize));
1105+
mem_copy(e, node->_data.entries(bucketsize), bucketsize);
11061106
}
11071107
lown._data.clear();
11081108
} else
@@ -1118,7 +1118,7 @@ void __ptrie<PTRIETLPA>::split_fwd(node_t* const node, fwdnode_t* const jumppar,
11181118
if (to_cut != 0) {
11191119
if constexpr (HAS_ENTRIES) {
11201120
auto* e = bucket.entries(bucketsize);
1121-
std::copy_n(e, bucketsize, lown._data.entries(bucketsize));
1121+
mem_copy(e, lown._data.entries(bucketsize), bucketsize);
11221122
}
11231123
node->_data = std::move(lown._data);
11241124
} else
@@ -1447,12 +1447,12 @@ returntype_t __ptrie<PTRIETLPA>::insert(const KEY* data, size_t length)
14471447
size_t entry = 0;
14481448
if constexpr (HAS_ENTRIES) {
14491449
// copy over entries
1450-
{
1451-
auto* src = node->_data.entries(node->_count);
1452-
auto* mid = src + b_index;
1453-
auto* end = mid + (node->_count - b_index);
1454-
std::copy(src, mid, nbucket.entries(nbucketcount));
1455-
std::copy(mid, end, nbucket.entries(nbucketcount) + b_index + 1);
1450+
if (node->_data) {
1451+
const auto* src = node->_data.entries(node->_count);
1452+
const auto* mid = src + b_index;
1453+
auto* dest = nbucket.entries(nbucketcount);
1454+
mem_copy(src, dest, b_index);
1455+
mem_copy(mid, dest + b_index + 1, node->_count - b_index);
14561456
}
14571457

14581458
entry = _entries->next(0);
@@ -1633,10 +1633,12 @@ void __ptrie<PTRIETLPA>::merge_empty(node_t* node, int on_heap, const KEY* data,
16331633

16341634
if (other == nullptr) {
16351635
return;
1636-
} else if (other->_type != 255) {
1636+
}
1637+
if (other->_type != 255) {
16371638
node = (node_t*)other;
16381639
return merge_down(node, on_heap, data, byte);
1639-
} else if (other != parent) {
1640+
}
1641+
if (other != parent) {
16401642
assert(other->_type == 255);
16411643
return;
16421644
}
@@ -1673,8 +1675,8 @@ bool __ptrie<PTRIETLPA>::merge_nodes(node_t* node, node_t* other, uchar path)
16731675

16741676
if constexpr (HAS_ENTRIES) {
16751677
// copy over entries
1676-
std::copy_n(first->entries(), first->_count, nbucket.entries(nbucketcount));
1677-
std::copy_n(second->entries(), second->_count, nbucket.entries(nbucketcount) + first->_count);
1678+
mem_copy(first->entries(), nbucket.entries(nbucketcount), first->_count);
1679+
mem_copy(second->entries(), nbucket.entries(nbucketcount) + first->_count, second->_count);
16781680
}
16791681

16801682
// copy over old data
@@ -1951,12 +1953,11 @@ void __ptrie<PTRIETLPA>::erase(node_t* node, size_t bindex, int on_heap, const K
19511953
if constexpr (HAS_ENTRIES) {
19521954
// copy over entries
19531955
{
1954-
auto* src = node->entries();
1955-
auto* mid = src + bindex;
1956-
auto* end = src + node->_count;
1956+
const auto* src = node->entries();
1957+
const auto* mid = src + bindex;
19571958
auto* dest = node->_data.entries(node->_count);
1958-
std::copy(src, mid, dest);
1959-
std::copy(mid + 1, end, dest + bindex);
1959+
mem_copy(src, dest, bindex);
1960+
mem_copy(mid + 1, dest + bindex, node->_count - bindex - 1);
19601961
}
19611962

19621963
// copy back entries here in _entries!

0 commit comments

Comments
 (0)