[ASTextNode2] Simplify allocWithZone: + initialize implementation #trivial (#1059)

* Simplify ASTextNode2 alloc + initialize implementation

* Kick the CI by marking two methods as NO_ESCAPE for Xcode 10
This commit is contained in:
Adlai Holler 2018-08-02 07:36:26 -07:00 committed by GitHub
parent 9d8406e938
commit 78be342e77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 26 deletions

View File

@ -1346,36 +1346,29 @@ static NSAttributedString *DefaultTruncationAttributedString()
}
#endif
+ (id)allocWithZone:(struct _NSZone *)zone
// All direct descendants of ASTextNode get their superclass replaced by ASTextNode2.
+ (void)initialize
{
// If they're not experimenting, just forward.
if (!ASActivateExperimentalFeature(ASExperimentalTextNode)) {
return [super allocWithZone:zone];
}
// We are plain ASTextNode. Just swap in an ASTextNode2 instead.
if (self == [ASTextNode class]) {
return (ASTextNode *)[ASTextNode2 allocWithZone:zone];
}
// We are descended from ASTextNode. We need to change the superclass for the
// ASTextNode subclass to ASTextNode2.
// Walk up the class hierarchy until we find ASTextNode.
// Note: This may be called on multiple threads simultaneously.
Class s;
for (Class c = self; c != Nil && c != [ASTextNode class]; c = s) {
s = class_getSuperclass(c);
if (s == [ASTextNode class]) {
// Texture requires that node subclasses call [super initialize]
[super initialize];
if (class_getSuperclass(self) == [ASTextNode class]
&& ASActivateExperimentalFeature(ASExperimentalTextNode)) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Direct descendent. Update superclass of c and end.
class_setSuperclass(c, [ASTextNode2 class]);
class_setSuperclass(self, [ASTextNode2 class]);
#pragma clang diagnostic pop
break;
}
}
}
return [super allocWithZone:zone];
// For direct allocations of ASTextNode itself, we override allocWithZone:
+ (id)allocWithZone:(struct _NSZone *)zone
{
if (ASActivateExperimentalFeature(ASExperimentalTextNode)) {
return (ASTextNode *)[ASTextNode2 allocWithZone:zone];
} else {
return [super allocWithZone:zone];
}
}
@end

View File

@ -217,7 +217,7 @@ static _ASDisplayLayerTestDelegateClassModes _class_modes;
}
// DANGER: Don't use the delegate as the parameters in real code; this is not thread-safe and just for accounting in unit tests!
+ (UIImage *)displayWithParameters:(_ASDisplayLayerTestDelegate *)delegate isCancelled:(asdisplaynode_iscancelled_block_t)sentinelBlock
+ (UIImage *)displayWithParameters:(_ASDisplayLayerTestDelegate *)delegate isCancelled:(NS_NOESCAPE asdisplaynode_iscancelled_block_t)sentinelBlock
{
UIImage *contents = bogusImage();
if (delegate->_displayLayerBlock != NULL) {
@ -228,7 +228,7 @@ static _ASDisplayLayerTestDelegateClassModes _class_modes;
}
// DANGER: Don't use the delegate as the parameters in real code; this is not thread-safe and just for accounting in unit tests!
+ (void)drawRect:(CGRect)bounds withParameters:(_ASDisplayLayerTestDelegate *)delegate isCancelled:(asdisplaynode_iscancelled_block_t)sentinelBlock isRasterizing:(BOOL)isRasterizing
+ (void)drawRect:(CGRect)bounds withParameters:(_ASDisplayLayerTestDelegate *)delegate isCancelled:(NS_NOESCAPE asdisplaynode_iscancelled_block_t)sentinelBlock isRasterizing:(BOOL)isRasterizing
{
__atomic_add_fetch(&delegate->_drawRectCount, 1, __ATOMIC_SEQ_CST);
}