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

Commit

Permalink
Merge pull request #6501 from EOSIO/feature/port-assign-change
Browse files Browse the repository at this point in the history
optimization when writing shared_blob data
  • Loading branch information
b1bart authored Dec 18, 2018
2 parents d0ebb3c + d02741c commit f3ec23a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
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
17 changes: 16 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,22 @@ 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;
}

shared_blob& operator=(shared_blob&& ) = default;

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

0 comments on commit f3ec23a

Please sign in to comment.