Skip to content

Commit 768e298

Browse files
msoosethclaude
andcommitted
libsolutil: append SHA-256 input via vector::insert
picosha2::hash256_one_by_one::process appends its input range to the internal buffer with std::copy + std::back_inserter, producing O(N) individual push_back calls (one capacity check per byte). For the random-access iterators this template is used with, vector::insert at the end is equivalent and does a single resize + bulk copy. Functional behavior is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 68d1a77 commit 768e298

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Language Features:
44

55
Compiler Features:
6+
* General: Speed up SHA-256 hashing (`picosha2`) by avoiding per-byte `vector::push_back` when consuming input.
67

78
Bugfixes:
89

libsolutil/picosha2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class hash256_one_by_one {
193193
template <typename RaIter>
194194
void process(RaIter first, RaIter last) {
195195
add_to_data_length(static_cast<word_t>(std::distance(first, last)));
196-
std::copy(first, last, std::back_inserter(buffer_));
196+
buffer_.insert(buffer_.end(), first, last);
197197
std::size_t i = 0;
198198
for (; i + 64 <= buffer_.size(); i += 64) {
199199
detail::hash256_block(h_, buffer_.begin() + long(i),

0 commit comments

Comments
 (0)