core: add LIKELY and UNLIKELY macros
helps the compiler optimize
This commit is contained in:
parent
2bad73354a
commit
b7a3c45269
58 changed files with 395 additions and 396 deletions
|
|
@ -126,7 +126,7 @@ bool CLinuxDMABuffer::good() {
|
|||
}
|
||||
|
||||
CLinuxDMABBUFParamsResource::CLinuxDMABBUFParamsResource(SP<CZwpLinuxBufferParamsV1> resource_) : resource(resource_) {
|
||||
if (!good())
|
||||
if UNLIKELY (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
|
||||
|
|
@ -208,12 +208,12 @@ bool CLinuxDMABBUFParamsResource::good() {
|
|||
void CLinuxDMABBUFParamsResource::create(uint32_t id) {
|
||||
used = true;
|
||||
|
||||
if (!verify()) {
|
||||
if UNLIKELY (!verify()) {
|
||||
LOGM(ERR, "Failed creating a dmabuf: verify() said no");
|
||||
return; // if verify failed, we errored the resource.
|
||||
}
|
||||
|
||||
if (!commence()) {
|
||||
if UNLIKELY (!commence()) {
|
||||
LOGM(ERR, "Failed creating a dmabuf: commence() said no");
|
||||
resource->sendFailed();
|
||||
return;
|
||||
|
|
@ -226,7 +226,7 @@ void CLinuxDMABBUFParamsResource::create(uint32_t id) {
|
|||
|
||||
auto buf = PROTO::linuxDma->m_vBuffers.emplace_back(makeShared<CLinuxDMABuffer>(id, resource->client(), *attrs));
|
||||
|
||||
if (!buf->good() || !buf->buffer->success) {
|
||||
if UNLIKELY (!buf->good() || !buf->buffer->success) {
|
||||
resource->sendFailed();
|
||||
return;
|
||||
}
|
||||
|
|
@ -259,12 +259,12 @@ bool CLinuxDMABBUFParamsResource::commence() {
|
|||
}
|
||||
|
||||
bool CLinuxDMABBUFParamsResource::verify() {
|
||||
if (attrs->planes <= 0) {
|
||||
if UNLIKELY (attrs->planes <= 0) {
|
||||
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (attrs->fds.at(0) < 0) {
|
||||
if UNLIKELY (attrs->fds.at(0) < 0) {
|
||||
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -282,7 +282,7 @@ bool CLinuxDMABBUFParamsResource::verify() {
|
|||
}
|
||||
}
|
||||
|
||||
if (attrs->size.x < 1 || attrs->size.y < 1) {
|
||||
if UNLIKELY (attrs->size.x < 1 || attrs->size.y < 1) {
|
||||
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -300,7 +300,7 @@ bool CLinuxDMABBUFParamsResource::verify() {
|
|||
}
|
||||
|
||||
CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(SP<CZwpLinuxDmabufFeedbackV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
|
||||
if (!good())
|
||||
if UNLIKELY (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
|
||||
|
|
@ -355,7 +355,7 @@ void CLinuxDMABUFFeedbackResource::sendDefaultFeedback() {
|
|||
}
|
||||
|
||||
CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : resource(resource_) {
|
||||
if (!good())
|
||||
if UNLIKELY (!good())
|
||||
return;
|
||||
|
||||
resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
|
||||
|
|
@ -365,7 +365,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
|
|||
const auto RESOURCE =
|
||||
PROTO::linuxDma->m_vFeedbacks.emplace_back(makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), nullptr));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
r->noMemory();
|
||||
PROTO::linuxDma->m_vFeedbacks.pop_back();
|
||||
return;
|
||||
|
|
@ -376,7 +376,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
|
|||
const auto RESOURCE = PROTO::linuxDma->m_vFeedbacks.emplace_back(
|
||||
makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf)));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
r->noMemory();
|
||||
PROTO::linuxDma->m_vFeedbacks.pop_back();
|
||||
return;
|
||||
|
|
@ -386,7 +386,7 @@ CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : re
|
|||
resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) {
|
||||
const auto RESOURCE = PROTO::linuxDma->m_vParams.emplace_back(makeShared<CLinuxDMABBUFParamsResource>(makeShared<CZwpLinuxBufferParamsV1>(r->client(), r->version(), id)));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
r->noMemory();
|
||||
PROTO::linuxDma->m_vParams.pop_back();
|
||||
return;
|
||||
|
|
@ -535,7 +535,7 @@ CLinuxDMABufV1Protocol::~CLinuxDMABufV1Protocol() {
|
|||
void CLinuxDMABufV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
|
||||
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CLinuxDMABUFResource>(makeShared<CZwpLinuxDmabufV1>(client, ver, id)));
|
||||
|
||||
if (!RESOURCE->good()) {
|
||||
if UNLIKELY (!RESOURCE->good()) {
|
||||
wl_client_post_no_memory(client);
|
||||
m_vManagers.pop_back();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue