Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ASWeakMapEntry Value Atomic #555

Merged
merged 6 commits into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Table and collection views to consider content inset when calculating (default) element size range [Huy Nguyen](https://github.com/nguyenhuy) [#525](https://github.com/TextureGroup/Texture/pull/525)
- [ASEditableTextNode] added -editableTextNodeShouldBeginEditing to ASEditableTextNodeDelegate to mirror the corresponding method from UITextViewDelegate. [Yan S.](https://github.com/yans) [#535](https://github.com/TextureGroup/Texture/pull/535)
- [Breaking] Remove APIs that have been deprecated since 2.0 and/or for at least 6 months [Huy Nguyen](https://github.com/nguyenhuy) [#529](https://github.com/TextureGroup/Texture/pull/529)
- Fixed a memory corruption issue in the ASImageNode display system. [Adlai Holler](https://github.com/Adlai-Holler) [#55](https://github.com/TextureGroup/Texture/pull/555)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "#555"


##2.4
- Fix an issue where inserting/deleting sections could lead to inconsistent supplementary element behavior. [Adlai Holler](https://github.com/Adlai-Holler)
Expand Down
4 changes: 2 additions & 2 deletions Source/Private/ASWeakMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
AS_SUBCLASSING_RESTRICTED
@interface ASWeakMapEntry<Value> : NSObject

@property (nonatomic, retain, readonly) Value value;
@property (atomic, strong, readonly) Value value;

@end

Expand All @@ -49,7 +49,7 @@ AS_SUBCLASSING_RESTRICTED
* The underlying storage is a hash table and the Key type should implement `hash` and `isEqual:`.
*/
AS_SUBCLASSING_RESTRICTED
@interface ASWeakMap<__covariant Key : NSObject *, Value> : NSObject
@interface ASWeakMap<__covariant Key, Value> : NSObject

/**
* Read from the cache. The Value object is accessible from the returned ASWeakMapEntry.
Expand Down
16 changes: 6 additions & 10 deletions Source/Private/ASWeakMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
#import <AsyncDisplayKit/ASWeakMap.h>

@interface ASWeakMapEntry ()
@property (nonatomic, strong) NSObject *key;
@property (nonatomic, strong, readonly) id key;
@property (atomic, strong) id value;
@end

@implementation ASWeakMapEntry

- (instancetype)initWithKey:(NSObject *)key value:(NSObject *)value
- (instancetype)initWithKey:(id)key value:(id)value
{
self = [super init];
if (self) {
Expand All @@ -33,16 +34,11 @@ - (instancetype)initWithKey:(NSObject *)key value:(NSObject *)value
return self;
}

- (void)setValue:(NSObject *)value
{
_value = value;
}

@end


@interface ASWeakMap ()
@property (nonatomic, strong) NSMapTable<NSObject *, ASWeakMapEntry *> *hashTable;
@property (nonatomic, strong, readonly) NSMapTable<id, ASWeakMapEntry *> *hashTable;
@end

/**
Expand All @@ -69,12 +65,12 @@ - (instancetype)init
return self;
}

- (ASWeakMapEntry *)entryForKey:(NSObject *)key
- (ASWeakMapEntry *)entryForKey:(id)key
{
return [self.hashTable objectForKey:key];
}

- (ASWeakMapEntry *)setObject:(NSObject *)value forKey:(NSObject *)key
- (ASWeakMapEntry *)setObject:(id)value forKey:(id)key
{
ASWeakMapEntry *entry = [self.hashTable objectForKey:key];
if (entry != nil) {
Expand Down