mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-19 04:39:36 +00:00
Do not reuse NSStringDrawingContexts (#2537)
This commit is contained in:
parent
ff9e493a59
commit
076d22e9f1
@ -35,20 +35,11 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
|||||||
return truncationCharacterSet;
|
return truncationCharacterSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface ASTextKitRenderer()
|
|
||||||
/**
|
|
||||||
* This object is lazily created. It is provided to the NSAttributedString
|
|
||||||
* drawing methods used by the fast-paths in the size calculation and drawing
|
|
||||||
* instance methods.
|
|
||||||
*/
|
|
||||||
@property (nonatomic, strong, readonly) NSStringDrawingContext *stringDrawingContext;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation ASTextKitRenderer {
|
@implementation ASTextKitRenderer {
|
||||||
CGSize _calculatedSize;
|
CGSize _calculatedSize;
|
||||||
BOOL _sizeIsCalculated;
|
BOOL _sizeIsCalculated;
|
||||||
}
|
}
|
||||||
@synthesize attributes = _attributes, context = _context, shadower = _shadower, truncater = _truncater, fontSizeAdjuster = _fontSizeAdjuster, stringDrawingContext = _stringDrawingContext;
|
@synthesize attributes = _attributes, context = _context, shadower = _shadower, truncater = _truncater, fontSizeAdjuster = _fontSizeAdjuster;
|
||||||
|
|
||||||
#pragma mark - Initialization
|
#pragma mark - Initialization
|
||||||
|
|
||||||
@ -118,15 +109,18 @@ static NSCharacterSet *_defaultAvoidTruncationCharacterSet()
|
|||||||
|
|
||||||
- (NSStringDrawingContext *)stringDrawingContext
|
- (NSStringDrawingContext *)stringDrawingContext
|
||||||
{
|
{
|
||||||
if (_stringDrawingContext == nil) {
|
// String drawing contexts are not safe to use from more than one thread.
|
||||||
_stringDrawingContext = [[NSStringDrawingContext alloc] init];
|
// i.e. if they are created on one thread, it is unsafe to use them on another.
|
||||||
|
// Therefore we always need to create a new one.
|
||||||
if (isinf(_constrainedSize.width) == NO && _attributes.maximumNumberOfLines > 0) {
|
//
|
||||||
ASDisplayNodeAssert(_attributes.maximumNumberOfLines != 1, @"Max line count 1 is not supported in fast-path.");
|
// http://web.archive.org/web/20140703122636/https://developer.apple.com/library/ios/documentation/uikit/reference/NSAttributedString_UIKit_Additions/Reference/Reference.html
|
||||||
[_stringDrawingContext setValue:@(_attributes.maximumNumberOfLines) forKey:@"maximumNumberOfLines"];
|
NSStringDrawingContext *stringDrawingContext = [[NSStringDrawingContext alloc] init];
|
||||||
}
|
|
||||||
|
if (isinf(_constrainedSize.width) == NO && _attributes.maximumNumberOfLines > 0) {
|
||||||
|
ASDisplayNodeAssert(_attributes.maximumNumberOfLines != 1, @"Max line count 1 is not supported in fast-path.");
|
||||||
|
[stringDrawingContext setValue:@(_attributes.maximumNumberOfLines) forKey:@"maximumNumberOfLines"];
|
||||||
}
|
}
|
||||||
return _stringDrawingContext;
|
return stringDrawingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Sizing
|
#pragma mark - Sizing
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user