Skip to content

Commit 66a34da

Browse files
authored
Merge pull request #1280 from SekaiArendelle/attributes
remove redundant __has_cpp_attribute guards for [[likely]]/[[unlikely]]
2 parents 7668a55 + 82ced8e commit 66a34da

16 files changed

Lines changed: 25 additions & 109 deletions

File tree

include/fast_io_core_impl/allocation/nt_rtlheapalloc.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#include "nt_preliminary_definition.h"
44

@@ -19,9 +19,7 @@ inline void *nt_rtlallocate_heap_handle_common_impl(void *heaphandle, ::std::siz
1919
}
2020
auto p{::fast_io::win32::nt::RtlAllocateHeap(heaphandle, flag, n)};
2121
if (p == nullptr)
22-
#if __has_cpp_attribute(unlikely)
2322
[[unlikely]]
24-
#endif
2523
{
2624
::fast_io::fast_terminate();
2725
}
@@ -38,9 +36,7 @@ inline void *nt_rtlreallocate_heap_handle_common_impl(void *heaphandle, void *ad
3836
n = 1;
3937
}
4038
if (addr == nullptr)
41-
#if __has_cpp_attribute(unlikely)
4239
[[unlikely]]
43-
#endif
4440
{
4541
return ::fast_io::details::nt_rtlallocate_heap_handle_common_impl(heaphandle, n, flag);
4642
}

include/fast_io_core_impl/allocation/win32_heapalloc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io
44
{
@@ -59,9 +59,7 @@ inline void *win32_heaprealloc_handle_common_impl(void *heaphandle, void *addr,
5959
n = 1;
6060
}
6161
if (addr == nullptr)
62-
#if __has_cpp_attribute(unlikely)
6362
[[unlikely]]
64-
#endif
6563
{
6664
return win32_heapalloc_handle_common_impl(heaphandle, n, flag);
6765
}

include/fast_io_core_impl/freestanding/bytes.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io::details
44
{
@@ -84,12 +84,10 @@ inline constexpr ::std::byte *bytes_copy_n(::std::byte const *first, ::std::size
8484
else
8585
{
8686
if (n)
87-
#if __has_cpp_attribute(likely)
8887
[[likely]]
89-
#endif
9088
{
9189
#if FAST_IO_HAS_BUILTIN(__builtin_memmove)
92-
__builtin_memmove(dest, first, n);
90+
__builtin_memmove(dest, first, n);
9391
#else
9492
::std::memmove(dest, first, n);
9593
#endif
@@ -116,12 +114,10 @@ inline constexpr ::std::byte *nonoverlapped_bytes_copy_n(::std::byte const *firs
116114
else
117115
{
118116
if (n)
119-
#if __has_cpp_attribute(likely)
120117
[[likely]]
121-
#endif
122118
{
123119
#if FAST_IO_HAS_BUILTIN(__builtin_memcpy)
124-
__builtin_memcpy(dest, first, n);
120+
__builtin_memcpy(dest, first, n);
125121
#else
126122
::std::memcpy(dest, first, n);
127123
#endif
@@ -155,7 +151,7 @@ inline constexpr ::std::byte const *type_punning_from_bytes(::std::byte const *_
155151
#endif
156152
{
157153
#if FAST_IO_HAS_BUILTIN(__builtin_memcpy)
158-
__builtin_memcpy(__builtin_addressof(t), first, n);
154+
__builtin_memcpy(__builtin_addressof(t), first, n);
159155
#else
160156
::std::memcpy(__builtin_addressof(t), first, n);
161157
#endif
@@ -180,7 +176,7 @@ inline constexpr ::std::byte *type_punning_to_bytes_n(T const &__restrict first,
180176
#endif
181177
{
182178
#if FAST_IO_HAS_BUILTIN(__builtin_memcpy)
183-
__builtin_memcpy(dest, __builtin_addressof(first), n);
179+
__builtin_memcpy(dest, __builtin_addressof(first), n);
184180
#else
185181
::std::memcpy(dest, __builtin_addressof(first), n);
186182
#endif
@@ -208,7 +204,7 @@ inline constexpr ::std::byte *bytes_clear_n(::std::byte *data, ::std::size_t siz
208204
else
209205
{
210206
#if FAST_IO_HAS_BUILTIN(__builtin_memset)
211-
__builtin_memset(data, 0, size);
207+
__builtin_memset(data, 0, size);
212208
#else
213209
::std::memset(data, 0, size);
214210
#endif
@@ -233,7 +229,7 @@ inline constexpr ::std::byte *bytes_fill_n(::std::byte *data, ::std::size_t size
233229
else
234230
{
235231
#if FAST_IO_HAS_BUILTIN(__builtin_memset)
236-
__builtin_memset(data, static_cast<char unsigned>(val), size);
232+
__builtin_memset(data, static_cast<char unsigned>(val), size);
237233
#else
238234
::std::memset(data, static_cast<char unsigned>(val), size);
239235
#endif

include/fast_io_core_impl/integers/percentage.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io
44
{
@@ -270,9 +270,7 @@ inline constexpr chartype *prrsv_percentage_main_common_impl(chartype *iter, T n
270270
bool denominatoriseven{!(denominator & 1u)};
271271
unsigned quotientmod100;
272272
if (numerator10000high == 0u)
273-
#if __has_cpp_attribute(likely)
274273
[[likely]]
275-
#endif
276274
{
277275
auto quotient{numerator10000low / denominator};
278276
auto remainder{numerator10000low % denominator};

include/fast_io_core_impl/operations/printimpl/print_freestanding_cxx20.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io
44
{
@@ -435,9 +435,7 @@ inline constexpr void print_control_single(output outstm, T t)
435435
bool smaller{static_cast<::std::ptrdiff_t>(size) < diff};
436436
::fast_io::details::local_operator_new_array_ptr<char_type> newptr;
437437
if (!smaller)
438-
#if __has_cpp_attribute(unlikely)
439438
[[unlikely]]
440-
#endif
441439
{
442440
newptr.ptr = toptr = ::fast_io::details::allocate_iobuf_space<
443441
char_type,
@@ -456,9 +454,7 @@ inline constexpr void print_control_single(output outstm, T t)
456454
obuffer_set_curr(outstm, it);
457455
}
458456
else
459-
#if __has_cpp_attribute(unlikely)
460457
[[unlikely]]
461-
#endif
462458
{
463459
::fast_io::operations::decay::write_all_decay(outstm, toptr, it);
464460
}
@@ -532,9 +528,7 @@ inline constexpr void print_control_single(output outstm, T t)
532528
auto bcurr{obuffer_curr(outstm)};
533529
auto bed{obuffer_end(outstm)};
534530
if (bed <= bcurr)
535-
#if __has_cpp_attribute(unlikely)
536531
[[unlikely]]
537-
#endif
538532
{
539533
if constexpr (minimum_buffer_output_stream_require_size_impl<output, reserved_size>)
540534
{
@@ -548,9 +542,7 @@ inline constexpr void print_control_single(output outstm, T t)
548542
bcurr = obuffer_curr(outstm);
549543
bed = obuffer_end(outstm);
550544
if (bed - bcurr < reserved_size_no_line)
551-
#if __has_cpp_attribute(unlikely)
552545
[[unlikely]]
553-
#endif
554546
{
555547
char_type buffer[reserved_size];
556548
char_type *buffered{buffer + reserved_size_no_line};
@@ -588,9 +580,7 @@ inline constexpr void print_control_single(output outstm, T t)
588580
auto [resit, done] = st.print_context_define(t, bcurr, bed);
589581
obuffer_set_curr(outstm, resit);
590582
if (done)
591-
#if __has_cpp_attribute(likely)
592583
[[likely]]
593-
#endif
594584
{
595585
if constexpr (line)
596586
{
@@ -1406,7 +1396,7 @@ template <bool line, typename outputstmtype, typename... Args>
14061396
#endif
14071397
inline constexpr decltype(auto) print_freestanding_decay_cold(outputstmtype optstm, Args... args)
14081398
{
1409-
#if !__has_cpp_attribute(__gnu__::__cold__) && __has_cpp_attribute(unlikely)
1399+
#if !__has_cpp_attribute(__gnu__::__cold__)
14101400
if (true) [[unlikely]]
14111401
#endif
14121402
return ::fast_io::operations::decay::print_freestanding_decay<line>(optstm, args...);

include/fast_io_core_impl/operations/printimpl/print_freestanding_cxx26.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
#error "We do not recommend using this header file for the time being."
44

@@ -408,9 +408,7 @@ inline constexpr void print_control_single(output outstm, T t)
408408
bool smaller{static_cast<::std::ptrdiff_t>(size) < diff};
409409
::fast_io::details::local_operator_new_array_ptr<char_type> newptr;
410410
if (!smaller)
411-
#if __has_cpp_attribute(unlikely)
412411
[[unlikely]]
413-
#endif
414412
{
415413
newptr.ptr = toptr = ::fast_io::details::allocate_iobuf_space<
416414
char_type,
@@ -429,9 +427,7 @@ inline constexpr void print_control_single(output outstm, T t)
429427
obuffer_set_curr(outstm, it);
430428
}
431429
else
432-
#if __has_cpp_attribute(unlikely)
433430
[[unlikely]]
434-
#endif
435431
{
436432
::fast_io::operations::decay::write_all_decay(outstm, toptr, it);
437433
}
@@ -505,9 +501,7 @@ inline constexpr void print_control_single(output outstm, T t)
505501
auto bcurr{obuffer_curr(outstm)};
506502
auto bed{obuffer_end(outstm)};
507503
if (bed <= bcurr)
508-
#if __has_cpp_attribute(unlikely)
509504
[[unlikely]]
510-
#endif
511505
{
512506
if constexpr (minimum_buffer_output_stream_require_size_impl<output, reserved_size>)
513507
{
@@ -521,9 +515,7 @@ inline constexpr void print_control_single(output outstm, T t)
521515
bcurr = obuffer_curr(outstm);
522516
bed = obuffer_end(outstm);
523517
if (bed - bcurr < reserved_size_no_line)
524-
#if __has_cpp_attribute(unlikely)
525518
[[unlikely]]
526-
#endif
527519
{
528520
char_type buffer[reserved_size];
529521
char_type *buffered{buffer + reserved_size_no_line};
@@ -561,9 +553,7 @@ inline constexpr void print_control_single(output outstm, T t)
561553
auto [resit, done] = st.print_context_define(t, bcurr, bed);
562554
obuffer_set_curr(outstm, resit);
563555
if (done)
564-
#if __has_cpp_attribute(likely)
565556
[[likely]]
566-
#endif
567557
{
568558
if constexpr (line)
569559
{
@@ -1338,7 +1328,7 @@ template <bool line, typename outputstmtype, typename... Args>
13381328
#endif
13391329
inline constexpr decltype(auto) print_freestanding_decay_cold(outputstmtype optstm, Args... args)
13401330
{
1341-
#if !__has_cpp_attribute(__gnu__::__cold__) && __has_cpp_attribute(unlikely)
1331+
#if !__has_cpp_attribute(__gnu__::__cold__)
13421332
if (true) [[unlikely]]
13431333
#endif
13441334
return ::fast_io::operations::decay::print_freestanding_decay<line>(optstm, args...);

include/fast_io_core_impl/operations/readimpl/scatter.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io
44
{
@@ -11,7 +11,7 @@ inline constexpr ::std::byte *read_some_bytes_decay(instmtype insm, ::std::byte
1111

1212
template <typename instmtype>
1313
inline constexpr ::std::byte *pread_some_bytes_decay(instmtype insm, ::std::byte *first, ::std::byte *last,
14-
::fast_io::intfpos_t);
14+
::fast_io::intfpos_t);
1515

1616
} // namespace operations::decay
1717

@@ -160,9 +160,7 @@ scatter_read_some_impl(instmtype insm, basic_io_scatter_t<typename instmtype::in
160160
{
161161
auto [base, len] = *i;
162162
if (len < buffptrdiff)
163-
#if __has_cpp_attribute(likely)
164163
[[likely]]
165-
#endif
166164
{
167165
::fast_io::details::non_overlapped_copy_n(curr, len, base);
168166
curr += len;
@@ -175,9 +173,7 @@ scatter_read_some_impl(instmtype insm, basic_io_scatter_t<typename instmtype::in
175173
}
176174
ibuffer_set_curr(insm, curr);
177175
if (i != e)
178-
#if __has_cpp_attribute(unlikely)
179176
[[unlikely]]
180-
#endif
181177
{
182178
auto ret{::fast_io::details::scatter_read_some_cold_impl(insm, i, static_cast<::std::size_t>(e - i))};
183179
ret.position += static_cast<::std::size_t>(i - pscatters);
@@ -311,9 +307,7 @@ inline constexpr void scatter_read_all_impl(instmtype insm,
311307
{
312308
auto [base, len] = *i;
313309
if (len < buffptrdiff)
314-
#if __has_cpp_attribute(likely)
315310
[[likely]]
316-
#endif
317311
{
318312
::fast_io::details::non_overlapped_copy_n(curr, len, base);
319313
curr += len;
@@ -326,9 +320,7 @@ inline constexpr void scatter_read_all_impl(instmtype insm,
326320
}
327321
ibuffer_set_curr(insm, curr);
328322
if (i != e)
329-
#if __has_cpp_attribute(unlikely)
330323
[[unlikely]]
331-
#endif
332324
{
333325
return ::fast_io::details::scatter_read_all_cold_impl(insm, i, static_cast<::std::size_t>(e - i));
334326
}

include/fast_io_core_impl/operations/readimpl/scatterbytes.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace fast_io
1+
namespace fast_io
22
{
33

44
namespace details
@@ -96,9 +96,7 @@ inline constexpr io_scatter_status_t scatter_read_some_bytes_impl(instmtype insm
9696
{
9797
auto [base, len] = *i;
9898
if (len < buffptrdiff)
99-
#if __has_cpp_attribute(likely)
10099
[[likely]]
101-
#endif
102100
{
103101
using char_type_ptr
104102
#if __has_cpp_attribute(__gnu__::__may_alias__)
@@ -116,9 +114,7 @@ inline constexpr io_scatter_status_t scatter_read_some_bytes_impl(instmtype insm
116114
}
117115
ibuffer_set_curr(insm, curr);
118116
if (i != e)
119-
#if __has_cpp_attribute(unlikely)
120117
[[unlikely]]
121-
#endif
122118
{
123119
auto ret{::fast_io::details::scatter_read_some_bytes_cold_impl(insm, i, static_cast<::std::size_t>(e - i))};
124120
ret.position += static_cast<::std::size_t>(i - pscatters);
@@ -251,9 +247,7 @@ inline constexpr void scatter_read_all_bytes_impl(instmtype insm, io_scatter_t c
251247
{
252248
auto [base, len] = *i;
253249
if (len < buffptrdiff)
254-
#if __has_cpp_attribute(likely)
255250
[[likely]]
256-
#endif
257251
{
258252
using char_type_ptr
259253
#if __has_cpp_attribute(__gnu__::__may_alias__)
@@ -271,9 +265,7 @@ inline constexpr void scatter_read_all_bytes_impl(instmtype insm, io_scatter_t c
271265
}
272266
ibuffer_set_curr(insm, curr);
273267
if (i != e)
274-
#if __has_cpp_attribute(unlikely)
275268
[[unlikely]]
276-
#endif
277269
{
278270
return ::fast_io::details::scatter_read_all_bytes_cold_impl(insm, i, static_cast<::std::size_t>(e - i));
279271
}

include/fast_io_core_impl/operations/writeimpl/basis.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#pragma once
1+
#pragma once
22

33
namespace fast_io
44
{
@@ -509,9 +509,7 @@ inline constexpr void write_all_impl(outstmtype outsm, typename outstmtype::outp
509509
::std::ptrdiff_t bfddiff{ed - curr};
510510
::std::ptrdiff_t itdiff{last - first};
511511
if (itdiff < bfddiff)
512-
#if __has_cpp_attribute(likely)
513512
[[likely]]
514-
#endif
515513
{
516514
obuffer_set_curr(outsm, non_overlapped_copy_n(first, static_cast<::std::size_t>(itdiff), curr));
517515
return;
@@ -540,9 +538,7 @@ inline constexpr ::std::byte const *write_some_bytes_impl(outstmtype outsm, ::st
540538
::std::ptrdiff_t bfddiff{ed - curr};
541539
::std::ptrdiff_t itdiff{last - first};
542540
if (itdiff < bfddiff)
543-
#if __has_cpp_attribute(likely)
544541
[[likely]]
545-
#endif
546542
{
547543
using char_type_const_ptr
548544
#if __has_cpp_attribute(__gnu__::__may_alias__)
@@ -642,9 +638,7 @@ char_put_impl(outstm outsm, typename decltype(::fast_io::operations::output_stre
642638
condition = curr != ed;
643639
}
644640
if (condition)
645-
#if __has_cpp_attribute(likely)
646641
[[likely]]
647-
#endif
648642

649643
{
650644
*curr = ch;

0 commit comments

Comments
 (0)