mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-06 04:32:06 +00:00
* Reimplement ASRectTable using unordered_map to avoid obscure NSMapTable exception. The new class is called ASRectMap, which patterns alongside ASIntegerMap in both name and implementation. After some pretty detailed investigation, including study of open-source reimplementations of Foundation, the best lead I've found on the NSMapTable exception is that some NSPointerFunction types are not fully supported. Strangely, the ones being used do seem to work fine almost all of the time. The main concern is the Struct memory type, which is not officially re-declared in NSMapTable, and as such the documentation claims that there may exist some combinations of NSPointerFunction that are not supported. Because the exception is occurring frequently enough to be a concern (in the hundreds to low thousands, though only 50 a day) - I decided to replace NSMapTable entirely in order to ensure full correctness. "*** -[NSMapTable initWithKeyPointerFunctions:valuePointerFunctions:capacity:] Requested configuration not supported." * Fix Xcode project
52 lines
1.3 KiB
Objective-C
52 lines
1.3 KiB
Objective-C
//
|
|
// ASRectMapTests.m
|
|
// Texture
|
|
//
|
|
// Created by Adlai Holler on 2/24/17.
|
|
// Copyright © 2017 Facebook. All rights reserved.
|
|
//
|
|
|
|
#import <XCTest/XCTest.h>
|
|
|
|
#import "ASRectMap.h"
|
|
#import "ASXCTExtensions.h"
|
|
|
|
@interface ASRectMapTests : XCTestCase
|
|
@end
|
|
|
|
@implementation ASRectMapTests
|
|
|
|
- (void)testThatItStoresRects
|
|
{
|
|
ASRectMap *table = [ASRectMap rectMapForWeakObjectPointers];
|
|
NSObject *key0 = [[NSObject alloc] init];
|
|
NSObject *key1 = [[NSObject alloc] init];
|
|
ASXCTAssertEqualRects([table rectForKey:key0], CGRectNull);
|
|
ASXCTAssertEqualRects([table rectForKey:key1], CGRectNull);
|
|
CGRect rect0 = CGRectMake(0, 0, 100, 100);
|
|
CGRect rect1 = CGRectMake(0, 0, 50, 50);
|
|
[table setRect:rect0 forKey:key0];
|
|
[table setRect:rect1 forKey:key1];
|
|
|
|
ASXCTAssertEqualRects([table rectForKey:key0], rect0);
|
|
ASXCTAssertEqualRects([table rectForKey:key1], rect1);
|
|
}
|
|
|
|
|
|
- (void)testCopying
|
|
{
|
|
ASRectMap *table = [ASRectMap rectMapForWeakObjectPointers];
|
|
NSObject *key = [[NSObject alloc] init];
|
|
ASXCTAssertEqualRects([table rectForKey:key], CGRectNull);
|
|
CGRect rect0 = CGRectMake(0, 0, 100, 100);
|
|
CGRect rect1 = CGRectMake(0, 0, 50, 50);
|
|
[table setRect:rect0 forKey:key];
|
|
ASRectMap *copy = [table copy];
|
|
[copy setRect:rect1 forKey:key];
|
|
|
|
ASXCTAssertEqualRects([table rectForKey:key], rect0);
|
|
ASXCTAssertEqualRects([copy rectForKey:key], rect1);
|
|
}
|
|
|
|
@end
|