Improve factoring of locking and early returns for -setInterfaceState: and -setHierarchyState:

This commit is contained in:
Scott Goodson 2015-12-06 19:30:04 -08:00
parent ea144310c8
commit 1e9c4563f3

View File

@ -1696,14 +1696,16 @@ void recursivelyEnsureDisplayForLayer(CALayer *layer)
- (void)setInterfaceState:(ASInterfaceState)newState - (void)setInterfaceState:(ASInterfaceState)newState
{ {
ASInterfaceState oldState; ASInterfaceState oldState = ASInterfaceStateNone;
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (_interfaceState == newState) {
return;
}
oldState = _interfaceState; oldState = _interfaceState;
_interfaceState = newState; _interfaceState = newState;
} }
if (newState != oldState) {
if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) { if ((newState & ASInterfaceStateMeasureLayout) != (oldState & ASInterfaceStateMeasureLayout)) {
// Trigger asynchronous measurement if it is not already cached or being calculated. // Trigger asynchronous measurement if it is not already cached or being calculated.
} }
@ -1736,7 +1738,6 @@ void recursivelyEnsureDisplayForLayer(CALayer *layer)
// Consider providing a -didBecomeInvisible. // Consider providing a -didBecomeInvisible.
} }
} }
}
} }
- (void)enterInterfaceState:(ASInterfaceState)interfaceState - (void)enterInterfaceState:(ASInterfaceState)interfaceState
@ -1767,9 +1768,12 @@ void recursivelyEnsureDisplayForLayer(CALayer *layer)
- (void)setHierarchyState:(ASHierarchyState)newState - (void)setHierarchyState:(ASHierarchyState)newState
{ {
ASHierarchyState oldState; ASHierarchyState oldState = ASHierarchyStateNormal;
{ {
ASDN::MutexLocker l(_propertyLock); ASDN::MutexLocker l(_propertyLock);
if (_hierarchyState == newState) {
return;
}
oldState = _hierarchyState; oldState = _hierarchyState;
_hierarchyState = newState; _hierarchyState = newState;
} }