Browse files

profile: stack.size() can be O(n) and these are done hundreds of time…

…s per frame. Keep track of the size instead.
  • Loading branch information...
1 parent eb20746 commit d505fd08f9a260f6723f1c03df8612d9d89bd627 Cory Fields committed Nov 21, 2012
Showing with 18 additions and 12 deletions.
  1. +2 −1 xbmc/guilib/GraphicContext.cpp
  2. +16 −11 xbmc/guilib/GraphicContext.h
View
3 xbmc/guilib/GraphicContext.cpp
@@ -52,7 +52,8 @@ CGraphicContext::CGraphicContext(void) :
m_Resolution(RES_INVALID),
/*m_windowResolution,*/
m_guiScaleX(1.0f),
- m_guiScaleY(1.0f)
+ m_guiScaleY(1.0f),
+ m_groupTransformSize(0)
/*,m_cameras, */
/*m_origins, */
/*m_clipRegions,*/
View
27 xbmc/guilib/GraphicContext.h
@@ -171,37 +171,42 @@ class CGraphicContext : public CCriticalSection
void ClipRect(CRect &vertex, CRect &texture, CRect *diffuse = NULL);
inline unsigned int AddGUITransform()
{
- unsigned int size = m_groupTransform.size();
m_groupTransform.push(m_guiTransform);
- UpdateFinalTransform(m_groupTransform.top());
- return size;
+ m_groupTransformSize++;
+ UpdateFinalTransform(m_guiTransform);
+ return m_groupTransformSize - 1;
}
inline TransformMatrix AddTransform(const TransformMatrix &matrix)
{
- ASSERT(m_groupTransform.size());
- TransformMatrix absoluteMatrix = m_groupTransform.size() ? m_groupTransform.top() * matrix : matrix;
+ ASSERT(m_groupTransformSize);
+ TransformMatrix absoluteMatrix = m_groupTransformSize ? m_groupTransform.top() * matrix : matrix;
m_groupTransform.push(absoluteMatrix);
+ m_groupTransformSize++;
UpdateFinalTransform(absoluteMatrix);
return absoluteMatrix;
}
inline void SetTransform(const TransformMatrix &matrix)
{
// TODO: We only need to add it to the group transform as other transforms may be added on top of this one later on
// Once all transforms are cached then this can be removed and UpdateFinalTransform can be called directly
- ASSERT(m_groupTransform.size());
+ ASSERT(m_groupTransformSize);
m_groupTransform.push(matrix);
+ m_groupTransformSize++;
UpdateFinalTransform(m_groupTransform.top());
}
inline unsigned int RemoveTransform()
{
- ASSERT(m_groupTransform.size());
- if (m_groupTransform.size())
+ ASSERT(m_groupTransformSize);
+ if (m_groupTransformSize)
+ {
m_groupTransform.pop();
- if (m_groupTransform.size())
+ m_groupTransformSize--;
+ }
+ if (m_groupTransformSize)
UpdateFinalTransform(m_groupTransform.top());
else
UpdateFinalTransform(TransformMatrix());
- return m_groupTransform.size();
+ return m_groupTransformSize;
}
CRect generateAABB(const CRect &rect) const;
@@ -232,7 +237,7 @@ class CGraphicContext : public CCriticalSection
TransformMatrix m_guiTransform;
TransformMatrix m_finalTransform;
std::stack<TransformMatrix> m_groupTransform;
-
+ unsigned int m_groupTransformSize;
CRect m_scissors;
};

0 comments on commit d505fd0

Please sign in to comment.