Skip to contentSkip to conversation

lib: fix unnecessary boolean casts

PATCH In review Ciara Power 4 participants 5 messages Dec 2, 2019 – Feb 14, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: fix unnecessary boolean casts

The values already boolean types, so the use of !! is unnecessary as it is used to convert to boolean.

Fixes ea672a8b1655 ("mbuf: remove the rte_pktmbuf structure")
Fixes a0fd91cefcc0 ("mempool: rename functions with confusing names")
---
 lib/librte_mbuf/rte_mbuf.h       | 2 +-
 lib/librte_mempool/rte_mempool.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/librte_mbuf/rte_mbuf.h +1 -1
index 219b110b7..6d080527f 100644
@@ -1535,7 +1535,7 @@ static inline int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
 static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
 {
 	__rte_mbuf_sanity_check(m, 1);
-	return !!(m->nb_segs == 1);
+	return m->nb_segs == 1;
 }
 
 /**
lib/librte_mempool/rte_mempool.h +2 -2
index f81152af9..e588c5d9b 100644
@@ -1653,7 +1653,7 @@ rte_mempool_in_use_count(const struct rte_mempool *mp);
 static inline int
 rte_mempool_full(const struct rte_mempool *mp)
 {
-	return !!(rte_mempool_avail_count(mp) == mp->size);
+	return rte_mempool_avail_count(mp) == mp->size;
 }
 
 /**
@@ -1672,7 +1672,7 @@ rte_mempool_full(const struct rte_mempool *mp)
 static inline int
 rte_mempool_empty(const struct rte_mempool *mp)
 {
-	return !!(rte_mempool_avail_count(mp) == 0);
+	return rte_mempool_avail_count(mp) == 0;
 }
 
 /**
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#2 lore raw
In reply to Ciara Power
Quoted 10 lines · Ciara Power

The values already boolean types, so the use of !! is unnecessary as it is used to convert to boolean.

Fixes ea672a8b1655 ("mbuf: remove the rte_pktmbuf structure")
Fixes a0fd91cefcc0 ("mempool: rename functions with confusing names")

Thanks

#3 lore raw

PATCH v2 1/1 lib: fix unnecessary double negation

In reply to Ciara Power

An equality expression already returns either 0 or 1. There is no need to use double negation for these cases.

Fixes ea672a8b1655 ("mbuf: remove the rte_pktmbuf structure")
Fixes a0fd91cefcc0 ("mempool: rename functions with confusing names")

---
V2:
- Rebased onto master
- Changed commit subject and description

---
 lib/librte_mbuf/rte_mbuf.h       | 2 +-
 lib/librte_mempool/rte_mempool.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/librte_mbuf/rte_mbuf.h +1 -1
index 219b110b7..6d080527f 100644
@@ -1535,7 +1535,7 @@ static inline int rte_pktmbuf_trim(struct rte_mbuf *m, uint16_t len)
 static inline int rte_pktmbuf_is_contiguous(const struct rte_mbuf *m)
 {
 	__rte_mbuf_sanity_check(m, 1);
-	return !!(m->nb_segs == 1);
+	return m->nb_segs == 1;
 }
 
 /**
lib/librte_mempool/rte_mempool.h +2 -2
index f81152af9..e588c5d9b 100644
@@ -1653,7 +1653,7 @@ rte_mempool_in_use_count(const struct rte_mempool *mp);
 static inline int
 rte_mempool_full(const struct rte_mempool *mp)
 {
-	return !!(rte_mempool_avail_count(mp) == mp->size);
+	return rte_mempool_avail_count(mp) == mp->size;
 }
 
 /**
@@ -1672,7 +1672,7 @@ rte_mempool_full(const struct rte_mempool *mp)
 static inline int
 rte_mempool_empty(const struct rte_mempool *mp)
 {
-	return !!(rte_mempool_avail_count(mp) == 0);
+	return rte_mempool_avail_count(mp) == 0;
 }
 
 /**
Signature · 1 line
2.17.1
#4 lore raw

Re: [dpdk-dev] [PATCH v2] lib: fix unnecessary double negation

Quoted 11 lines · Ciara Power

An equality expression already returns either 0 or 1. There is no need to use double negation for these cases.

Fixes ea672a8b1655 ("mbuf: remove the rte_pktmbuf structure")
Fixes a0fd91cefcc0 ("mempool: rename functions with confusing names")

Applied, thanks.

--
David Marchand