@@ -141,19 +141,12 @@ void ASLayoutElementPopContext()
141
141
NSString * const ASYogaAspectRatioProperty = @" ASYogaAspectRatioProperty" ;
142
142
#endif
143
143
144
- #define ASLayoutElementStyleSetSizeWithScope (x ) \
145
- ({ \
146
- __instanceLock__.lock (); \
147
- const ASLayoutElementSize oldSize = _size.load (); \
148
- ASLayoutElementSize newSize = oldSize; \
149
- {x}; \
150
- BOOL changed = !ASLayoutElementSizeEqualToLayoutElementSize (oldSize, newSize); \
151
- if (changed) { \
152
- _size.store (newSize); \
153
- } \
154
- __instanceLock__.unlock (); \
155
- changed; \
156
- })
144
+ #define ASLayoutElementStyleSetSizeWithScope (x ) \
145
+ __instanceLock__.lock(); \
146
+ ASLayoutElementSize newSize = _size.load(); \
147
+ { x } \
148
+ _size.store(newSize); \
149
+ __instanceLock__.unlock();
157
150
158
151
#define ASLayoutElementStyleCallDelegate (propertyName )\
159
152
do {\
@@ -211,13 +204,9 @@ - (instancetype)init
211
204
{
212
205
self = [super init ];
213
206
if (self) {
214
- std::atomic_init (&_size, ASLayoutElementSizeMake ());
215
- std::atomic_init (&_flexBasis, ASDimensionAuto);
207
+ _size = ASLayoutElementSizeMake ();
216
208
#if YOGA
217
209
_parentAlignStyle = ASStackLayoutAlignItemsNotSet;
218
- std::atomic_init (&_flexDirection, ASStackLayoutDirectionVertical);
219
- std::atomic_init (&_alignItems, ASStackLayoutAlignItemsStretch);
220
- std::atomic_init (&_aspectRatio, static_cast <CGFloat >(YGUndefined));
221
210
#endif
222
211
}
223
212
return self;
@@ -249,10 +238,10 @@ - (ASDimension)width
249
238
250
239
- (void )setWidth : (ASDimension)width
251
240
{
252
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. width = width; });
253
- if (changed) {
254
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty );
255
- }
241
+ ASLayoutElementStyleSetSizeWithScope ({
242
+ newSize. width = width;
243
+ } );
244
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty);
256
245
}
257
246
258
247
- (ASDimension)height
@@ -262,10 +251,10 @@ - (ASDimension)height
262
251
263
252
- (void )setHeight : (ASDimension)height
264
253
{
265
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. height = height; });
266
- if (changed) {
267
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty );
268
- }
254
+ ASLayoutElementStyleSetSizeWithScope ({
255
+ newSize. height = height;
256
+ } );
257
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty);
269
258
}
270
259
271
260
- (ASDimension)minWidth
@@ -275,10 +264,10 @@ - (ASDimension)minWidth
275
264
276
265
- (void )setMinWidth : (ASDimension)minWidth
277
266
{
278
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. minWidth = minWidth; });
279
- if (changed) {
280
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty );
281
- }
267
+ ASLayoutElementStyleSetSizeWithScope ({
268
+ newSize. minWidth = minWidth;
269
+ } );
270
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty);
282
271
}
283
272
284
273
- (ASDimension)maxWidth
@@ -288,10 +277,10 @@ - (ASDimension)maxWidth
288
277
289
278
- (void )setMaxWidth : (ASDimension)maxWidth
290
279
{
291
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. maxWidth = maxWidth; });
292
- if (changed) {
293
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty );
294
- }
280
+ ASLayoutElementStyleSetSizeWithScope ({
281
+ newSize. maxWidth = maxWidth;
282
+ } );
283
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty);
295
284
}
296
285
297
286
- (ASDimension)minHeight
@@ -301,10 +290,10 @@ - (ASDimension)minHeight
301
290
302
291
- (void )setMinHeight : (ASDimension)minHeight
303
292
{
304
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. minHeight = minHeight; });
305
- if (changed) {
306
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty );
307
- }
293
+ ASLayoutElementStyleSetSizeWithScope ({
294
+ newSize. minHeight = minHeight;
295
+ } );
296
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty);
308
297
}
309
298
310
299
- (ASDimension)maxHeight
@@ -314,25 +303,23 @@ - (ASDimension)maxHeight
314
303
315
304
- (void )setMaxHeight : (ASDimension)maxHeight
316
305
{
317
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({ newSize. maxHeight = maxHeight; });
318
- if (changed) {
319
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty );
320
- }
306
+ ASLayoutElementStyleSetSizeWithScope ({
307
+ newSize. maxHeight = maxHeight;
308
+ } );
309
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty);
321
310
}
322
311
323
312
324
313
#pragma mark - ASLayoutElementStyleSizeHelpers
325
314
326
315
- (void )setPreferredSize : (CGSize )preferredSize
327
316
{
328
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
317
+ ASLayoutElementStyleSetSizeWithScope ({
329
318
newSize.width = ASDimensionMakeWithPoints (preferredSize.width );
330
319
newSize.height = ASDimensionMakeWithPoints (preferredSize.height );
331
320
});
332
- if (changed) {
333
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty);
334
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty);
335
- }
321
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty);
322
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty);
336
323
}
337
324
338
325
- (CGSize )preferredSize
@@ -353,26 +340,22 @@ - (CGSize)preferredSize
353
340
354
341
- (void )setMinSize : (CGSize )minSize
355
342
{
356
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
343
+ ASLayoutElementStyleSetSizeWithScope ({
357
344
newSize.minWidth = ASDimensionMakeWithPoints (minSize.width );
358
345
newSize.minHeight = ASDimensionMakeWithPoints (minSize.height );
359
346
});
360
- if (changed) {
361
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty);
362
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty);
363
- }
347
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty);
348
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty);
364
349
}
365
350
366
351
- (void )setMaxSize : (CGSize )maxSize
367
352
{
368
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
353
+ ASLayoutElementStyleSetSizeWithScope ({
369
354
newSize.maxWidth = ASDimensionMakeWithPoints (maxSize.width );
370
355
newSize.maxHeight = ASDimensionMakeWithPoints (maxSize.height );
371
356
});
372
- if (changed) {
373
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty);
374
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty);
375
- }
357
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty);
358
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty);
376
359
}
377
360
378
361
- (ASLayoutSize)preferredLayoutSize
@@ -383,14 +366,12 @@ - (ASLayoutSize)preferredLayoutSize
383
366
384
367
- (void )setPreferredLayoutSize : (ASLayoutSize)preferredLayoutSize
385
368
{
386
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
369
+ ASLayoutElementStyleSetSizeWithScope ({
387
370
newSize.width = preferredLayoutSize.width ;
388
371
newSize.height = preferredLayoutSize.height ;
389
372
});
390
- if (changed) {
391
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty);
392
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty);
393
- }
373
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleWidthProperty);
374
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleHeightProperty);
394
375
}
395
376
396
377
- (ASLayoutSize)minLayoutSize
@@ -401,14 +382,12 @@ - (ASLayoutSize)minLayoutSize
401
382
402
383
- (void )setMinLayoutSize : (ASLayoutSize)minLayoutSize
403
384
{
404
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
385
+ ASLayoutElementStyleSetSizeWithScope ({
405
386
newSize.minWidth = minLayoutSize.width ;
406
387
newSize.minHeight = minLayoutSize.height ;
407
388
});
408
- if (changed) {
409
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty);
410
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty);
411
- }
389
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinWidthProperty);
390
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMinHeightProperty);
412
391
}
413
392
414
393
- (ASLayoutSize)maxLayoutSize
@@ -419,23 +398,20 @@ - (ASLayoutSize)maxLayoutSize
419
398
420
399
- (void )setMaxLayoutSize : (ASLayoutSize)maxLayoutSize
421
400
{
422
- BOOL changed = ASLayoutElementStyleSetSizeWithScope ({
401
+ ASLayoutElementStyleSetSizeWithScope ({
423
402
newSize.maxWidth = maxLayoutSize.width ;
424
403
newSize.maxHeight = maxLayoutSize.height ;
425
404
});
426
- if (changed) {
427
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty);
428
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty);
429
- }
405
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxWidthProperty);
406
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleMaxHeightProperty);
430
407
}
431
408
432
409
#pragma mark - ASStackLayoutElement
433
410
434
411
- (void )setSpacingBefore : (CGFloat )spacingBefore
435
412
{
436
- if (_spacingBefore.exchange (spacingBefore) != spacingBefore) {
437
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleSpacingBeforeProperty);
438
- }
413
+ _spacingBefore.store (spacingBefore);
414
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleSpacingBeforeProperty);
439
415
}
440
416
441
417
- (CGFloat )spacingBefore
@@ -445,9 +421,8 @@ - (CGFloat)spacingBefore
445
421
446
422
- (void )setSpacingAfter : (CGFloat )spacingAfter
447
423
{
448
- if (_spacingAfter.exchange (spacingAfter) != spacingAfter) {
449
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleSpacingAfterProperty);
450
- }
424
+ _spacingAfter.store (spacingAfter);
425
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleSpacingAfterProperty);
451
426
}
452
427
453
428
- (CGFloat )spacingAfter
@@ -457,9 +432,8 @@ - (CGFloat)spacingAfter
457
432
458
433
- (void )setFlexGrow : (CGFloat )flexGrow
459
434
{
460
- if (_flexGrow.exchange (flexGrow) != flexGrow) {
461
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexGrowProperty);
462
- }
435
+ _flexGrow.store (flexGrow);
436
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexGrowProperty);
463
437
}
464
438
465
439
- (CGFloat )flexGrow
@@ -469,9 +443,8 @@ - (CGFloat)flexGrow
469
443
470
444
- (void )setFlexShrink : (CGFloat )flexShrink
471
445
{
472
- if (_flexShrink.exchange (flexShrink) != flexShrink) {
473
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexShrinkProperty);
474
- }
446
+ _flexShrink.store (flexShrink);
447
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexShrinkProperty);
475
448
}
476
449
477
450
- (CGFloat )flexShrink
@@ -481,9 +454,8 @@ - (CGFloat)flexShrink
481
454
482
455
- (void )setFlexBasis : (ASDimension)flexBasis
483
456
{
484
- if (!ASDimensionEqualToDimension (_flexBasis.exchange (flexBasis), flexBasis)) {
485
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexBasisProperty);
486
- }
457
+ _flexBasis.store (flexBasis);
458
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleFlexBasisProperty);
487
459
}
488
460
489
461
- (ASDimension)flexBasis
@@ -493,9 +465,8 @@ - (ASDimension)flexBasis
493
465
494
466
- (void )setAlignSelf : (ASStackLayoutAlignSelf)alignSelf
495
467
{
496
- if (_alignSelf.exchange (alignSelf) != alignSelf) {
497
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleAlignSelfProperty);
498
- }
468
+ _alignSelf.store (alignSelf);
469
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleAlignSelfProperty);
499
470
}
500
471
501
472
- (ASStackLayoutAlignSelf)alignSelf
@@ -505,9 +476,8 @@ - (ASStackLayoutAlignSelf)alignSelf
505
476
506
477
- (void )setAscender : (CGFloat )ascender
507
478
{
508
- if (_ascender.exchange (ascender) != ascender) {
509
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleAscenderProperty);
510
- }
479
+ _ascender.store (ascender);
480
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleAscenderProperty);
511
481
}
512
482
513
483
- (CGFloat )ascender
@@ -517,9 +487,8 @@ - (CGFloat)ascender
517
487
518
488
- (void )setDescender : (CGFloat )descender
519
489
{
520
- if (_descender.exchange (descender) != descender) {
521
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleDescenderProperty);
522
- }
490
+ _descender.store (descender);
491
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleDescenderProperty);
523
492
}
524
493
525
494
- (CGFloat )descender
@@ -531,9 +500,8 @@ - (CGFloat)descender
531
500
532
501
- (void )setLayoutPosition : (CGPoint )layoutPosition
533
502
{
534
- if (!CGPointEqualToPoint (_layoutPosition.exchange (layoutPosition), layoutPosition)) {
535
- ASLayoutElementStyleCallDelegate (ASLayoutElementStyleLayoutPositionProperty);
536
- }
503
+ _layoutPosition.store (layoutPosition);
504
+ ASLayoutElementStyleCallDelegate (ASLayoutElementStyleLayoutPositionProperty);
537
505
}
538
506
539
507
- (CGPoint )layoutPosition
@@ -821,64 +789,48 @@ - (ASStackLayoutAlignItems)parentAlignStyle {
821
789
}
822
790
823
791
- (void )setFlexWrap : (YGWrap)flexWrap {
824
- if (_flexWrap.exchange (flexWrap) != flexWrap) {
825
- ASLayoutElementStyleCallDelegate (ASYogaFlexWrapProperty);
826
- }
792
+ _flexWrap.store (flexWrap);
793
+ ASLayoutElementStyleCallDelegate (ASYogaFlexWrapProperty);
827
794
}
828
795
- (void )setFlexDirection : (ASStackLayoutDirection)flexDirection {
829
- if (_flexDirection.exchange (flexDirection) != flexDirection) {
830
- ASLayoutElementStyleCallDelegate (ASYogaFlexDirectionProperty);
831
- }
796
+ _flexDirection.store (flexDirection);
797
+ ASLayoutElementStyleCallDelegate (ASYogaFlexDirectionProperty);
832
798
}
833
799
- (void )setDirection : (YGDirection)direction {
834
- if (_direction.exchange (direction) != direction) {
835
- ASLayoutElementStyleCallDelegate (ASYogaDirectionProperty);
836
- }
800
+ _direction.store (direction);
801
+ ASLayoutElementStyleCallDelegate (ASYogaDirectionProperty);
837
802
}
838
803
- (void )setJustifyContent : (ASStackLayoutJustifyContent)justify {
839
- if (_justifyContent.exchange (justify) != justify) {
840
- ASLayoutElementStyleCallDelegate (ASYogaJustifyContentProperty);
841
- }
804
+ _justifyContent.store (justify);
805
+ ASLayoutElementStyleCallDelegate (ASYogaJustifyContentProperty);
842
806
}
843
807
- (void )setAlignItems : (ASStackLayoutAlignItems)alignItems {
844
- if (_alignItems.exchange (alignItems) != alignItems) {
845
- ASLayoutElementStyleCallDelegate (ASYogaAlignItemsProperty);
846
- }
808
+ _alignItems.store (alignItems);
809
+ ASLayoutElementStyleCallDelegate (ASYogaAlignItemsProperty);
847
810
}
848
811
- (void )setPositionType : (YGPositionType)positionType {
849
- if (_positionType.exchange (positionType) != positionType) {
850
- ASLayoutElementStyleCallDelegate (ASYogaPositionTypeProperty);
851
- }
812
+ _positionType.store (positionType);
813
+ ASLayoutElementStyleCallDelegate (ASYogaPositionTypeProperty);
852
814
}
853
- // / TODO: smart compare ASEdgeInsets instead of memory compare.
854
815
- (void )setPosition : (ASEdgeInsets)position {
855
- ASEdgeInsets oldValue = _position.exchange (position);
856
- if (0 != memcmp (&position, &oldValue, sizeof (ASEdgeInsets))) {
857
- ASLayoutElementStyleCallDelegate (ASYogaPositionProperty);
858
- }
816
+ _position.store (position);
817
+ ASLayoutElementStyleCallDelegate (ASYogaPositionProperty);
859
818
}
860
819
- (void )setMargin : (ASEdgeInsets)margin {
861
- ASEdgeInsets oldValue = _margin.exchange (margin);
862
- if (0 != memcmp (&margin, &oldValue, sizeof (ASEdgeInsets))) {
863
- ASLayoutElementStyleCallDelegate (ASYogaMarginProperty);
864
- }
820
+ _margin.store (margin);
821
+ ASLayoutElementStyleCallDelegate (ASYogaMarginProperty);
865
822
}
866
823
- (void )setPadding : (ASEdgeInsets)padding {
867
- ASEdgeInsets oldValue = _padding.exchange (padding);
868
- if (0 != memcmp (&padding, &oldValue, sizeof (ASEdgeInsets))) {
869
- ASLayoutElementStyleCallDelegate (ASYogaPaddingProperty);
870
- }
824
+ _padding.store (padding);
825
+ ASLayoutElementStyleCallDelegate (ASYogaPaddingProperty);
871
826
}
872
827
- (void )setBorder : (ASEdgeInsets)border {
873
- ASEdgeInsets oldValue = _border.exchange (border);
874
- if (0 != memcmp (&border, &oldValue, sizeof (ASEdgeInsets))) {
875
- ASLayoutElementStyleCallDelegate (ASYogaBorderProperty);
876
- }
828
+ _border.store (border);
829
+ ASLayoutElementStyleCallDelegate (ASYogaBorderProperty);
877
830
}
878
831
- (void )setAspectRatio : (CGFloat )aspectRatio {
879
- if (_aspectRatio.exchange (aspectRatio) != aspectRatio) {
880
- ASLayoutElementStyleCallDelegate (ASYogaAspectRatioProperty);
881
- }
832
+ _aspectRatio.store (aspectRatio);
833
+ ASLayoutElementStyleCallDelegate (ASYogaAspectRatioProperty);
882
834
}
883
835
// private (ASLayoutElementStylePrivate.h)
884
836
- (void )setParentAlignStyle : (ASStackLayoutAlignItems)style {
0 commit comments