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 }
我想到也许缓存的这个结果和无效它时,其父母一方移动或调整,但首先我我想知道是否有明显的优化。
谢谢