Skip to content
Browse files

small optim in CGUIControlGroup::GetFocusedControl() to avoid double …

…control group tree traversing
  • Loading branch information...
1 parent 83ff758 commit f472ae7bb6681fc6effb585b67f76ec882c4f868 @pieh pieh committed Jul 19, 2012
Showing with 9 additions and 7 deletions.
  1. +9 −7 xbmc/guilib/GUIControlGroup.cpp
View
16 xbmc/guilib/GUIControlGroup.cpp
@@ -480,15 +480,17 @@ CGUIControl *CGUIControlGroup::GetFocusedControl() const
for (ciControls it = m_children.begin(); it != m_children.end(); ++it)
{
const CGUIControl* control = *it;
- if (control->HasFocus())
+ // Avoid calling HasFocus() on control group as it will (possibly) recursively
+ // traverse entire group tree just to check if there is focused control.
+ // We are recursively traversing it here so no point in doing it twice.
+ if (control->IsGroup())
{
- if (control->IsGroup())
- {
- CGUIControlGroup *group = (CGUIControlGroup *)control;
- return group->GetFocusedControl();
- }
- return (CGUIControl *)control;
+ CGUIControl* focusedControl = ((CGUIControlGroup *)control)->GetFocusedControl();
+ if (focusedControl)
+ return (CGUIControl *)focusedControl;
}
+ else if (control->HasFocus())
+ return (CGUIControl *)control;
}
return NULL;
}

0 comments on commit f472ae7

Please sign in to comment.
Something went wrong with that request. Please try again.