Differences From Artifact [fd9ea3d6be]:
- File src/OFIntrospection.m — part of check-in [82b9b5f7c8] at 2012-07-17 23:59:52 on branch trunk — Add ivar introspection for the ObjFW runtime. (user: js, size: 7255) [annotate] [blame] [check-ins using]
To Artifact [e0bf0f6365]:
- File
src/OFIntrospection.m
— part of check-in
[1255f3a11a]
at
2012-08-10 20:08:24
on branch trunk
— Directly use the runtime's autorelease pools.
This greatly improves performance, as it gets rid of the overhead of
OFAutoreleasePool. (user: js, size: 7540) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
21 22 23 24 25 26 27 | #if defined(OF_APPLE_RUNTIME) # import <objc/runtime.h> #endif #import "OFIntrospection.h" #import "OFString.h" #import "OFArray.h" | < > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #if defined(OF_APPLE_RUNTIME) # import <objc/runtime.h> #endif #import "OFIntrospection.h" #import "OFString.h" #import "OFArray.h" #import "autorelease.h" #import "macros.h" @implementation OFMethod #if defined(OF_OBJFW_RUNTIME) - _initWithMethod: (struct objc_method*)method { self = [super init]; |
︙ | ︙ | |||
215 216 217 218 219 220 221 | } - initWithClass: (Class)class { self = [super init]; @try { | < | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | } - initWithClass: (Class)class { self = [super init]; @try { #if defined(OF_OBJFW_RUNTIME) struct objc_method_list *methodList; #elif defined(OF_APPLE_RUNTIME) Method *methodList; Ivar *ivarList; # ifdef OF_HAVE_PROPERTIES objc_property_t *propertyList; |
︙ | ︙ | |||
240 241 242 243 244 245 246 247 248 249 | #if defined(OF_OBJFW_RUNTIME) for (methodList = object_getClass(class)->methodlist; methodList != NULL; methodList = methodList->next) { int i; for (i = 0; i < methodList->count; i++) { OFMethod *method = [[OFMethod alloc] _initWithMethod: &methodList->methods[i]]; [classMethods addObject: [method autorelease]]; | > | > | > | > > | > | > | > | < < | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 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 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | #if defined(OF_OBJFW_RUNTIME) for (methodList = object_getClass(class)->methodlist; methodList != NULL; methodList = methodList->next) { int i; for (i = 0; i < methodList->count; i++) { void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] _initWithMethod: &methodList->methods[i]]; [classMethods addObject: [method autorelease]]; objc_autoreleasePoolPop(pool); } } for (methodList = class->methodlist; methodList != NULL; methodList = methodList->next) { int i; for (i = 0; i < methodList->count; i++) { void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] _initWithMethod: &methodList->methods[i]]; [instanceMethods addObject: [method autorelease]]; objc_autoreleasePoolPop(pool); } } if (class->ivars != NULL) { unsigned i; for (i = 0; i < class->ivars->count; i++) { void *pool = objc_autoreleasePoolPush(); OFInstanceVariable *ivar; ivar = [[OFInstanceVariable alloc] _initWithIvar: &class->ivars->ivars[i]]; [instanceVariables addObject: [ivar autorelease]]; objc_autoreleasePoolPop(pool); } } /* TODO: properties */ #elif defined(OF_APPLE_RUNTIME) methodList = class_copyMethodList(object_getClass(class), &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [classMethods addObject: [[[OFMethod alloc] _initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [instanceMethods addObject: [[[OFMethod alloc] _initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { free(methodList); } ivarList = class_copyIvarList(class, &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [instanceVariables addObject: [[[OFInstanceVariable alloc] _initWithIvar: ivarList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { free(ivarList); } propertyList = class_copyPropertyList(class, &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [properties addObject: [[[OFProperty alloc] _initWithProperty: propertyList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { free(propertyList); } #endif [classMethods makeImmutable]; [instanceMethods makeImmutable]; [instanceVariables makeImmutable]; #ifdef OF_HAVE_PROPERTIES [properties makeImmutable]; #endif } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |