-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve STVector256 deserialization #4204
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,19 +26,19 @@ namespace ripple { | |
|
||
STVector256::STVector256(SerialIter& sit, SField const& name) : STBase(name) | ||
{ | ||
Blob data = sit.getVL(); | ||
auto const count = data.size() / (256 / 8); | ||
mValue.reserve(count); | ||
Blob::iterator begin = data.begin(); | ||
unsigned int uStart = 0; | ||
for (unsigned int i = 0; i != count; i++) | ||
{ | ||
unsigned int uEnd = uStart + (256 / 8); | ||
// This next line could be optimized to construct a default | ||
// uint256 in the vector and then copy into it | ||
mValue.push_back(uint256(Blob(begin + uStart, begin + uEnd))); | ||
uStart = uEnd; | ||
} | ||
auto const slice = sit.getSlice(sit.getVLDataLength()); | ||
|
||
if (slice.size() % uint256::size() != 0) | ||
Throw<std::runtime_error>( | ||
"Bad serialization for STVector256: " + | ||
std::to_string(slice.size())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The I think it's fine as-is, but I did want to bring this up. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for bringing this up. So two comments:
Given than we're planning to introduce another fix amendment to correct a minor issue identified with the XLS-20 implementation, which (for obvious reasons!) should be activated before XLS-20 implementation, I think my suggestion would be to include this code with this release. It doesn't need to be directly gated by the amendment, but if the fix amendment activates before Apropos of this, I wonder what the performance implications of always executing the serialization/deserialization check that's currently only done if compiled with There are good reasons to have it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the clarifications. Yeah, definitely fine as-is. 👍 |
||
|
||
auto const cnt = slice.size() / uint256::size(); | ||
|
||
mValue.reserve(cnt); | ||
|
||
for (std::size_t i = 0; i != cnt; ++i) | ||
mValue.emplace_back(slice.substr(i * uint256::size(), uint256::size())); | ||
} | ||
|
||
STBase* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
using const_iterator = value_type const*;