-
Notifications
You must be signed in to change notification settings - Fork 40
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
Size limited containers; Refactored Buffer and BufferView #1373
Conversation
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1373 +/- ##
==========================================
+ Coverage 24.19% 24.57% +0.38%
==========================================
Files 628 629 +1
Lines 23520 23613 +93
Branches 12287 12288 +1
==========================================
+ Hits 5691 5804 +113
- Misses 12540 12543 +3
+ Partials 5289 5266 -23
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
…nditional compiling Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
bool operator==(const Base &other) const noexcept { | ||
return Base::size() == other.size() | ||
and std::equal( | ||
Base::cbegin(), Base::cend(), other.cbegin(), other.cend()); | ||
} | ||
|
||
template <size_t Size> | ||
bool operator==(const std::array<typename Base::value_type, Size> &other) | ||
const noexcept { | ||
return Base::size() == Size | ||
and std::equal( | ||
Base::cbegin(), Base::cend(), other.cbegin(), other.cend()); | ||
} | ||
|
||
bool operator<(const Base &other) const noexcept { | ||
return std::lexicographical_compare( | ||
Base::cbegin(), Base::cend(), other.cbegin(), other.cend()); | ||
} | ||
|
||
template <size_t Size> | ||
bool operator<(const std::array<typename Base::value_type, Size> &other) | ||
const noexcept { | ||
return std::lexicographical_compare( | ||
Base::cbegin(), Base::cend(), other.cbegin(), other.cend()); | ||
} |
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.
May want bidirectional compare like Self < Base
and Base < Self
.
Maybe boost::equality_comparable
, or friend functions.
|
||
SizeLimitedContainer() = default; | ||
|
||
SizeLimitedContainer( |
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.
Я бы оставил только мув-/копи-конструкторы, инит лист, и через итераторы.
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
|
||
template <size_t MaxSize> | ||
using SLBufer = BufferT<MaxSize>; | ||
typedef SLBuffer<std::numeric_limits<size_t>::max()> Buffer; |
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.
Why not using
?
|
||
back_insert_iterator<Buffer> &operator=(uint8_t value) { | ||
back_insert_iterator<Container> &operator=(uint8_t value) { |
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.
May shorten
back_insert_iterator<Container> &operator=(uint8_t value) { | |
using Self = back_insert_iterator<Container>; | |
Self &operator=(uint8_t value) { |
or
back_insert_iterator<Container> &operator=(uint8_t value) { | |
auto &operator=(uint8_t value) { |
return Base(size); | ||
}()) {} | ||
|
||
SizeLimitedContainer(size_t size, const typename Base::value_type &value) |
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.
Can we simplify typename Base::value_type
to
value_type
(because we are already inherited that container)
or using
?
|
||
std::ostream &operator<<(std::ostream &os, const Buffer &buffer); | ||
std::ostream &operator<<(std::ostream &os, BufferView view); | ||
using BufferMutRef = std::reference_wrapper<Buffer>; |
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.
Unused
using BufferMutRef = std::reference_wrapper<Buffer>; |
@@ -41,7 +40,8 @@ namespace kagome::blockchain { | |||
} | |||
auto root = trie.getRoot(); | |||
if (root == nullptr) { | |||
return codec.hash256(common::Buffer{0}); | |||
static const auto zero_hash = codec.hash256(common::Buffer{0}); |
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.
Testing mocks may conflict
@@ -371,7 +371,7 @@ namespace kagome::host_api { | |||
storage::trie::PolkadotCodec codec; | |||
if (pv.empty()) { | |||
static const auto empty_root = | |||
common::Buffer{}.put(codec.hash256(common::Buffer{0})); | |||
common::Buffer(codec.hash256(common::Buffer{0})); |
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.
Should this be moved to global const?
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
Signed-off-by: Dmitriy Khaustov aka xDimon [email protected]
Referenced issues
Resolves #1364
Description of the Change
Implemented size limited containers.
Refactored Buffer and BufferView: inheritance instead composition, hold mover span by BufferView
Benefits
Ability to limit size of containers (i.e. can be useful during scale-decode).
Fixed some using memory of just destroyed temporary buffers.
Usage Examples or Tests
Appended