Do not call handler blocks if they are nil

This commit is contained in:
Levin Li 2021-11-17 21:35:49 +08:00 committed by Levin Li
parent e68b97d58b
commit 5b151c5fa0
12 changed files with 32 additions and 33 deletions

View file

@ -1146,7 +1146,7 @@ compare(id elem1, id elem2, void* context)
}
if (range.length == 1)
{
switch (CALL_BLOCK(comparator, key, [self objectAtIndex: range.location]))
switch (CALL_NON_NULL_BLOCK(comparator, key, [self objectAtIndex: range.location]))
{
case NSOrderedSame:
return range.location;
@ -1212,7 +1212,7 @@ compare(id elem1, id elem2, void* context)
* For a search from the left, we'd have the correct index anyways. Check
* whether it's equal to the key and return NSNotFound otherwise
*/
return (NSOrderedSame == CALL_BLOCK(comparator,
return (NSOrderedSame == CALL_NON_NULL_BLOCK(comparator,
key, [self objectAtIndex: index]) ? index : NSNotFound);
}
// Never reached
@ -1858,10 +1858,10 @@ compare(id elem1, id elem2, void* context)
}
else // call block directly
# endif
if (CALL_BLOCK(predicate, obj, count, &shouldStop))
if (CALL_NON_NULL_BLOCK(predicate, obj, count, &shouldStop))
{
/* TODO: It would be more efficient to collect an NSRange and only
* pass it to the index set when CALL_BLOCK returned NO. */
* pass it to the index set when CALL_NON_NULL_BLOCK returned NO. */
[set addIndex: count];
}
if (shouldStop)
@ -1959,7 +1959,7 @@ compare(id elem1, id elem2, void* context)
}
else // call block directly
# endif
if (CALL_BLOCK(predicate, obj, count, &shouldStop))
if (CALL_NON_NULL_BLOCK(predicate, obj, count, &shouldStop))
{
index = count;
shouldStop = YES;