Avoid array copy
This commit is contained in:
parent
1bda001b8c
commit
ed7eefec67
1 changed files with 7 additions and 6 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
#include <fc/optional.hpp>
|
#include <fc/optional.hpp>
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
#include <fc/container/flat_fwd.hpp>
|
#include <fc/container/flat_fwd.hpp>
|
||||||
|
#include <fc/crypto/hex.hpp>
|
||||||
#include <boost/endian/buffers.hpp>
|
#include <boost/endian/buffers.hpp>
|
||||||
#include <boost/multi_index_container_fwd.hpp>
|
#include <boost/multi_index_container_fwd.hpp>
|
||||||
|
|
||||||
|
|
@ -663,14 +664,14 @@ namespace fc
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void to_variant( const std::array<char,N>& bi, variant& v, uint32_t max_depth = 1 )
|
void to_variant( const std::array<char,N>& bi, variant& v, uint32_t max_depth = 1 )
|
||||||
{
|
{
|
||||||
to_variant( std::vector<char>( bi.begin(), bi.end() ), v, 1 );
|
v = variant( to_hex( bi.data(), N ) );
|
||||||
}
|
}
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void from_variant( const variant& v, std::array<char,N>& bi, uint32_t max_depth = 1 )
|
void from_variant( const variant& v, std::array<char,N>& bi, uint32_t max_depth = 1 )
|
||||||
{
|
{
|
||||||
std::vector<char> ve = v.as< std::vector<char> >( 1 );
|
std::string ve = v.as_string();
|
||||||
if( ve.size() )
|
if( ve.size() )
|
||||||
memcpy( bi.data(), ve.data(), std::min<size_t>( ve.size(), bi.size() ) );
|
from_hex( ve, bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
|
||||||
else
|
else
|
||||||
memset( bi.data(), 0, bi.size() );
|
memset( bi.data(), 0, bi.size() );
|
||||||
}
|
}
|
||||||
|
|
@ -678,14 +679,14 @@ namespace fc
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void to_variant( const std::array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
|
void to_variant( const std::array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
|
||||||
{
|
{
|
||||||
to_variant( std::vector<char>( bi.begin(), bi.end() ), v, 1 );
|
v = variant( to_hex( (char*) bi.data(), N ) );
|
||||||
}
|
}
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
void from_variant( const variant& v, std::array<unsigned char,N>& bi, uint32_t max_depth = 1 )
|
void from_variant( const variant& v, std::array<unsigned char,N>& bi, uint32_t max_depth = 1 )
|
||||||
{
|
{
|
||||||
std::vector<char> ve = v.as< std::vector<char> >( 1 );
|
std::string ve = v.as_string();
|
||||||
if( ve.size() )
|
if( ve.size() )
|
||||||
memcpy( bi.data(), ve.data(), std::min<size_t>( ve.size(), bi.size() ) );
|
from_hex( ve, (char*)bi.data(), std::min<size_t>( ve.size() / 2, bi.size() ) );
|
||||||
else
|
else
|
||||||
memset( bi.data(), 0, bi.size() );
|
memset( bi.data(), 0, bi.size() );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue