Skip to content

Commit cab1ea8

Browse files
committed
Moved the +load logic from JSONDecoder in to jk_collectionClassLoadTimeInitialization(). Missed the JSONDecoder +load stuff on the last commit. Related to issue johnezang#23.
1 parent 353b124 commit cab1ea8

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

JSONKit.m

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -614,22 +614,37 @@ - (void)releaseState;
614614
// Basically, there seem to be a problem with using +load in static libraries on iOS. However, __attribute__ ((constructor)) does work correctly.
615615
// Since we do not require anything "special" that +load provides, and we can accomplish the same thing using __attribute__ ((constructor)), the +load logic was moved here.
616616

617-
static Class _JKArrayClass = NULL;
618-
static size_t _JKArrayInstanceSize = 0UL;
619-
static Class _JKDictionaryClass = NULL;
620-
static size_t _JKDictionaryInstanceSize = 0UL;
617+
static Class _JKArrayClass = NULL;
618+
static size_t _JKArrayInstanceSize = 0UL;
619+
static Class _JKDictionaryClass = NULL;
620+
static size_t _JKDictionaryInstanceSize = 0UL;
621+
622+
// For JSONDecoder...
623+
static Class _jk_NSNumberClass = NULL;
624+
static NSNumberAllocImp _jk_NSNumberAllocImp = NULL;
625+
static NSNumberInitWithUnsignedLongLongImp _jk_NSNumberInitWithUnsignedLongLongImp = NULL;
621626

622627
extern void jk_collectionClassLoadTimeInitialization(void) __attribute__ ((constructor));
623628

624629
void jk_collectionClassLoadTimeInitialization(void) {
625-
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Though technically not required, the run time environment at +load time may be less than ideal.
630+
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Though technically not required, the run time environment at load time initialization may be less than ideal.
626631

627632
_JKArrayClass = objc_getClass("JKArray");
628633
_JKArrayInstanceSize = jk_max(16UL, class_getInstanceSize(_JKArrayClass));
629634

630635
_JKDictionaryClass = objc_getClass("JKDictionary");
631636
_JKDictionaryInstanceSize = jk_max(16UL, class_getInstanceSize(_JKDictionaryClass));
632637

638+
// For JSONDecoder...
639+
_jk_NSNumberClass = [NSNumber class];
640+
_jk_NSNumberAllocImp = (NSNumberAllocImp)[NSNumber methodForSelector:@selector(alloc)];
641+
642+
// Hacktacular. Need to do it this way due to the nature of class clusters.
643+
id temp_NSNumber = [NSNumber alloc];
644+
_jk_NSNumberInitWithUnsignedLongLongImp = (NSNumberInitWithUnsignedLongLongImp)[temp_NSNumber methodForSelector:@selector(initWithUnsignedLongLong:)];
645+
[[temp_NSNumber init] release];
646+
temp_NSNumber = NULL;
647+
633648
[pool release]; pool = NULL;
634649
}
635650

@@ -2052,26 +2067,6 @@ JK_STATIC_INLINE void jk_cache_age(JKParseState *parseState) {
20522067
#pragma mark -
20532068
@implementation JSONDecoder
20542069

2055-
static Class _jk_NSNumberClass;
2056-
static NSNumberAllocImp _jk_NSNumberAllocImp;
2057-
static NSNumberInitWithUnsignedLongLongImp _jk_NSNumberInitWithUnsignedLongLongImp;
2058-
2059-
+ (void)load
2060-
{
2061-
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // Though technically not required, the run time environment at +load time may be less than ideal.
2062-
2063-
_jk_NSNumberClass = [NSNumber class];
2064-
_jk_NSNumberAllocImp = (NSNumberAllocImp)[NSNumber methodForSelector:@selector(alloc)];
2065-
2066-
// Hacktacular. Need to do it this way due to the nature of class clusters.
2067-
id temp_NSNumber = [NSNumber alloc];
2068-
_jk_NSNumberInitWithUnsignedLongLongImp = (NSNumberInitWithUnsignedLongLongImp)[temp_NSNumber methodForSelector:@selector(initWithUnsignedLongLong:)];
2069-
[[temp_NSNumber init] release];
2070-
temp_NSNumber = NULL;
2071-
2072-
[pool release]; pool = NULL;
2073-
}
2074-
20752070
+ (id)decoder
20762071
{
20772072
return([self decoderWithParseOptions:JKParseOptionStrict]);

0 commit comments

Comments
 (0)