From f0e392ac2dbb44eb42a242353f392d570b5de8e8 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 18 Oct 2017 13:32:30 +0200 Subject: Simplify bitvec_write_field() Use existing function instead of copy-pasted loop. Change-Id: I9fe27c06125ac52e02e63dcded056a5f1cf68f41 Related: OS#1526 --- src/bitvec.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/bitvec.c b/src/bitvec.c index 24049cda..e86315cb 100644 --- a/src/bitvec.c +++ b/src/bitvec.c @@ -505,18 +505,16 @@ uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned */ 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; } -- cgit v1.2.3