mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Avoid bad code #4052
This commit is contained in:
parent
e8871bc211
commit
78671d15bd
@ -43,14 +43,17 @@ void compressDataForType(const char * source, UInt32 source_size, char * dest)
|
|||||||
if (source_size % sizeof(T) != 0)
|
if (source_size % sizeof(T) != 0)
|
||||||
throw Exception("Cannot delta compress, data size " + toString(source_size) + " is not aligned to " + toString(sizeof(T)), ErrorCodes::CANNOT_COMPRESS);
|
throw Exception("Cannot delta compress, data size " + toString(source_size) + " is not aligned to " + toString(sizeof(T)), ErrorCodes::CANNOT_COMPRESS);
|
||||||
|
|
||||||
const auto * source_with_type = reinterpret_cast<const T *>(source);
|
T prev_src{};
|
||||||
auto * dest_with_type = reinterpret_cast<T *>(dest);
|
const char * source_end = source + source_size;
|
||||||
|
while (source < source_end)
|
||||||
|
{
|
||||||
|
T curr_src = unalignedLoad<T>(source);
|
||||||
|
unalignedStore(dest, curr_src - prev_src);
|
||||||
|
prev_src = curr_src;
|
||||||
|
|
||||||
if (source_size > 0)
|
source += sizeof(T);
|
||||||
unalignedStore<T>(&dest_with_type[0], source_with_type[0]);
|
dest += sizeof(T);
|
||||||
|
}
|
||||||
for (size_t dest_index = 1, dest_end = source_size / sizeof(T); dest_index < dest_end; ++dest_index)
|
|
||||||
unalignedStore<T>(&dest_with_type[dest_index], source_with_type[dest_index] - source_with_type[dest_index - 1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -59,14 +62,16 @@ void decompressDataForType(const char * source, UInt32 source_size, char * dest)
|
|||||||
if (source_size % sizeof(T) != 0)
|
if (source_size % sizeof(T) != 0)
|
||||||
throw Exception("Cannot delta decompress, data size " + toString(source_size) + " is not aligned to " + toString(sizeof(T)), ErrorCodes::CANNOT_DECOMPRESS);
|
throw Exception("Cannot delta decompress, data size " + toString(source_size) + " is not aligned to " + toString(sizeof(T)), ErrorCodes::CANNOT_DECOMPRESS);
|
||||||
|
|
||||||
const auto * source_with_type = reinterpret_cast<const T *>(source);
|
T accumulator{};
|
||||||
auto * dest_with_type = reinterpret_cast<T *>(dest);
|
const char * source_end = source + source_size;
|
||||||
|
while (source < source_end)
|
||||||
|
{
|
||||||
|
accumulator += unalignedLoad<T>(source);
|
||||||
|
unalignedStore(dest, accumulator);
|
||||||
|
|
||||||
if (source_size > 0)
|
source += sizeof(T);
|
||||||
unalignedStore<T>(&dest_with_type[0], source_with_type[0]);
|
dest += sizeof(T);
|
||||||
|
}
|
||||||
for (size_t dest_index = 1, dest_end = source_size / sizeof(T); dest_index < dest_end; ++dest_index)
|
|
||||||
unalignedStore<T>(&dest_with_type[dest_index], source_with_type[dest_index] + dest_with_type[dest_index - 1]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user