Skip to content

Commit

Permalink
Make ASWeakMapEntry Value Atomic (TextureGroup#555)
Browse files Browse the repository at this point in the history
* Make ASWeakMapEntry value atomic

* Increment changelog

* Go a little nuts

* Update CHANGELOG.md
  • Loading branch information
Adlai-Holler authored and bernieperez committed Apr 25, 2018
1 parent 493a1ac commit 32bbf1d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [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)
- [ASDisplayNode] Ensure `-displayWillStartAsynchronously:` and `-displayDidFinish` are invoked on rasterized subnodes. [Eric Scheers](https://github.com/smeis) [#532](https://github.com/TextureGroup/Texture/pull/532)
- Fixed a memory corruption issue in the ASImageNode display system. [Adlai Holler](https://github.com/Adlai-Holler) [#555](https://github.com/TextureGroup/Texture/pull/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

0 comments on commit 32bbf1d

Please sign in to comment.