Differences From Artifact [acdacb86e1]:
- File src/OFNotificationCenter.m — part of check-in [7413a728a7] at 2024-04-03 02:16:03 on branch trunk — Change license to LGPLv3 only (user: js, size: 8352) [annotate] [blame] [check-ins using] [more...]
To Artifact [eb7640502b]:
- File
src/OFNotificationCenter.m
— part of check-in
[ff3a60cc12]
at
2024-04-28 08:36:55
on branch trunk
— Use @synchronized over OFMutex in a few places
These places are not super performance critical and the code becomes a
lot more readable.Actually using @synchronized in ObjFW itself is also a good motivation
to optimize it further. (user: js, size: 7846) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
20 21 22 23 24 25 26 | #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" | < < < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFSet.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @interface OFDefaultNotificationCenter: OFNotificationCenter @end |
︙ | ︙ | |||
183 184 185 186 187 188 189 | } - (instancetype)init { self = [super init]; @try { | < < < < < < < < < | < < < < | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | } - (instancetype)init { self = [super init]; @try { _handles = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_handles release]; [super dealloc]; } - (void)of_addObserver: (OFNotificationCenterHandle *)handle { @synchronized (_handles) { OFMutableSet *handlesForName = [_handles objectForKey: handle->_name]; if (handlesForName == nil) { handlesForName = [OFMutableSet set]; [_handles setObject: handlesForName forKey: handle->_name]; } [handlesForName addObject: handle]; } } - (void)addObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (id)object { |
︙ | ︙ | |||
278 279 280 281 282 283 284 | if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); | < | | | < < < < < < < < | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; @synchronized (_handles) { OFNotificationName name = [[handle->_name copy] autorelease]; OFMutableSet *handlesForName = [_handles objectForKey: name]; [handlesForName removeObject: handle]; if (handlesForName.count == 0) [_handles removeObjectForKey: name]; } objc_autoreleasePoolPop(pool); } - (void)removeObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name |
︙ | ︙ | |||
325 326 327 328 329 330 331 | } - (void)postNotification: (OFNotification *)notification { void *pool = objc_autoreleasePoolPush(); OFMutableArray *matchedHandles = [OFMutableArray array]; | < < < | < < < < | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | } - (void)postNotification: (OFNotification *)notification { void *pool = objc_autoreleasePoolPush(); OFMutableArray *matchedHandles = [OFMutableArray array]; @synchronized (_handles) { for (OFNotificationCenterHandle *handle in [_handles objectForKey: notification.name]) if (handle->_object == nil || handle->_object == notification.object) [matchedHandles addObject: handle]; } for (OFNotificationCenterHandle *handle in matchedHandles) { #ifdef OF_HAVE_BLOCKS if (handle->_block != NULL) handle->_block(notification); else { #endif |
︙ | ︙ |