Do not check nil block, useless in our use case

This commit is contained in:
DreamPiggy 2023-01-06 19:34:37 +08:00
parent 57403c9d3f
commit fdd9a98210
2 changed files with 8 additions and 12 deletions

View File

@ -28,20 +28,20 @@
/// Submits a block for execution and returns after that block finishes executing.
/// - Parameter block: The block that contains the work to perform.
- (void)sync:(nullable dispatch_block_t)block;
- (void)sync:(nonnull NS_NOESCAPE dispatch_block_t)block;
/// Submits a block for execution and returns after that block finishes executing. When the current enqueued queue matching the callback queue, call the block immediately.
/// @warning This will not works when using `dispatch_set_target_queue` or recursive queue context.
/// - Parameter block: The block that contains the work to perform.
- (void)syncSafe:(nullable dispatch_block_t)block;
- (void)syncSafe:(nonnull NS_NOESCAPE dispatch_block_t)block;
/// Schedules a block asynchronously for execution.
/// - Parameter block: The block that contains the work to perform.
- (void)async:(nullable dispatch_block_t)block;
- (void)async:(nonnull NS_NOESCAPE dispatch_block_t)block;
/// Schedules a block asynchronously for execution. When the current enqueued queue matching the callback queue, call the block immediately.
/// @warning This will not works when using `dispatch_set_target_queue` or recursive queue context.
/// - Parameter block: The block that contains the work to perform.
- (void)asyncSafe:(nullable dispatch_block_t)block;
- (void)asyncSafe:(nonnull NS_NOESCAPE dispatch_block_t)block;
@end

View File

@ -55,13 +55,11 @@ static void SDReleaseBlock(void *context) {
return queue;
}
- (void)sync:(dispatch_block_t)block {
if (!block) return;
- (void)sync:(nonnull NS_NOESCAPE dispatch_block_t)block {
dispatch_sync(self.queue, block);
}
- (void)syncSafe:(dispatch_block_t)block {
if (!block) return;
- (void)syncSafe:(nonnull NS_NOESCAPE dispatch_block_t)block {
// Special handle for main queue, faster
const char *currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
if (currentLabel && currentLabel == dispatch_queue_get_label(dispatch_get_main_queue())) {
@ -78,13 +76,11 @@ static void SDReleaseBlock(void *context) {
}
}
- (void)async:(dispatch_block_t)block {
if (!block) return;
- (void)async:(nonnull NS_NOESCAPE dispatch_block_t)block {
dispatch_async(self.queue, block);
}
- (void)asyncSafe:(dispatch_block_t)block {
if (!block) return;
- (void)asyncSafe:(nonnull NS_NOESCAPE dispatch_block_t)block {
// Special handle for main queue, faster
const char *currentLabel = dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL);
if (currentLabel && currentLabel == dispatch_queue_get_label(dispatch_get_main_queue())) {