Microoptimize thread bit operations.

This commit is contained in:
Bartosz Taudul 2017-12-05 22:22:07 +01:00
parent 52df06d478
commit 5407676f1f

View File

@ -2752,10 +2752,8 @@ enum class LockState
WaitLock // red WaitLock // red
}; };
static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::iterator& it, const Vector<LockEvent*>::iterator& end, LockState state, LockState& nextState, uint8_t thread ) static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::iterator& it, const Vector<LockEvent*>::iterator& end, LockState state, LockState& nextState, uint64_t threadBit )
{ {
const auto threadBit = GetThreadBit( thread );
nextState = LockState::Nothing; nextState = LockState::Nothing;
auto next = it; auto next = it;
next++; next++;
@ -2767,7 +2765,7 @@ static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::
{ {
if( (*next)->lockCount != 0 ) if( (*next)->lockCount != 0 )
{ {
if( (*next)->lockingThread == thread ) if( GetThreadBit( (*next)->lockingThread ) == threadBit )
{ {
nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
@ -2825,7 +2823,7 @@ static Vector<LockEvent*>::iterator GetNextLockEvent( const Vector<LockEvent*>::
nextState = LockState::WaitLock; nextState = LockState::WaitLock;
while( next < end ) while( next < end )
{ {
if( (*next)->lockingThread == thread ) if( GetThreadBit( (*next)->lockingThread ) == threadBit )
{ {
nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock; nextState = AreOtherWaiting( (*next)->waitList, threadBit ) ? LockState::HasBlockingLock : LockState::HasLock;
break; break;
@ -2906,7 +2904,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
{ {
while( vbegin < vend && ( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) ) ) while( vbegin < vend && ( state == LockState::Nothing || ( m_onlyContendedLocks && state == LockState::HasLock ) ) )
{ {
vbegin = GetNextLockEvent( vbegin, vend, state, state, thread ); vbegin = GetNextLockEvent( vbegin, vend, state, state, threadBit );
} }
if( vbegin >= vend ) break; if( vbegin >= vend ) break;
@ -2915,7 +2913,7 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
LockState drawState = state; LockState drawState = state;
LockState nextState; LockState nextState;
auto next = GetNextLockEvent( vbegin, vend, state, nextState, thread ); auto next = GetNextLockEvent( vbegin, vend, state, nextState, threadBit );
const auto t0 = (*vbegin)->time; const auto t0 = (*vbegin)->time;
int64_t t1 = next == tl.end() ? GetLastTime() : (*next)->time; int64_t t1 = next == tl.end() ? GetLastTime() : (*next)->time;
@ -2931,12 +2929,12 @@ int View::DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos,
auto ns = nextState; auto ns = nextState;
while( n < vend && ( ns == LockState::Nothing || ( m_onlyContendedLocks && ns == LockState::HasLock ) ) ) while( n < vend && ( ns == LockState::Nothing || ( m_onlyContendedLocks && ns == LockState::HasLock ) ) )
{ {
n = GetNextLockEvent( n, vend, ns, ns, thread ); n = GetNextLockEvent( n, vend, ns, ns, threadBit );
} }
if( n >= vend ) break; if( n >= vend ) break;
if( n == next ) if( n == next )
{ {
n = GetNextLockEvent( n, vend, ns, ns, thread ); n = GetNextLockEvent( n, vend, ns, ns, threadBit );
} }
drawState = CombineLockState( drawState, nextState ); drawState = CombineLockState( drawState, nextState );
condensed++; condensed++;