Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Changes to be released in next version
*

🙌 Improvements
*
* MXCollectionViewCell: Reduced disk access when creating cells by caching UINib objects.

🐛 Bugfix
*
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Contributing code to the Matrix iOS Kit
=======================================

matrix-ios-kit follows the same pattern as https://github.com/matrix-org/synapse/blob/master/CONTRIBUTING.rst
matrix-ios-kit follows the same pattern as https://github.com/matrix-org/synapse/blob/master/CONTRIBUTING.md
31 changes: 23 additions & 8 deletions MatrixKit/Views/MXKCollectionViewCell/MXKCollectionViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,28 @@ @implementation MXKCollectionViewCell

+ (UINib *)nib
{
// Check whether a nib file is available
NSBundle *mainBundle = [NSBundle bundleForClass:self.class];
NSString *path = [mainBundle pathForResource:NSStringFromClass([self class]) ofType:@"nib"];
if (path)
NSParameterAssert(NSThread.isMainThread);

// Nib cache lives forever. UINibs release resources on demand. Null means there is no nib.
static NSMutableDictionary<Class, id> *nibs;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
nibs = [[NSMutableDictionary alloc] init];
});

id result = nibs[(id)self];
if (!result)
{
return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:mainBundle];
NSString *className = NSStringFromClass(self);
NSBundle *bundle = [NSBundle bundleForClass:self];
NSString *path = [bundle pathForResource:className ofType:@"nib"];
if (path)
{
result = [UINib nibWithNibName:className bundle:bundle];
}
nibs[(id)self] = result ?: [NSNull null];
}
return nil;
return result == [NSNull null] ? nil : result;
}

+ (NSString*)defaultReuseIdentifier
Expand All @@ -53,9 +67,10 @@ - (void)prepareForReuse
- (instancetype)initWithFrame:(CGRect)frame
{
// Check whether a xib is defined
if ([[self class] nib])
UINib *nib = [self.class nib];
if (nib)
{
self = [[[self class] nib] instantiateWithOwner:nil options:nil].firstObject;
self = [nib instantiateWithOwner:nil options:nil].firstObject;
self.frame = frame;
}
else
Expand Down