@@ -82,6 +82,9 @@ - (instancetype)init {
82
82
83
83
#endif
84
84
85
+ #define Assert (_condition_, ...) \
86
+ if (__builtin_expect(!(_condition_), 0 )) { WARN (__VA_ARGS__); }
87
+
85
88
#define SkipSpace (charPtr ) while ( isspace(*(charPtr)) ) {++(charPtr);}
86
89
87
90
#define kDefaultSpace 8
@@ -154,7 +157,7 @@ static inline NSLayoutAttribute getAttr(char attrChar){
154
157
if (*format == ' $' ) {
155
158
++format;
156
159
it = _tryGetIndexValue (format, env, out);
157
- NSCAssert1 (*out, @" can't found indexValue at %s " , format);
160
+ Assert (*out, @" can't found indexValue at %s " , format);
158
161
return it;
159
162
} else if (!env->envIsArray ) { // dict $ may omit
160
163
it = _tryGetIndexValue (format, env, out);
@@ -183,13 +186,13 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
183
186
184
187
if (leftView == SUPER_TOKEN) { // [V]-|
185
188
leftView = [rightView superview ];
186
- NSCAssert (leftView, @" superview not exist!" );
189
+ Assert (leftView, @" superview not exist!" );
187
190
188
191
defAttr1 = defAttr2 = vertical ?
189
192
NSLayoutAttributeBottom : NSLayoutAttributeRight;
190
193
} else if (rightView == SUPER_TOKEN) { // |-[V]
191
194
rightView = [leftView superview ];
192
- NSCAssert (rightView, @" superview not exist!" );
195
+ Assert (rightView, @" superview not exist!" );
193
196
194
197
defAttr1 = defAttr2 = vertical ?
195
198
NSLayoutAttributeTop : NSLayoutAttributeLeft;
@@ -349,7 +352,7 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
349
352
}
350
353
// it's attr1
351
354
(*outPredicate)->attr1 = getAttr (*format);
352
- NSCAssert ((*outPredicate)->attr1 != 0, @"format error: unexpect attr type %c", *format);
355
+ Assert ((*outPredicate)->attr1 != 0 , @" format error: unexpect attr type %c " , *format);
353
356
format = identifierEnd;
354
357
}
355
358
}
@@ -387,7 +390,7 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
387
390
++format;
388
391
SkipSpace (format);
389
392
identifierEnd = analyzeConstant (format, env, &((*outPredicate)->multiplier ));
390
- NSCAssert ( identifierEnd != format, @" * should follow metric. at %s " , format);
393
+ Assert ( identifierEnd != format, @" * should follow metric. at %s " , format);
391
394
format = identifierEnd;
392
395
}
393
396
@@ -404,7 +407,7 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
404
407
++format;
405
408
SkipSpace (format);
406
409
identifierEnd = analyzeConstant (format, env, &((*outPredicate)->priority ));
407
- NSCAssert ( identifierEnd != format, @" @ should follow priority. at %s " , format);
410
+ Assert ( identifierEnd != format, @" @ should follow priority. at %s " , format);
408
411
format = identifierEnd;
409
412
}
410
413
@@ -431,7 +434,7 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
431
434
if (*format == ' $' ) ++format;
432
435
format = _tryGetIndexValue (format, env, outView);
433
436
// outView should be UIView or layoutGuide
434
- NSCAssert (*outView, @" can't found identifier at %s !" , format);
437
+ Assert (*outView, @" can't found identifier at %s !" , format);
435
438
436
439
SkipSpace (format);
437
440
if (*format == ' !' ) { (*outView).translatesAutoresizingMaskIntoConstraints = NO ; ++format; SkipSpace (format); }
@@ -457,11 +460,11 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
457
460
// set H or V according to label. if not set, don't change.(init default to H)
458
461
if (*format == ' V' ) {
459
462
env->vertical = true ;
460
- NSCAssert (*(format+1 ) == ':', @"V should followed by :!");
463
+ Assert (*(format+1 ) == ' :' , @" V should followed by :!" );
461
464
format += 2 ;
462
465
} else if (*format == ' H' ) {
463
466
env->vertical = false ;
464
- NSCAssert (*(format+1 ) == ':', @"H should followed by :!");
467
+ Assert (*(format+1 ) == ' :' , @" H should followed by :!" );
465
468
format += 2 ;
466
469
}
467
470
@@ -512,7 +515,7 @@ static void buildConstraints(id leftView, NSArray* predicates, id rightView, boo
512
515
}
513
516
goto CONTINUE_LOOP;
514
517
}
515
- NSCAssert (NO , @" shouldn't happen!" );
518
+ Assert (NO , @" shouldn't happen!" );
516
519
}
517
520
case ' [' : { // view statement
518
521
View:
0 commit comments