Skip to content

Commit 4be8236

Browse files
authored
Merge pull request ClickHouse#67778 from ClickHouse/test_attr
Apply `preserve_most` attribute at some places in code
2 parents bc5df49 + ca07db7 commit 4be8236

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

base/base/defines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
#define NO_INLINE __attribute__((__noinline__))
2929
#define MAY_ALIAS __attribute__((__may_alias__))
3030

31+
#if defined(__x86_64__) || defined(__aarch64__)
32+
# define PRESERVE_MOST __attribute__((preserve_most))
33+
#else
34+
# define PRESERVE_MOST
35+
#endif
36+
3137
#if !defined(__x86_64__) && !defined(__aarch64__) && !defined(__PPC__) && !defined(__s390x__) && !(defined(__loongarch64)) && !(defined(__riscv) && (__riscv_xlen == 64))
3238
# error "The only supported platforms are x86_64 and AArch64, PowerPC (work in progress), s390x (work in progress), loongarch64 (experimental) and RISC-V 64 (experimental)"
3339
#endif

src/Common/Arena.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Arena : private boost::noncopyable
146146
}
147147

148148
/// Add next contiguous MemoryChunk of memory with size not less than specified.
149-
void NO_INLINE addMemoryChunk(size_t min_size)
149+
void PRESERVE_MOST NO_INLINE addMemoryChunk(size_t min_size)
150150
{
151151
size_t next_size = nextSize(min_size + pad_right);
152152
if (head.empty())

src/Common/HashTable/HashTable.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ class HashTable : private boost::noncopyable,
502502
}
503503

504504
/// Increase the size of the buffer.
505-
void resize(size_t for_num_elems = 0, size_t for_buf_size = 0)
505+
void PRESERVE_MOST resize(size_t for_num_elems = 0, size_t for_buf_size = 0)
506506
{
507507
#ifdef DBMS_HASH_MAP_DEBUG_RESIZES
508508
Stopwatch watch;
@@ -962,10 +962,7 @@ class HashTable : private boost::noncopyable,
962962
}
963963

964964
public:
965-
void reserve(size_t num_elements)
966-
{
967-
resize(num_elements);
968-
}
965+
void PRESERVE_MOST reserve(size_t num_elements) { resize(num_elements); }
969966

970967
/// Insert a value. In the case of any more complex values, it is better to use the `emplace` function.
971968
std::pair<LookupResult, bool> ALWAYS_INLINE insert(const value_type & x)

src/Common/PODArray.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class PODArrayBase : private boost::noncopyable, private TAllocator /// empty
135135
TAllocator::free(c_start - pad_left, allocated_bytes());
136136
}
137137

138-
template <typename ... TAllocatorParams>
139-
void realloc(size_t bytes, TAllocatorParams &&... allocator_params)
138+
template <typename... TAllocatorParams>
139+
void PRESERVE_MOST realloc(size_t bytes, TAllocatorParams &&... allocator_params)
140140
{
141141
if (c_start == null)
142142
{
@@ -167,8 +167,8 @@ class PODArrayBase : private boost::noncopyable, private TAllocator /// empty
167167
return (stack_threshold > 0) && (allocated_bytes() <= stack_threshold);
168168
}
169169

170-
template <typename ... TAllocatorParams>
171-
void reserveForNextSize(TAllocatorParams &&... allocator_params)
170+
template <typename... TAllocatorParams>
171+
void PRESERVE_MOST reserveForNextSize(TAllocatorParams &&... allocator_params)
172172
{
173173
if (empty())
174174
{

src/Interpreters/AggregationCommon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static inline T ALWAYS_INLINE packFixed(
174174
static constexpr auto bitmap_size = std::tuple_size<KeysNullMap<T>>::value;
175175
static constexpr bool has_bitmap = bitmap_size > 0;
176176

177-
if (has_bitmap)
177+
if constexpr (has_bitmap)
178178
{
179179
memcpy(bytes + offset, bitmap.data(), bitmap_size * sizeof(UInt8));
180180
offset += bitmap_size;

src/Interpreters/Aggregator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ Aggregator::ConvertToBlockResVariant Aggregator::convertToBlockImplFinal(
20782078
data.forEachValue(
20792079
[&](const auto & key, auto & mapped)
20802080
{
2081-
if (!out_cols.has_value())
2081+
if (unlikely(!out_cols.has_value()))
20822082
init_out_cols();
20832083

20842084
const auto & key_sizes_ref = shuffled_key_sizes ? *shuffled_key_sizes : key_sizes;

0 commit comments

Comments
 (0)