diff options
Diffstat (limited to 'libdevcore')
-rw-r--r-- | libdevcore/JSON.h | 4 | ||||
-rw-r--r-- | libdevcore/SwarmHash.cpp | 12 | ||||
-rw-r--r-- | libdevcore/SwarmHash.h | 5 |
3 files changed, 12 insertions, 9 deletions
diff --git a/libdevcore/JSON.h b/libdevcore/JSON.h index 7876dfb2..0d6e0d2e 100644 --- a/libdevcore/JSON.h +++ b/libdevcore/JSON.h @@ -28,13 +28,13 @@ namespace dev { /// Serialise the JSON object (@a _input) with identation -std::string jsonPrettyPrint(Json::Value const& _input) +inline std::string jsonPrettyPrint(Json::Value const& _input) { return Json::StyledWriter().write(_input); } /// Serialise theJ SON object (@a _input) without identation -std::string jsonCompactPrint(Json::Value const& _input) +inline std::string jsonCompactPrint(Json::Value const& _input) { Json::FastWriter writer; writer.omitEndingLineFeed(); diff --git a/libdevcore/SwarmHash.cpp b/libdevcore/SwarmHash.cpp index e7b844eb..aa98eafd 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -38,13 +38,14 @@ h256 swarmHashSimple(bytesConstRef _data, size_t _size) return keccak256(toLittleEndian(_size) + _data.toBytes()); } -h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length) +h256 swarmHashIntermediate(string const& _input, size_t _offset, size_t _length) { + bytesConstRef ref; + bytes innerNodes; if (_length <= 0x1000) - return swarmHashSimple(bytesConstRef(_input.data() + _offset, _length), _length); + ref = bytesConstRef(_input).cropped(_offset, _length); else { - bytes innerNodes; size_t maxRepresentedSize = 0x1000; while (maxRepresentedSize * (0x1000 / 32) < _length) maxRepresentedSize *= (0x1000 / 32); @@ -53,11 +54,12 @@ h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length) size_t size = std::min(maxRepresentedSize, _length - i); innerNodes += swarmHashIntermediate(_input, _offset + i, size).asBytes(); } - return swarmHashSimple(bytesConstRef(&innerNodes), _length); + ref = bytesConstRef(&innerNodes); } + return swarmHashSimple(ref, _length); } -h256 dev::swarmHash(bytes const& _input) +h256 dev::swarmHash(string const& _input) { return swarmHashIntermediate(_input, 0, _input.size()); } diff --git a/libdevcore/SwarmHash.h b/libdevcore/SwarmHash.h index 925509ab..f474ce11 100644 --- a/libdevcore/SwarmHash.h +++ b/libdevcore/SwarmHash.h @@ -20,12 +20,13 @@ #pragma once #include <libdevcore/FixedHash.h> -#include <libdevcore/Common.h> + +#include <string> namespace dev { /// Compute the "swarm hash" of @a _data -h256 swarmHash(bytes const& _data); +h256 swarmHash(std::string const& _data); } |