Skip to content

Commit

Permalink
Merge pull request #30 from Trinitou/unlikely
Browse files Browse the repository at this point in the history
Add CLAP_HELPERS_UNLIKELY
  • Loading branch information
abique authored Nov 23, 2023
2 parents 4a2e3ee + 2851221 commit 2cc2f28
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/clap/helpers/host.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <iostream>

#include "host.hh"
#include "macros.hh"

namespace clap { namespace helpers {

Expand Down Expand Up @@ -349,15 +350,15 @@ namespace clap { namespace helpers {
template <MisbehaviourHandler h, CheckingLevel l>
Host<h, l> &Host<h, l>::from(const clap_host *host) noexcept {
if constexpr (l >= CheckingLevel::Minimal) {
if (!host) [[unlikely]] {
if (!host) CLAP_HELPERS_UNLIKELY {
std::cerr << "Passed an null host pointer" << std::endl;
std::terminate();
}
}

auto self = static_cast<Host *>(host->host_data);
if constexpr (l >= CheckingLevel::Minimal) {
if (!self) [[unlikely]] {
if (!self) CLAP_HELPERS_UNLIKELY {
std::cerr << "Passed an invalid host pointer because the host_data is null"
<< std::endl;
std::terminate();
Expand Down
7 changes: 7 additions & 0 deletions include/clap/helpers/macros.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

#if defined(__cplusplus) && __cplusplus >= 202002L
# define CLAP_HELPERS_UNLIKELY [[unlikely]]
#else
# define CLAP_HELPERS_UNLIKELY
#endif

0 comments on commit 2cc2f28

Please sign in to comment.