Skip to content

Commit d19cb72

Browse files
assert: Made Expects/Ensures cheaper
1 parent 4f2635e commit d19cb72

2 files changed

Lines changed: 4 additions & 22 deletions

File tree

api/common

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,11 @@
5353
#undef Expects
5454
#undef Ensures
5555

56-
#define Expects(cond) \
57-
do { \
58-
if (UNLIKELY(not (cond))) { \
59-
std::cerr << "OS: Precondition (" OS_STRINGIFY(cond) \
60-
<< ") failed...\n" << "\t...in function: " \
61-
<< __func__ << " @" << __FILE__ << ":" \
62-
<< __LINE__ << '\n'; \
63-
std::terminate(); \
64-
} \
65-
} while(0)
56+
#define Expects(cond) \
57+
assert(LIKELY(cond) && "OS: Precondition failed")
6658

67-
#define Ensures(cond) \
68-
do { \
69-
if (UNLIKELY(not (cond))) { \
70-
std::cerr << "OS: Postcondition (" OS_STRINGIFY(cond) \
71-
<< ") failed...\n" << "\t...in function: " \
72-
<< __func__ << " @" << __FILE__ << ":" \
73-
<< __LINE__ << '\n'; \
74-
std::terminate(); \
75-
} \
76-
} while(0)
59+
#define Ensures(cond) \
60+
assert(LIKELY(cond) && "OS: Postcondition failed")
7761

7862
#endif //< defined(OS_TERMINATE_ON_CONTRACT_VIOLATION)
7963

api/net/ip4/packet_ip4.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,11 @@ namespace net {
105105

106106
Byte* ip_data() noexcept __attribute__((assume_aligned(4)))
107107
{
108-
Expects((size_t)(data_end() - layer_begin()) >= sizeof(IP4::header));
109108
return layer_begin() + ip_header_length();
110109
}
111110

112111
const Byte* ip_data() const noexcept __attribute__((assume_aligned(4)))
113112
{
114-
Expects((size_t)(data_end() - layer_begin()) >= sizeof(IP4::header));
115113
return layer_begin() + ip_header_length();
116114
}
117115

0 commit comments

Comments
 (0)