|
12 | 12 |
|
13 | 13 | #include <solvers/floatbv/float_utils.h>
|
14 | 14 |
|
| 15 | +#include <algorithm> |
| 16 | +#include <iterator> |
| 17 | + |
15 | 18 | #include "boolbv_type.h"
|
16 | 19 |
|
17 | 20 | bvt boolbvt::convert_unary_minus(const unary_exprt &expr)
|
@@ -48,42 +51,28 @@ bvt boolbvt::convert_unary_minus(const unary_exprt &expr)
|
48 | 51 | "total bitvector width needs to be a multiple of the component bitvector "
|
49 | 52 | "widths");
|
50 | 53 |
|
51 |
| - std::size_t size=width/sub_width; |
52 | 54 | bvt bv;
|
53 |
| - bv.resize(width); |
54 | 55 |
|
55 |
| - for(std::size_t i=0; i<size; i++) |
| 56 | + for(std::size_t sub_idx = 0; sub_idx < width; sub_idx += sub_width) |
56 | 57 | {
|
57 | 58 | bvt tmp_op;
|
58 |
| - tmp_op.resize(sub_width); |
59 |
| - |
60 |
| - for(std::size_t j=0; j<tmp_op.size(); j++) |
61 |
| - { |
62 |
| - INVARIANT( |
63 |
| - i * sub_width + j < op_bv.size(), "bit index shall be within bounds"); |
64 |
| - tmp_op[j]=op_bv[i*sub_width+j]; |
65 |
| - } |
66 | 59 |
|
67 |
| - bvt tmp_result; |
| 60 | + const auto sub_it = std::next(op_bv.begin(), sub_idx); |
| 61 | + std::copy_n(sub_it, sub_width, std::back_inserter(tmp_op)); |
68 | 62 |
|
69 |
| - if(type.subtype().id()==ID_floatbv) |
| 63 | + if(type.subtype().id() == ID_floatbv) |
70 | 64 | {
|
71 | 65 | float_utilst float_utils(prop, to_floatbv_type(subtype));
|
72 |
| - tmp_result=float_utils.negate(tmp_op); |
| 66 | + tmp_op = float_utils.negate(tmp_op); |
73 | 67 | }
|
74 | 68 | else
|
75 |
| - tmp_result=bv_utils.negate(tmp_op); |
| 69 | + tmp_op = bv_utils.negate(tmp_op); |
76 | 70 |
|
77 | 71 | INVARIANT(
|
78 |
| - tmp_result.size() == sub_width, |
| 72 | + tmp_op.size() == sub_width, |
79 | 73 | "bitvector after negation shall have same bit width");
|
80 | 74 |
|
81 |
| - for(std::size_t j=0; j<tmp_result.size(); j++) |
82 |
| - { |
83 |
| - INVARIANT( |
84 |
| - i * sub_width + j < bv.size(), "bit index shall be within bounds"); |
85 |
| - bv[i*sub_width+j]=tmp_result[j]; |
86 |
| - } |
| 75 | + std::copy(tmp_op.begin(), tmp_op.end(), std::back_inserter(bv)); |
87 | 76 | }
|
88 | 77 |
|
89 | 78 | return bv;
|
|
0 commit comments