[MERGED] libosmocore[master]: Simplify bitvec_write_field()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Tue Oct 24 10:22:03 UTC 2017


Max has submitted this change and it was merged.

Change subject: Simplify bitvec_write_field()
......................................................................


Simplify bitvec_write_field()

Use existing function instead of copy-pasted loop.

Change-Id: I9fe27c06125ac52e02e63dcded056a5f1cf68f41
Related: OS#1526
---
M src/bitvec.c
1 file changed, 7 insertions(+), 9 deletions(-)

Approvals:
  Neels Hofmeyr: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/bitvec.c b/src/bitvec.c
index 24049cd..e86315c 100644
--- a/src/bitvec.c
+++ b/src/bitvec.c
@@ -505,18 +505,16 @@
  */
 int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len)
 {
-	unsigned int i;
 	int rc;
+
 	bv->cur_bit = *write_index;
-	for (i = 0; i < len; i++) {
-		int bit = 0;
-		if (val & ((uint64_t)1 << (len - i - 1)))
-			bit = 1;
-		rc = bitvec_set_bit(bv, bit);
-		if (rc)
-			return rc;
-	}
+
+	rc = bitvec_set_u64(bv, val, len, false);
+	if (rc != 0)
+		return rc;
+
 	*write_index += len;
+
 	return 0;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/4339
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9fe27c06125ac52e02e63dcded056a5f1cf68f41
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Minh-Quang Nguyen <minh-quang.nguyen at nutaq.com>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list