From a041af486dcba18b1fbd9a9e5d81730416f7ec52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 11 Dec 2016 03:56:56 -0500 Subject: [PATCH] Add branch prediction hints in ref count interface MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/babeltrace/ref-internal.h | 4 ++-- lib/ref.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/babeltrace/ref-internal.h b/include/babeltrace/ref-internal.h index cf1547da..c5d8143a 100644 --- a/include/babeltrace/ref-internal.h +++ b/include/babeltrace/ref-internal.h @@ -51,7 +51,7 @@ void bt_ref_get(struct bt_ref *ref) { assert(ref); - if (!ref->release) { + if (unlikely(!ref->release)) { return; } @@ -65,7 +65,7 @@ void bt_ref_put(struct bt_ref *ref) { assert(ref); /* Only assert if the object has opted-in for reference counting. */ - if ((--ref->count) == 0 && ref->release) { + if (unlikely((--ref->count) == 0 && ref->release)) { ref->release((struct bt_object *) ref); } } diff --git a/lib/ref.c b/lib/ref.c index ac058013..4e245adf 100644 --- a/lib/ref.c +++ b/lib/ref.c @@ -31,11 +31,11 @@ void *bt_get(void *ptr) { struct bt_object *obj = ptr; - if (!obj) { + if (unlikely(!obj)) { goto end; } - if (obj->parent && bt_object_get_ref_count(obj) == 0) { + if (unlikely(obj->parent && bt_object_get_ref_count(obj) == 0)) { bt_get(obj->parent); } bt_ref_get(&obj->ref_count); @@ -47,7 +47,7 @@ void bt_put(void *ptr) { struct bt_object *obj = ptr; - if (!obj) { + if (unlikely(!obj)) { return; } -- 2.34.1