Simple change for better performance of GUI rendering. (1 Viewer)

ojo

Portal Member
September 19, 2004
47
1
Ulstrup, Denmark
I hope this comes in handy. I've looked at the source and found a small change that could spare a couple of CPU cycles....

Suggested change to Core\guilib\GUIWindow.cs

Code:
public virtual GUIControl GetControl(int iControlId) 
{
  for (int x = 0; x < m_vecControls.Count; ++x)
  {
    GUIControl cntl = (GUIControl)m_vecControls[x];
    
    // old code
    // GUIControl cntlFound =  cntl.GetControlById( iControlId  );
    // if (cntlFound!=null) return cntlFound;

    // new code
    if (iControlId == cntl.GetID) return cntl;
  }

  return null;
}

Should help generel GUI rendering since no new object is assigned and transferred.
It's just a simple property-lookup. As far as i can tell (and test) the code performs the exact same functionality only slightly faster...

The best solution (if possible at all) would be to get rid of the for loop. But I think only Frodo can anwser if that is even possible.

;-) Ojo
 

ojo

Portal Member
September 19, 2004
47
1
Ulstrup, Denmark
frodo said:
wont work since a control can be a groupcontrol and a groupcontrol can have 1 or more other controls

Darn' :cry: I didn't see that. Would have been ok though. Doing profiling sessions on my machine that did -2%.

Did try a couple of other aproaches to the same topic (minding the group control) but none proved feasable.

Only one conclusion => Great code already.

I will look into other areas of "interest". Maybe I'll end up being lucky....

;-) Ojo
 

Users who are viewing this thread

Top Bottom