XorTroll / Plutonium

An easy-to-use UI framework for Nintendo Switch homebrew
https://xortroll.github.io/Plutonium/
MIT License
272 stars 40 forks source link

Iterating Map #18

Open 3096 opened 5 years ago

3096 commented 5 years ago

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

For this example: https://github.com/XorTroll/Plutonium/blob/0fefac2455683f2e98bb7091c5891ebb222a8683/Plutonium/Source/pu/ui/render/render_SDL2.cpp#L35-L38 Consider something like:

auto foundItr = shfonts.find(Size);
if (foundItr != shfonts.end() && foundItr->first == Type) return foundItr->second;
3096 commented 5 years ago

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

3096 commented 5 years ago

Same applies to arrays like: https://github.com/XorTroll/Plutonium/blob/0fefac2455683f2e98bb7091c5891ebb222a8683/Plutonium/Source/pu/ui/elm/elm_Menu.cpp#L411-L415 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?)