Skip to content

Commit 2388f67

Browse files
maickiAdlai Holler
authored andcommitted
[ASTextNode] Add NSCache based cache for ASTextKitRenderer (facebookarchive#2199)
* Add cache implementation * Remove old ASEqualityHashHelpers * Some more ASEquality and ASEqualityHashHelper cleanup * Add cache for text renderer in ASTextNode * Move from C++ LRU renderer cache to NSCache based renderer cache
1 parent 6124830 commit 2388f67

9 files changed

Lines changed: 126 additions & 227 deletions

File tree

AsyncDisplayKit.xcodeproj/project.pbxproj

Lines changed: 25 additions & 27 deletions
Large diffs are not rendered by default.

AsyncDisplayKit/ASTextNode.mm

Lines changed: 97 additions & 158 deletions
Large diffs are not rendered by default.
File renamed without changes.

AsyncDisplayKit/TextKit/ASTextKitAttributes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ struct ASTextKitAttributes {
110110
&& maximumNumberOfLines == other.maximumNumberOfLines
111111
&& shadowOpacity == other.shadowOpacity
112112
&& shadowRadius == other.shadowRadius
113-
&& [pointSizeScaleFactors isEqualToArray:other.pointSizeScaleFactors]
113+
&& (pointSizeScaleFactors == other.pointSizeScaleFactors
114+
|| [pointSizeScaleFactors isEqualToArray:other.pointSizeScaleFactors])
114115
&& CGSizeEqualToSize(shadowOffset, other.shadowOffset)
115116
&& ASObjectIsEqual(exclusionPaths, other.exclusionPaths)
116117
&& ASObjectIsEqual(avoidTailTruncationSet, other.avoidTailTruncationSet)

AsyncDisplayKit/TextKit/ASTextKitContext.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
exclusionPaths:(NSArray *)exclusionPaths
3030
constrainedSize:(CGSize)constrainedSize;
3131

32-
@property (nonatomic, assign, readwrite) CGSize constrainedSize;
33-
3432
/**
3533
All operations on TextKit values MUST occur within this locked context. Simultaneous access (even non-mutative) to
3634
TextKit components may cause crashes.

AsyncDisplayKit/TextKit/ASTextKitContext.mm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString
5454
return self;
5555
}
5656

57-
- (CGSize)constrainedSize
58-
{
59-
ASDN::MutexSharedLocker l(__instanceLock__);
60-
return _textContainer.size;
61-
}
62-
63-
- (void)setConstrainedSize:(CGSize)constrainedSize
64-
{
65-
ASDN::MutexSharedLocker l(__instanceLock__);
66-
_textContainer.size = constrainedSize;
67-
}
68-
6957
- (void)performBlockWithLockedTextKitComponents:(void (^)(NSLayoutManager *,
7058
NSTextStorage *,
7159
NSTextContainer *))block

AsyncDisplayKit/TextKit/ASTextKitRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
@property (nonatomic, assign, readonly) ASTextKitAttributes attributes;
5555

56-
@property (nonatomic, assign, readwrite) CGSize constrainedSize;
56+
@property (nonatomic, assign, readonly) CGSize constrainedSize;
5757

5858
@property (nonatomic, assign, readonly) CGFloat currentScaleFactor;
5959

AsyncDisplayKit/TextKit/ASTextKitRenderer.mm

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,6 @@ - (CGSize)size
116116
return _calculatedSize;
117117
}
118118

119-
- (void)setConstrainedSize:(CGSize)constrainedSize
120-
{
121-
if (!CGSizeEqualToSize(constrainedSize, _constrainedSize)) {
122-
_sizeIsCalculated = NO;
123-
_constrainedSize = constrainedSize;
124-
_calculatedSize = CGSizeZero;
125-
126-
// Throw away the all subcomponents to create them with the new constrained size new as well as let the
127-
// truncater do it's job again for the new constrained size. This is necessary as after a truncation did happen
128-
// the context would use the truncated string and not the original string to truncate based on the new
129-
// constrained size
130-
__block ASTextKitContext *ctx = _context;
131-
__block ASTextKitTailTruncater *tru = _truncater;
132-
__block ASTextKitFontSizeAdjuster *adj = _fontSizeAdjuster;
133-
_context = nil;
134-
_truncater = nil;
135-
_fontSizeAdjuster = nil;
136-
ASPerformBlockOnDeallocationQueue(^{
137-
ctx = nil;
138-
tru = nil;
139-
adj = nil;
140-
});
141-
}
142-
}
143-
144119
- (void)_calculateSize
145120
{
146121
// if we have no scale factors or an unconstrained width, there is no reason to try to adjust the font size

AsyncDisplayKitTests/ASTextNodeSnapshotTests.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ - (void)testTextContainerInsetIsIncludedWithSmallerConstrainedSize
3939
ASTextNode *textNode = [[ASTextNode alloc] init];
4040
textNode.attributedText = [[NSAttributedString alloc] initWithString:@"judar judar judar judar judar judar"
4141
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:30] }];
42-
42+
4343
[textNode measureWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(100, 80))];
4444
textNode.frame = CGRectMake(50, 50, textNode.calculatedSize.width, textNode.calculatedSize.height);
4545
textNode.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);

0 commit comments

Comments
 (0)