mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-08 21:49:41 +00:00
Introduced ASIndexPath for efficient handling of index paths in C++ vectors, while maintaining the readability of ".section" and ".row" instead of ".first" and ".second" inside of complicated business logic. Confirmed that the working range calls are firing appropriately during ASTableViewStressTest, including the deallocation of the rich text placeholders provided by ASTextNode.
85 lines
2.1 KiB
Objective-C
85 lines
2.1 KiB
Objective-C
//
|
|
// ASIndexPath.h
|
|
// Pods
|
|
//
|
|
// Created by Scott Goodson on 7/4/15.
|
|
//
|
|
// A much more efficient way to handle index paths than NSIndexPath.
|
|
// For best results, use C++ vectors; NSValue wrapping with Cocoa collections
|
|
// would make NSIndexPath a much better choice.
|
|
//
|
|
|
|
typedef struct {
|
|
NSInteger section;
|
|
NSInteger row;
|
|
} ASIndexPath;
|
|
|
|
typedef struct {
|
|
ASIndexPath start;
|
|
ASIndexPath end;
|
|
} ASIndexPathRange;
|
|
|
|
ASIndexPath ASIndexPathMake(NSInteger section, NSInteger row)
|
|
{
|
|
ASIndexPath indexPath;
|
|
indexPath.section = section;
|
|
indexPath.row = row;
|
|
return indexPath;
|
|
}
|
|
|
|
BOOL ASIndexPathEqualToIndexPath(ASIndexPath first, ASIndexPath second)
|
|
{
|
|
return (first.section == second.section && first.row == second.row);
|
|
}
|
|
|
|
ASIndexPath ASIndexPathMinimum(ASIndexPath first, ASIndexPath second)
|
|
{
|
|
if (first.section < second.section) {
|
|
return first;
|
|
} else if (first.section > second.section) {
|
|
return second;
|
|
} else {
|
|
return (first.row < second.row ? first : second);
|
|
}
|
|
}
|
|
|
|
ASIndexPath ASIndexPathMaximum(ASIndexPath first, ASIndexPath second)
|
|
{
|
|
if (first.section > second.section) {
|
|
return first;
|
|
} else if (first.section < second.section) {
|
|
return second;
|
|
} else {
|
|
return (first.row > second.row ? first : second);
|
|
}
|
|
}
|
|
|
|
ASIndexPathRange ASIndexPathRangeMake(ASIndexPath first, ASIndexPath second)
|
|
{
|
|
ASIndexPathRange range;
|
|
range.start = ASIndexPathMinimum(first, second);
|
|
range.end = ASIndexPathMaximum(first, second);
|
|
return range;
|
|
}
|
|
|
|
BOOL ASIndexPathRangeEqualToIndexPathRange(ASIndexPathRange first, ASIndexPathRange second)
|
|
{
|
|
return ASIndexPathEqualToIndexPath(first.start, second.start) && ASIndexPathEqualToIndexPath(first.end, second.end);
|
|
}
|
|
|
|
@interface NSIndexPath (ASIndexPathAdditions)
|
|
+ (NSIndexPath *)indexPathWithASIndexPath:(ASIndexPath)indexPath;
|
|
- (ASIndexPath)ASIndexPathValue;
|
|
@end
|
|
|
|
@implementation NSIndexPath (ASIndexPathAdditions)
|
|
+ (NSIndexPath *)indexPathWithASIndexPath:(ASIndexPath)indexPath
|
|
{
|
|
return [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];;
|
|
}
|
|
- (ASIndexPath)ASIndexPathValue
|
|
{
|
|
return ASIndexPathMake(self.section, self.row);
|
|
}
|
|
@end
|