Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterating Map #18

Open
3096 opened this issue Aug 14, 2019 · 2 comments
Open

Iterating Map #18

3096 opened this issue Aug 14, 2019 · 2 comments

Comments

@3096
Copy link

3096 commented Aug 14, 2019

Iterating maps is unnecessary and a loss of performance, especially if a map size gets large.

For this example:

for(auto font: shfonts)
{
if((font.first == Size) && (font.second.first == Type)) return font.second.second;
}

Consider something like:

auto foundItr = shfonts.find(Size);
if (foundItr != shfonts.end() && foundItr->first == Type) return foundItr->second;
@3096
Copy link
Author

3096 commented Aug 14, 2019

Unordered map can be used for constant time access, and even ordered map is logarithmic time.

@3096
Copy link
Author

3096 commented Aug 15, 2019

Same applies to arrays like:

if(!this->itms.empty()) for(s32 i = 0; i < this->itms.size(); i++)
{
if(i == this->isel) this->selfact = 0;
else if(i == this->previsel) this->pselfact = 255;
}

This code is essentially checking if this->isel and this->previsel (whatever those are) are in range of 0 to itms.size(), no need to iterate. (It also should always be in range?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant