39
39
static NSNumber *kPositiveInfinity ;
40
40
static NSNumber *kNegativeInfinity ;
41
41
42
- static id kStaticStringCache ;
43
-
44
42
45
43
@implementation SBJsonStreamWriter
46
44
@@ -57,16 +55,6 @@ + (void)initialize {
57
55
kNegativeInfinity = [NSNumber numberWithDouble: -INFINITY];
58
56
kTrue = [NSNumber numberWithBool: YES ];
59
57
kFalse = [NSNumber numberWithBool: NO ];
60
-
61
- Class cacheClass = NSClassFromString (@" NSCache" );
62
- if (cacheClass) {
63
- NSLog (@" %s NSCache supported" , __FUNCTION__);
64
- kStaticStringCache = [[cacheClass alloc ] init ];
65
- }else {
66
- NSLog (@" %s NSCache not supported" , __FUNCTION__);
67
- }
68
-
69
-
70
58
}
71
59
72
60
#pragma mark Housekeeping
@@ -79,6 +67,7 @@ - (id)init {
79
67
maxDepth = 32u ;
80
68
stateStack = [[NSMutableArray alloc ] initWithCapacity: maxDepth];
81
69
state = [SBJsonStreamWriterStateStart sharedInstance ];
70
+ cache = [[NSMutableDictionary alloc ] initWithCapacity: 32 ];
82
71
}
83
72
return self;
84
73
}
@@ -87,6 +76,7 @@ - (void)dealloc {
87
76
self.error = nil ;
88
77
self.state = nil ;
89
78
[stateStack release ];
79
+ [cache release ];
90
80
[super dealloc ];
91
81
}
92
82
@@ -294,7 +284,7 @@ - (BOOL)writeString:(NSString*)string {
294
284
[state appendSeparator: self ];
295
285
if (humanReadable) [state appendWhitespace: self ];
296
286
297
- NSMutableData *buf = [kStaticStringCache objectForKey: string];
287
+ NSMutableData *buf = [cache objectForKey: string];
298
288
if (!buf) {
299
289
300
290
NSUInteger len = [string lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
@@ -321,7 +311,7 @@ - (BOOL)writeString:(NSString*)string {
321
311
[buf appendBytes: utf8 + written length: i - written];
322
312
323
313
[buf appendBytes: " \" " length: 1 ];
324
- [kStaticStringCache setObject: buf forKey: string];
314
+ [cache setObject: buf forKey: string];
325
315
}
326
316
327
317
[delegate writer: self appendBytes: [buf bytes ] length: [buf length ]];
0 commit comments