Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
22 changes: 13 additions & 9 deletions Server/mods/deathmatch/logic/luadefs/CLuaResourceDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1476,24 +1476,28 @@ bool CLuaResourceDefs::isResourceProtected(CResource* const resource)
std::vector<std::string> CLuaResourceDefs::GetResourceFiles(lua_State* luaVM, std::optional<CResourceFile::eResourceCategory> type,
std::optional<CResource*> resource) noexcept
{
using eResourceCategory = CResourceFile::eResourceCategory;

if (!type)
type = CResourceFile::eResourceCategory::ALL;
type = eResourceCategory::ALL;

if (!resource)
resource = &lua_getownerresource(luaVM);

const auto resourceFiles = (*resource)->GetResourceFiles();

std::vector<std::string> files;
files.reserve(resourceFiles.size());
std::unordered_set<std::string> files;
for (const auto& file : resourceFiles)
{
if (file->GetResourceCategoryType() == type.value()
|| type.value() == CResourceFile::eResourceCategory::ALL)
{
files.push_back(file->GetName());
}
if (file->GetResourceCategoryType() != type.value() && type.value() != eResourceCategory::ALL)
continue;
files.insert(file->GetName());
Comment on lines +1492 to +1494
Copy link
Member

Choose a reason for hiding this comment

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

Previous varian was more readable. Why did you change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

previous variant was basically the same.
This leaves room for more conditions to come.

Copy link
Member

Choose a reason for hiding this comment

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

There is no 'early continue' rule. You obfuscate the code with overusing 'continue' in loops. And you don't really need to use early return for small code blocks.
You did the code less readable and maintainable.

if (file->GetResourceCategoryType() == type.value() || type.value() == eResourceCategory::ALL)
    files.insert(file->GetName());

Is fine condition, that describes the function logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is early-return which is basically the same but whatever.
I'd rather go with continue rather than indentation

Copy link
Member

Choose a reason for hiding this comment

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

Your continue creates indentation too. Please, keep it simple

There is early-return which is basically the same but whatever.

Not really. Multiple 'continue' conditions can make a loop harder for reading.
There is no goal to use minimal indentation. The code should primarily describe the logic.
You're overusing 'early return'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again?

No one was interested in this convo for 2 weeks, give it a break.
No contributors were opposed against this so Im leaving it as it is.

Copy link
Member

Choose a reason for hiding this comment

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

I also see the early return overuse here.

Copy link
Member

Choose a reason for hiding this comment

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

No contributors were opposed against this so Im leaving it as it is.

And nobody confirm your position. Don't hide requested changes. Stale conversations should be dismissed by another members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And nobody confirm your position

Im following the guidelines is'all.

Copy link
Member

Choose a reason for hiding this comment

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

you interpreter these guidelines very differently

}

return files;
// TODO: Upgrade ArgumentParser so it would accept
// std::set and std::unordered_set as return values
return std::vector<std::string>(
std::make_move_iterator(files.begin()),
std::make_move_iterator(files.end())
);
}