diff options
author | chriseth <chris@ethereum.org> | 2018-12-19 01:23:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-19 01:23:27 +0800 |
commit | f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d (patch) | |
tree | 90b947fbfd14ede59c3f98c2f3fabc8c4c632035 /libsolidity/interface/CompilerStack.cpp | |
parent | 34be592e533ad72087a3a32d2466404e6ca0d442 (diff) | |
parent | bd52beedfff7196070880abbd396f5c7469314d0 (diff) | |
download | dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar.gz dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar.bz2 dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar.lz dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar.xz dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.tar.zst dexon-solidity-f5e52ef3c00fe1e988ca7071f7d6b03ab349ff4d.zip |
Merge pull request #5679 from ethereum/hashCache
Cache hash computations.
Diffstat (limited to 'libsolidity/interface/CompilerStack.cpp')
-rw-r--r-- | libsolidity/interface/CompilerStack.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 625a665d..adfb94bd 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -619,6 +619,22 @@ tuple<int, int, int, int> CompilerStack::positionFromSourceLocation(SourceLocati return make_tuple(++startLine, ++startColumn, ++endLine, ++endColumn); } + +h256 const& CompilerStack::Source::keccak256() const +{ + if (keccak256HashCached == h256{}) + keccak256HashCached = dev::keccak256(scanner->source()); + return keccak256HashCached; +} + +h256 const& CompilerStack::Source::swarmHash() const +{ + if (swarmHashCached == h256{}) + swarmHashCached = dev::swarmHash(scanner->source()); + return swarmHashCached; +} + + StringMap CompilerStack::loadMissingSources(SourceUnit const& _ast, std::string const& _sourcePath) { solAssert(m_stackState < ParsingSuccessful, ""); @@ -860,16 +876,13 @@ string CompilerStack::createMetadata(Contract const& _contract) const continue; solAssert(s.second.scanner, "Scanner not available"); - meta["sources"][s.first]["keccak256"] = - "0x" + toHex(dev::keccak256(s.second.scanner->source()).asBytes()); + meta["sources"][s.first]["keccak256"] = "0x" + toHex(s.second.keccak256().asBytes()); if (m_metadataLiteralSources) meta["sources"][s.first]["content"] = s.second.scanner->source(); else { meta["sources"][s.first]["urls"] = Json::arrayValue; - meta["sources"][s.first]["urls"].append( - "bzzr://" + toHex(dev::swarmHash(s.second.scanner->source()).asBytes()) - ); + meta["sources"][s.first]["urls"].append("bzzr://" + toHex(s.second.swarmHash().asBytes())); } } meta["settings"]["optimizer"]["enabled"] = m_optimize; @@ -896,7 +909,7 @@ string CompilerStack::createMetadata(Contract const& _contract) const return jsonCompactPrint(meta); } -bytes CompilerStack::createCBORMetadata(string _metadata, bool _experimentalMode) +bytes CompilerStack::createCBORMetadata(string const& _metadata, bool _experimentalMode) { bytes cborEncodedHash = // CBOR-encoding of the key "bzzr0" |