mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Improve factoring of locking and early returns for -setInterfaceState: and -setHierarchyState:
This commit is contained in:
parent
ea144310c8
commit
1e9c4563f3
@ -1696,45 +1696,46 @@ 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.
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Entered or exited data loading state.
|
// Entered or exited data loading state.
|
||||||
if ((newState & ASInterfaceStateFetchData) != (oldState & ASInterfaceStateFetchData)) {
|
if ((newState & ASInterfaceStateFetchData) != (oldState & ASInterfaceStateFetchData)) {
|
||||||
if (newState & ASInterfaceStateFetchData) {
|
if (newState & ASInterfaceStateFetchData) {
|
||||||
[self fetchData];
|
[self fetchData];
|
||||||
} else {
|
} else {
|
||||||
[self clearFetchedData];
|
[self clearFetchedData];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Entered or exited contents rendering state.
|
// Entered or exited contents rendering state.
|
||||||
if ((newState & ASInterfaceStateDisplay) != (oldState & ASInterfaceStateDisplay)) {
|
if ((newState & ASInterfaceStateDisplay) != (oldState & ASInterfaceStateDisplay)) {
|
||||||
if (newState & ASInterfaceStateDisplay) {
|
if (newState & ASInterfaceStateDisplay) {
|
||||||
// Once the working window is eliminated (ASRangeHandlerRender), trigger display directly here.
|
// Once the working window is eliminated (ASRangeHandlerRender), trigger display directly here.
|
||||||
[self setDisplaySuspended:NO];
|
[self setDisplaySuspended:NO];
|
||||||
} else {
|
} else {
|
||||||
[self setDisplaySuspended:YES];
|
[self setDisplaySuspended:YES];
|
||||||
[self clearContents];
|
[self clearContents];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Entered or exited data loading state.
|
// Entered or exited data loading state.
|
||||||
if ((newState & ASInterfaceStateVisible) != (oldState & ASInterfaceStateVisible)) {
|
if ((newState & ASInterfaceStateVisible) != (oldState & ASInterfaceStateVisible)) {
|
||||||
if (newState & ASInterfaceStateVisible) {
|
if (newState & ASInterfaceStateVisible) {
|
||||||
// Consider providing a -didBecomeVisible.
|
// Consider providing a -didBecomeVisible.
|
||||||
} else {
|
} else {
|
||||||
// Consider providing a -didBecomeInvisible.
|
// Consider providing a -didBecomeInvisible.
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user