diff options
author | Max <msuraev@sysmocom.de> | 2017-10-18 13:32:30 +0200 |
---|---|---|
committer | Max <msuraev@sysmocom.de> | 2017-10-24 12:08:34 +0200 |
commit | f0e392ac2dbb44eb42a242353f392d570b5de8e8 (patch) | |
tree | 84e63f4fc0517f0cdf7c42d972a25a2b21949822 | |
parent | 0b3db5039d25fca3d15ec3375ede77161257db4a (diff) |
Simplify bitvec_write_field()
Use existing function instead of copy-pasted loop.
Change-Id: I9fe27c06125ac52e02e63dcded056a5f1cf68f41
Related: OS#1526
-rw-r--r-- | src/bitvec.c | 16 |
1 files changed, 7 insertions, 9 deletions
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; } |