0
我剖析我的比賽,看來我在這裏度過一個良好的時間:優化獲取絕對矩形的Widget?
const Rectangle Widget::getAbsoluteRectangle() const
0.01s {
Point absLocation;
0.00s absLocation = getLocation();
if(!getParent())
{
return Rectangle(absLocation.getX(),absLocation.getY(),
getSize().getWidth(),getSize().getHeight());
}
const Widget* parent = this;
int eX = 0;
int eY = 0;
while(parent->getParent() != NULL)
{
0.02s parent = parent->getParent();
0.01s eX = parent->getMargin(SIDE_LEFT);
0.04s eY = parent->getMargin(SIDE_TOP);
0.03s absLocation.setX(absLocation.getX() + parent->getLocation().getX() + eX);
0.04s absLocation.setY(absLocation.getY() + parent->getLocation().getY() + eY);
}
0.02s return Rectangle(absLocation,getSize());
0.01s }
我想到也許緩存的這個結果和無效它時,其父母一方移動或調整,但首先我我想知道是否有明顯的優化。
謝謝