Merge pull request #8914 from random-internet-cat/down-with-unique-ptr

Down with unique_ptr!
This commit is contained in:
chriseth 2020-05-20 13:22:06 +02:00 committed by GitHub
commit 84092edc5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 9 deletions

View File

@ -582,9 +582,9 @@ string const* CompilerStack::sourceMapping(string const& _contractName) const
if (!c.sourceMapping)
{
if (auto items = assemblyItems(_contractName))
c.sourceMapping = make_unique<string>(evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices()));
c.sourceMapping.emplace(evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices()));
}
return c.sourceMapping.get();
return c.sourceMapping ? &*c.sourceMapping : nullptr;
}
string const* CompilerStack::runtimeSourceMapping(string const& _contractName) const
@ -596,11 +596,11 @@ string const* CompilerStack::runtimeSourceMapping(string const& _contractName) c
if (!c.runtimeSourceMapping)
{
if (auto items = runtimeAssemblyItems(_contractName))
c.runtimeSourceMapping = make_unique<string>(
c.runtimeSourceMapping.emplace(
evmasm::AssemblyItem::computeSourceMapping(*items, sourceIndices())
);
}
return c.runtimeSourceMapping.get();
return c.runtimeSourceMapping ? &*c.runtimeSourceMapping : nullptr;
}
std::string const CompilerStack::filesystemFriendlyName(string const& _contractName) const

View File

@ -348,8 +348,8 @@ private:
util::LazyInit<Json::Value const> storageLayout;
util::LazyInit<Json::Value const> userDocumentation;
util::LazyInit<Json::Value const> devDocumentation;
mutable std::unique_ptr<std::string const> sourceMapping;
mutable std::unique_ptr<std::string const> runtimeSourceMapping;
mutable std::optional<std::string const> sourceMapping;
mutable std::optional<std::string const> runtimeSourceMapping;
};
/// Loads the missing sources from @a _ast (named @a _path) using the callback

View File

@ -25,6 +25,7 @@
#include <vector>
#include <map>
#include <memory>
#include <optional>
namespace solidity::yul::wasm
{
@ -76,7 +77,7 @@ struct FunctionImport {
std::string externalName;
std::string internalName;
std::vector<std::string> paramTypes;
std::unique_ptr<std::string> returnType;
std::optional<std::string> returnType;
};
struct FunctionDefinition

View File

@ -29,6 +29,8 @@
#include <liblangutil/Exceptions.h>
#include <optional>
using namespace std;
using namespace solidity;
using namespace solidity::yul;
@ -125,7 +127,7 @@ wasm::Expression WasmCodeTransform::operator()(FunctionCall const& _call)
builtin->name.str().substr(4),
builtin->name.str(),
{},
builtin->returns.empty() ? nullptr : make_unique<string>(builtin->returns.front().str())
builtin->returns.empty() ? nullopt : make_optional<string>(builtin->returns.front().str())
};
for (auto const& param: builtin->parameters)
imp.paramTypes.emplace_back(param.str());

View File

@ -89,7 +89,10 @@ int registerTests(
}
else
{
static vector<unique_ptr<string>> filenames;
// This must be a vector of unique_ptrs because Boost.Test keeps the equivalent of a string_view to the filename
// that is passed in. If the strings were stored directly in the vector, pointers/references to them would be
// invalidated on reallocation.
static vector<unique_ptr<string const>> filenames;
filenames.emplace_back(make_unique<string>(_path.string()));
_suite.add(make_test_case(