Skip to content

Commit 2fa4fd1

Browse files
committed
Use std::iota instead of manually pushing range
1 parent 405c96f commit 2fa4fd1

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/bech32.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
#include <bech32.h>
77
#include <util/vector.h>
88

9+
#include <array>
910
#include <assert.h>
11+
#include <numeric>
1012
#include <optional>
11-
#include <array>
1213

1314
namespace bech32
1415
{
@@ -282,13 +283,6 @@ inline unsigned char LowerCase(unsigned char c)
282283
return (c >= 'A' && c <= 'Z') ? (c - 'A') + 'a' : c;
283284
}
284285

285-
void push_range(int from, int to, std::vector<int>& vec)
286-
{
287-
for (int i = from; i < to; i++) {
288-
vec.push_back(i);
289-
}
290-
}
291-
292286
/** Return indices of invalid characters in a Bech32 string. */
293287
bool CheckCharacters(const std::string& str, std::vector<int>& errors) {
294288
bool lower = false, upper = false;
@@ -404,7 +398,8 @@ DecodeResult Decode(const std::string& str) {
404398
/** Find index of an incorrect character in a Bech32 string. */
405399
std::string LocateErrors(const std::string& str, std::vector<int>& error_locations) {
406400
if (str.size() > 90) {
407-
push_range(90, str.size(), error_locations);
401+
error_locations.resize(str.size() - 90);
402+
std::iota(error_locations.begin(), error_locations.end(), 90);
408403
return "Bech32 string too long";
409404
}
410405
if (!CheckCharacters(str, error_locations)){

0 commit comments

Comments
 (0)