Skip to content

Commit

Permalink
Clang tidy performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner authored and joshuacolvin0 committed Nov 12, 2021
1 parent 3270d6f commit 417f528
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ rollups
/packages/arb-rpc-node/arb-node
/packages/arb-rpc-node/cmd/arb-dev-node/arb-dev-node
/packages/arb-rpc-node/cmd/arb-dev-node/arbitrum*
compile_commands.json

# Logs
logs
Expand Down
4 changes: 4 additions & 0 deletions packages/arb-avm-cpp/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
Checks: '-*,performance-*'
WarningsAsErrors: '*'
FormatStyle: file
4 changes: 2 additions & 2 deletions packages/arb-avm-cpp/avm_values/include/avm_values/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Buffer : private std::shared_ptr<RawBuffer> {
// Sets bytes at a given offset, growing or shrinking as needed. The bytes
// set must be within a single 32 byte chunk.
[[nodiscard]] Buffer set_many(uint64_t offset,
std::vector<uint8_t> arr) const;
const std::vector<uint8_t>& arr) const;

// Gets the byte at a given offset
[[nodiscard]] uint8_t get(uint64_t pos) const;
Expand Down Expand Up @@ -150,7 +150,7 @@ class RawBuffer {
// Sets bytes at a given offset, growing or shrinking as needed. The bytes
// set must be within a single 32 byte chunk.
[[nodiscard]] RawBuffer set_many(uint64_t offset,
std::vector<uint8_t> arr) const;
const std::vector<uint8_t>& arr) const;

// Creates a buffer representing the given bytes
static RawBuffer fromData(const std::vector<uint8_t>& data);
Expand Down
14 changes: 9 additions & 5 deletions packages/arb-avm-cpp/avm_values/src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const std::vector<Buffer> zero_buffers_of_depth = []() -> std::vector<Buffer> {
RawBuffer::RawBuffer(LeafData bytes) : depth(0), components(bytes) {}

RawBuffer::RawBuffer(Buffer left, Buffer right)
: depth(left->depth + 1), components(std::make_pair(left, right)) {
: depth(left->depth + 1),
components(std::make_pair(std::move(left), std::move(right))) {
auto children = get_children_const();
if (children->first->depth != children->second->depth) {
throw new std::runtime_error("Attempted to create uneven buffer");
Expand Down Expand Up @@ -238,7 +239,8 @@ uint256_t Buffer::data_length() const {
return (*this)->packed_size();
}

RawBuffer RawBuffer::set_many(uint64_t offset, std::vector<uint8_t> arr) const {
RawBuffer RawBuffer::set_many(uint64_t offset,
const std::vector<uint8_t>& arr) const {
RawBuffer ret(*this);
if (uint256_t(offset) + arr.size() > ret.size()) {
ret = ret.grow(needed_depth(uint256_t(offset) + arr.size()));
Expand Down Expand Up @@ -393,14 +395,15 @@ std::vector<Buffer> Buffer::serialize(
}

Buffer::Buffer(RawBuffer raw)
: std::shared_ptr<RawBuffer>(std::make_shared<RawBuffer>(raw)) {}
: std::shared_ptr<RawBuffer>(std::make_shared<RawBuffer>(std::move(raw))) {}

Buffer::Buffer() : Buffer(RawBuffer()) {}

Buffer::Buffer(std::array<unsigned char, 32> bytes)
: Buffer(RawBuffer(bytes)) {}

Buffer::Buffer(Buffer left, Buffer right) : Buffer(RawBuffer(left, right)) {}
Buffer::Buffer(Buffer left, Buffer right)
: Buffer(RawBuffer(std::move(left), std::move(right))) {}

Buffer Buffer::fromData(const std::vector<uint8_t>& data) {
return Buffer(RawBuffer::fromData(data));
Expand All @@ -410,6 +413,7 @@ uint256_t Buffer::hash() const {
return (*this)->hash();
}

Buffer Buffer::set_many(uint64_t offset, std::vector<uint8_t> arr) const {
Buffer Buffer::set_many(uint64_t offset,
const std::vector<uint8_t>& arr) const {
return Buffer((*this)->set_many(offset, arr));
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
CoreValueLoader::CoreValueLoader(std::shared_ptr<DataStorage> data_storage_,
std::shared_ptr<CoreCode> core_code_,
ValueCache cache_)
: data_storage(data_storage_), core_code(core_code_), cache(cache_) {}
: data_storage(std::move(data_storage_)),
core_code(std::move(core_code_)),
cache(std::move(cache_)) {}

value CoreValueLoader::loadValue(const uint256_t& hash) {
ReadTransaction tx(data_storage);
Expand Down

0 comments on commit 417f528

Please sign in to comment.