Fix Alignment of Hashed Structs (#287)

* Fix alignment of ASImageNodeContentsKey struct to fix hashing

* Change the change log by logging a change

* Add the world's stupidest explicit cast

* Actually its simpler
This commit is contained in:
Adlai Holler
2017-05-17 18:08:50 -07:00
committed by GitHub
parent 8c45eaefce
commit d30c35787c
5 changed files with 16 additions and 2 deletions

View File

@@ -24,4 +24,4 @@
- [Layout] Extract layout implementation code into it's own subcategories [Michael Schneider] (https://github.com/maicki)[#272](https://github.com/TextureGroup/Texture/pull/272)
- [Fix] Fix a potential crash when cell nodes that need layout are deleted during the same runloop. [Adlai Holler](https://github.com/Adlai-Holler) [#279](https://github.com/TextureGroup/Texture/pull/279)
- [Batch fetching] Add ASBatchFetchingDelegate that takes scroll velocity and remaining time into account [Huy Nguyen](https://github.com/nguyenhuy) [#281](https://github.com/TextureGroup/Texture/pull/281)
- [Fix] Fix a major regression in our image node contents caching. [Adlai Holler](https://github.com/Adlai-Holler) [#287](https://github.com/TextureGroup/Texture/pull/287)

View File

@@ -113,15 +113,18 @@ typedef void (^ASImageNodeDrawParametersBlock)(ASWeakMapEntry *entry);
- (NSUInteger)hash
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
NSUInteger imageHash;
CGSize backingSize;
CGRect imageDrawRect;
BOOL isOpaque;
NSInteger isOpaque;
NSUInteger backgroundColorHash;
void *willDisplayNodeContentWithRenderingContext;
void *didDisplayNodeContentWithRenderingContext;
void *imageModificationBlock;
#pragma clang diagnostic pop
} data = {
_image.hash,
_backingSize,

View File

@@ -64,9 +64,12 @@ static NSString *ASTextNodeTruncationTokenAttributeName = @"ASTextNodeTruncation
- (NSUInteger)hash
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
size_t attributesHash;
CGSize constrainedSize;
#pragma clang diagnostic pop
} data = {
_attributes.hash(),
_constrainedSize

View File

@@ -34,6 +34,11 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
* _bounds.size
* };
* return ASHashBytes(&data, sizeof(data));
*
* @warning: If a struct has padding, any fields that are intiailized in {}
* will have garbage data for their padding, which will break this hash! Either
* use `pragma clang diagnostic warning "-Wpadded"` around your struct definition
* or manually initialize the fields of your struct (`myStruct.x = 7;` etc).
*/
NSUInteger ASHashBytes(void *bytes, size_t length);

View File

@@ -24,6 +24,8 @@ NSString *const ASTextKitEntityAttributeName = @"ck_entity";
size_t ASTextKitAttributes::hash() const
{
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wpadded"
struct {
NSUInteger attrStringHash;
NSUInteger truncationStringHash;
@@ -35,6 +37,7 @@ size_t ASTextKitAttributes::hash() const
NSUInteger shadowColorHash;
CGFloat shadowOpacity;
CGFloat shadowRadius;
#pragma clang diagnostic pop
} data = {
[attributedString hash],
[truncationAttributedString hash],