From bc87c486da5f16168c368e9167949ff8f07e7a70 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 17 Mar 2020 15:44:00 +0000 Subject: [PATCH] optimized rbt.c and htb.c a bit --- hawk/lib/htb.c | 4 ++-- hawk/lib/rbt.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hawk/lib/htb.c b/hawk/lib/htb.c index a0997546..bb50b7b3 100644 --- a/hawk/lib/htb.c +++ b/hawk/lib/htb.c @@ -300,7 +300,7 @@ int hawk_htb_init (hawk_htb_t* htb, hawk_gem_t* gem, hawk_oow_t capa, int factor htb->gem = gem; htb->bucket = hawk_gem_allocmem(gem, capa * HAWK_SIZEOF(pair_t*)); - if (htb->bucket == HAWK_NULL) return -1; + if (HAWK_UNLIKELY(!htb->bucket)) return -1; /*for (i = 0; i < capa; i++) htb->bucket[i] = HAWK_NULL;*/ HAWK_MEMSET (htb->bucket, 0, capa * HAWK_SIZEOF(pair_t*)); @@ -391,7 +391,7 @@ static HAWK_INLINE int reorganize (hawk_htb_t* htb) } new_buck = (pair_t**)hawk_gem_allocmem(htb->gem, new_capa * HAWK_SIZEOF(pair_t*)); - if (new_buck == HAWK_NULL) + if (HAWK_UNLIKELY(!new_buck)) { /* reorganization is disabled once it fails */ htb->threshold = 0; diff --git a/hawk/lib/rbt.c b/hawk/lib/rbt.c index d79068d2..639073d1 100644 --- a/hawk/lib/rbt.c +++ b/hawk/lib/rbt.c @@ -68,7 +68,7 @@ HAWK_INLINE hawk_rbt_pair_t* hawk_rbt_allocpair ( if (vcop == HAWK_RBT_COPIER_INLINE) as += VTOB(rbt,vlen); pair = (hawk_rbt_pair_t*)hawk_gem_allocmem(rbt->gem, as); - if (!pair) return HAWK_NULL; + if (HAWK_UNLIKELY(!pair)) return HAWK_NULL; pair->color = HAWK_RBT_RED; pair->parent = HAWK_NULL; @@ -196,9 +196,9 @@ hawk_rbt_t* hawk_rbt_open (hawk_gem_t* gem, hawk_oow_t xtnsize, int kscale, int hawk_rbt_t* rbt; rbt = (hawk_rbt_t*)hawk_gem_allocmem(gem, HAWK_SIZEOF(hawk_rbt_t) + xtnsize); - if (!rbt) return HAWK_NULL; + if (HAWK_UNLIKELY(!rbt)) return HAWK_NULL; - if (hawk_rbt_init(rbt, gem, kscale, vscale) <= -1) + if (HAWK_UNLIKELY(hawk_rbt_init(rbt, gem, kscale, vscale) <= -1)) { hawk_gem_freemem (gem, rbt); return HAWK_NULL; @@ -443,7 +443,7 @@ static hawk_rbt_pair_t* change_pair_val ( { /* need to reconstruct the pair */ hawk_rbt_pair_t* p = hawk_rbt_allocpair(rbt, KPTR(pair), KLEN(pair), vptr, vlen); - if (p == HAWK_NULL) return HAWK_NULL; + if (HAWK_UNLIKELY(!p)) return HAWK_NULL; p->color = pair->color; p->left = pair->left; @@ -530,7 +530,7 @@ static hawk_rbt_pair_t* insert (hawk_rbt_t* rbt, void* kptr, hawk_oow_t klen, vo } x_new = hawk_rbt_allocpair(rbt, kptr, klen, vptr, vlen); - if (x_new == HAWK_NULL) return HAWK_NULL; + if (HAWK_UNLIKELY(!x_new)) return HAWK_NULL; if (x_par == HAWK_NULL) {