Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

optimization when writing shared_blob data #6501

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,8 @@ int apply_context::db_store_i64( uint64_t code, uint64_t scope, uint64_t table,
const auto& obj = db.create<key_value_object>( [&]( auto& o ) {
o.t_id = tableid;
o.primary_key = id;
o.value.resize( buffer_size );
o.value.assign( buffer, buffer_size );
o.payer = payer;
memcpy( o.value.data(), buffer, buffer_size );
});

db.modify( tab, [&]( auto& t ) {
Expand Down Expand Up @@ -562,8 +561,7 @@ void apply_context::db_update_i64( int iterator, account_name payer, const char*
}

db.modify( obj, [&]( auto& o ) {
o.value.resize( buffer_size );
memcpy( o.value.data(), buffer, buffer_size );
o.value.assign( buffer, buffer_size );
o.payer = payer;
});
}
Expand Down
17 changes: 10 additions & 7 deletions libraries/chain/eosio_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ void apply_eosio_setcode(apply_context& context) {
// TODO: update setcode message to include the hash, then validate it in validate
a.last_code_update = context.control.pending_block_time();
a.code_version = code_id;
a.code.resize( code_size );
if( code_size > 0 )
memcpy( a.code.data(), act.code.data(), code_size );

if ( code_size > 0 ) {
a.code.assign(act.code.data(), code_size);
} else {
a.code.resize(0);
}
});

const auto& account_sequence = db.get<account_sequence_object, by_name>(act.account);
Expand All @@ -185,9 +186,11 @@ void apply_eosio_setabi(apply_context& context) {
int64_t new_size = abi_size;

db.modify( account, [&]( auto& a ) {
a.abi.resize( abi_size );
if( abi_size > 0 )
memcpy( a.abi.data(), act.abi.data(), abi_size );
if (abi_size > 0) {
a.abi.assign(act.abi.data(), abi_size);
} else {
a.abi.resize(0);
}
});

const auto& account_sequence = db.get<account_sequence_object, by_name>(act.account);
Expand Down
14 changes: 13 additions & 1 deletion libraries/chain/include/eosio/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ namespace eosio { namespace chain {
*/
class shared_blob : public shared_string {
public:
shared_blob() = default;
shared_blob() = delete;
shared_blob(shared_blob&&) = default;

shared_blob(const shared_blob& s)
:shared_string(s.get_allocator())
{
assign(s.c_str(), s.size());
}

shared_blob &operator=(const shared_blob &s) {
assign(s.c_str(), s.size());
return *this;
}

template <typename InputIterator>
shared_blob(InputIterator f, InputIterator l, const allocator_type& a)
Expand Down