seanchas116 / qtimgui

Qt (QOpenGLWidget / QOpenGLWindow) backend for ImGui
MIT License
370 stars 95 forks source link

Minor optimization - utilized double keyMap lookup #31

Closed inobelar closed 3 years ago

inobelar commented 3 years ago

Original code contains double QHash search for a key (code below decomposed from original - for readability):

if (keyMap.contains( event->key() )) // QHash::contains() do the search of value-by-key
{
    const int  key = keyMap[ event->key() ]; // QHash::operator[] do the search of value-by-key again
    const bool key_pressed = (event->type() == QEvent::KeyPress);
    io.KeysDown[key] = key_pressed;
}

This is minor (possibly, due to small keyMap size, performance-irrelevant) issue, fixed in kinda 'less-readable way' (due to iterators usage), only for a next reason: to not worry about such place :smile: