Remove unneeded heap allocation in AnchoredSetVariable::set

This commit is contained in:
Martin Vierula 2023-10-25 06:07:26 -07:00
parent dc6cce5f0c
commit fd67c6eb1d
No known key found for this signature in database
GPG Key ID: F2FC4E45883BCBA4

View File

@ -53,9 +53,7 @@ void AnchoredSetVariable::unset() {
void AnchoredSetVariable::set(const std::string &key,
const std::string &value, size_t offset, size_t len) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
std::string *v = new std::string(value);
VariableValue *var = new VariableValue(&m_name, &key, v);
delete v;
VariableValue *var = new VariableValue(&m_name, &key, &value);
origin->m_offset = offset;
origin->m_length = len;
@ -68,9 +66,7 @@ void AnchoredSetVariable::set(const std::string &key,
void AnchoredSetVariable::set(const std::string &key,
const std::string &value, size_t offset) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
std::string *v = new std::string(value);
VariableValue *var = new VariableValue(&m_name, &key, v);
delete v;
VariableValue *var = new VariableValue(&m_name, &key, &value);
origin->m_offset = offset;
origin->m_length = value.size();