Skip to content

Commit

Permalink
Replace push_back with emplace_back where it makes sense
Browse files Browse the repository at this point in the history
  • Loading branch information
Marenz committed Dec 10, 2018
1 parent 871ea22 commit 2f6dc2e
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 75 deletions.
2 changes: 1 addition & 1 deletion libdevcore/IndentedWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ string IndentedWriter::format() const
void IndentedWriter::newLine()
{
if (!m_lines.back().contents.empty())
m_lines.push_back({ string(), m_lines.back().indentation });
m_lines.emplace_back(Line{string(), m_lines.back().indentation});
}

void IndentedWriter::indent()
Expand Down
2 changes: 1 addition & 1 deletion libdevcore/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ string dev::quotedAlternativesList(vector<string> const& suggestions)
vector<string> quotedSuggestions;

for (auto& suggestion: suggestions)
quotedSuggestions.push_back("\"" + suggestion + "\"");
quotedSuggestions.emplace_back("\"" + suggestion + "\"");

return joinHumanReadable(quotedSuggestions, ", ", " or ");
}
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ AssemblyItem const& Assembly::append(AssemblyItem const& _i)
{
assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
m_deposit += _i.deposit();
m_items.push_back(_i);
m_items.emplace_back(_i);
if (m_items.back().location().isEmpty() && !m_currentSourceLocation.isEmpty())
m_items.back().setLocation(m_currentSourceLocation);
return back();
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/ControlFlowGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void ControlFlowGraph::splitBlocks()
m_blocks[id].begin = index;
}
if (item.type() == PushTag)
m_blocks[id].pushedTags.push_back(BlockId(item.data()));
m_blocks[id].pushedTags.emplace_back(item.data());
if (SemanticInformation::altersControlFlow(item))
{
m_blocks[id].end = index + 1;
Expand Down
2 changes: 1 addition & 1 deletion libevmasm/SimplificationRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ExpressionTemplate::ExpressionTemplate(Pattern const& _pattern, SourceLocation c
item = _pattern.toAssemblyItem(_location);
}
for (auto const& arg: _pattern.arguments())
arguments.push_back(ExpressionTemplate(arg, _location));
arguments.emplace_back(arg, _location);
}

string ExpressionTemplate::toString() const
Expand Down
2 changes: 1 addition & 1 deletion liblangutil/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SecondarySourceLocation
public:
SecondarySourceLocation& append(std::string const& _errMsg, SourceLocation const& _sourceLocation)
{
infos.push_back(std::make_pair(_errMsg, _sourceLocation));
infos.emplace_back(_errMsg, _sourceLocation);
return *this;
}

Expand Down
6 changes: 3 additions & 3 deletions liblll/CodeFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
if (j.tag() || j.which() != sp::utree_type::symbol_type)
error<InvalidMacroArgs>();
auto sr = j.get<sp::basic_string<boost::iterator_range<char const*>, sp::utree_type::symbol_type>>();
args.push_back(string(sr.begin(), sr.end()));
args.emplace_back(sr.begin(), sr.end());
}
else if (ii == 3)
{
Expand Down Expand Up @@ -464,9 +464,9 @@ void CodeFragment::constructOperation(sp::utree const& _t, CompilerState& _s)
if (c++)
{
if (us == "LLL" && c == 1)
code.push_back(CodeFragment(i, ns, m_readFile));
code.emplace_back(i, ns, m_readFile);
else
code.push_back(CodeFragment(i, _s, m_readFile));
code.emplace_back(i, _s, m_readFile);
}
auto requireSize = [&](unsigned s) { if (code.size() != s) error<IncorrectParameterCount>(us); };
auto requireMinSize = [&](unsigned s) { if (code.size() < s) error<IncorrectParameterCount>(us); };
Expand Down
20 changes: 10 additions & 10 deletions liblll/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ bytes dev::lll::compileLLL(string const& _src, dev::solidity::EVMVersion _evmVer
{
if (_errors)
{
_errors->push_back("Parse error.");
_errors->push_back(boost::diagnostic_information(_e));
_errors->emplace_back("Parse error.");
_errors->emplace_back(boost::diagnostic_information(_e));
}
}
catch (std::exception const& _e)
{
if (_errors)
{
_errors->push_back("Parse exception.");
_errors->push_back(boost::diagnostic_information(_e));
_errors->emplace_back("Parse exception.");
_errors->emplace_back(boost::diagnostic_information(_e));
}
}
catch (...)
{
if (_errors)
_errors->push_back("Internal compiler exception.");
_errors->emplace_back("Internal compiler exception.");
}
return bytes();
}
Expand All @@ -84,22 +84,22 @@ std::string dev::lll::compileLLLToAsm(std::string const& _src, EVMVersion _evmVe
{
if (_errors)
{
_errors->push_back("Parse error.");
_errors->push_back(boost::diagnostic_information(_e));
_errors->emplace_back("Parse error.");
_errors->emplace_back(boost::diagnostic_information(_e));
}
}
catch (std::exception const& _e)
{
if (_errors)
{
_errors->push_back("Parse exception.");
_errors->push_back(boost::diagnostic_information(_e));
_errors->emplace_back("Parse exception.");
_errors->emplace_back(boost::diagnostic_information(_e));
}
}
catch (...)
{
if (_errors)
_errors->push_back("Internal compiler exception.");
_errors->emplace_back("Internal compiler exception.");
}
return string();
}
Expand Down
10 changes: 5 additions & 5 deletions libsolidity/analysis/ContractLevelChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void ContractLevelChecker::checkAbstractFunctions(ContractDefinition const& _con
return _type->hasEqualParameterTypes(*_funAndFlag.first);
});
if (it == overloads.end())
overloads.push_back(make_pair(_type, _implemented));
overloads.emplace_back(_type, _implemented);
else if (it->second)
{
if (!_implemented)
Expand Down Expand Up @@ -409,8 +409,8 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
auto functionType = make_shared<FunctionType>(*f);
// under non error circumstances this should be true
if (functionType->interfaceFunctionType())
externalDeclarations[functionType->externalSignature()].push_back(
make_pair(f, functionType->asCallableFunction(false))
externalDeclarations[functionType->externalSignature()].emplace_back(
f, functionType->asCallableFunction(false)
);
}
for (VariableDeclaration const* v: contract->stateVariables())
Expand All @@ -419,8 +419,8 @@ void ContractLevelChecker::checkExternalTypeClashes(ContractDefinition const& _c
auto functionType = make_shared<FunctionType>(*v);
// under non error circumstances this should be true
if (functionType->interfaceFunctionType())
externalDeclarations[functionType->externalSignature()].push_back(
make_pair(v, functionType->asCallableFunction(false))
externalDeclarations[functionType->externalSignature()].emplace_back(
v, functionType->asCallableFunction(false)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/AST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::inter
{
signaturesSeen.insert(functionSignature);
FixedHash<4> hash(dev::keccak256(functionSignature));
m_interfaceFunctionList->push_back(make_pair(hash, fun));
m_interfaceFunctionList->emplace_back(hash, fun);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions libsolidity/ast/ASTJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ bool ASTJsonConverter::visit(ImportDirective const& _node)
make_pair(m_legacy ? "SourceUnit" : "sourceUnit", nodeId(*_node.annotation().sourceUnit)),
make_pair("scope", idOrNull(_node.scope()))
};
attributes.push_back(make_pair("unitAlias", _node.name()));
attributes.emplace_back("unitAlias", _node.name());
Json::Value symbolAliases(Json::arrayValue);
for (auto const& symbolAlias: _node.symbolAliases())
{
Expand All @@ -244,7 +244,7 @@ bool ASTJsonConverter::visit(ImportDirective const& _node)
tuple["local"] = symbolAlias.second ? Json::Value(*symbolAlias.second) : Json::nullValue;
symbolAliases.append(tuple);
}
attributes.push_back(make_pair("symbolAliases", std::move(symbolAliases)));
attributes.emplace_back("symbolAliases", std::move(symbolAliases));
setJsonNode(_node, "ImportDirective", std::move(attributes));
return false;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ bool ASTJsonConverter::visit(VariableDeclaration const& _node)
make_pair("typeDescriptions", typePointerToJson(_node.annotation().type, true))
};
if (m_inEvent)
attributes.push_back(make_pair("indexed", _node.isIndexed()));
attributes.emplace_back("indexed", _node.isIndexed());
setJsonNode(_node, "VariableDeclaration", std::move(attributes));
return false;
}
Expand Down Expand Up @@ -647,11 +647,11 @@ bool ASTJsonConverter::visit(FunctionCall const& _node)
};
if (m_legacy)
{
attributes.push_back(make_pair("isStructConstructorCall", _node.annotation().kind == FunctionCallKind::StructConstructorCall));
attributes.push_back(make_pair("type_conversion", _node.annotation().kind == FunctionCallKind::TypeConversion));
attributes.emplace_back("isStructConstructorCall", _node.annotation().kind == FunctionCallKind::StructConstructorCall);
attributes.emplace_back("type_conversion", _node.annotation().kind == FunctionCallKind::TypeConversion);
}
else
attributes.push_back(make_pair("kind", functionCallKind(_node.annotation().kind)));
attributes.emplace_back("kind", functionCallKind(_node.annotation().kind));
appendExpressionAttributes(attributes, _node.annotation());
setJsonNode(_node, "FunctionCall", std::move(attributes));
return false;
Expand Down
Loading

0 comments on commit 2f6dc2e

Please sign in to comment.