Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions lib/base/configobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class ModAttrValidationUtils final : public ValidationUtils
void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool updateVersion)
{
Dictionary::Ptr original_attributes = GetOriginalAttributes();
std::vector<std::pair<String, Value>> orig_attr_updates;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this declaration can be moved a little closer to where it's used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also using snake_case as a variable name in 2026 :).

bool updated_original_attributes = false;

Type::Ptr type = GetReflectionType();
Expand Down Expand Up @@ -161,46 +162,45 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
oldValue = dict->Get(key).Clone();

if (field.Attributes & FAConfig) {
updated_original_attributes = true;

if (oldValue.IsObjectType<Dictionary>()) {
Dictionary::Ptr oldDict = oldValue;
ObjectLock olock(oldDict);
for (const auto& kv : oldDict) {
String key = prefix + "." + kv.first;
if (!original_attributes->Contains(key))
original_attributes->Set(key, kv.second);
orig_attr_updates.emplace_back(prefix + "." + kv.first, kv.second);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe std::move(kv.second) here and std::move(oldValue) in the two cases below. Probably doesn't matter much unless the Value contains a really big string, but still...

}

/* store the new value as null */
if (value.IsObjectType<Dictionary>()) {
Dictionary::Ptr valueDict = value;
ObjectLock olock(valueDict);
for (const auto& kv : valueDict) {
String key = attr + "." + kv.first;
if (!original_attributes->Contains(key))
original_attributes->Set(key, Empty);
orig_attr_updates.emplace_back(attr + "." + kv.first, Empty);
}
}
} else if (!original_attributes->Contains(attr))
original_attributes->Set(attr, oldValue);
} else {
orig_attr_updates.emplace_back(attr, oldValue);
}
}

dict->Set(key, value);
} else {
newValue = value;

if (field.Attributes & FAConfig) {
if (!original_attributes->Contains(attr)) {
updated_original_attributes = true;
original_attributes->Set(attr, oldValue);
}
orig_attr_updates.emplace_back(attr, oldValue);
}
}

ModAttrValidationUtils utils;
ValidateField(fid, Lazy<Value>{newValue}, utils);

for (auto &[key, val] : orig_attr_updates) {
if (!original_attributes->Contains(key)) {
updated_original_attributes = true;
original_attributes->Set(key, std::move(val));
}
}

SetField(fid, newValue);

if (updateVersion && (field.Attributes & FAConfig))
Expand Down
Loading