Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 390 lines (269 sloc) 39.176 kB
8339b27 @johnezang Fixed a serious crashing bug. Fixed a memory leak. Fixed an off by …
authored
1 # JSONKit Changelog
2
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
3 ## Version 1.X ????/??/??
4
5 **IMPORTANT:** The following changelog notes are a work in progress. They apply to the work done on JSONKit post v1.4. Since JSONKit itself is inbetween versions, these changelog notes are subject to change, may be wrong, and just about everything else you could expect at this point in development.
6
7 ### New Features
8
9 * When `JKSerializeOptionPretty` is enabled, JSONKit now sorts the keys.
10
1b123b6 @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
11 * Normally, JSONKit can only serialize NSNull, NSNumber, NSString, NSArray, and NSDictioonary like objects. It is now possible to serialize an object of any class via either a delegate or a `^` block.
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
12
1b123b6 @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
13 The delegate or `^` block must return an object that can be serialized by JSONKit, however, otherwise JSONKit will fail to serialize the object. In other words, JSONKit tries to serialize an unsupported class of the object just once, and if the delegate or ^block returns another unsupported class, the second attempt to serialize will fail. In practice, this is not a problem at all, but it does prevent endless recursive attempts to serialize an unsupported class.
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
14
15 This makes it trivial to serialize objects like NSDate or NSData. A NSDate object can be formatted using a NSDateFormatter to return a ISO-8601 `YYYY-MM-DDTHH:MM:SS.sssZ` type object, for example. Or a NSData object could be Base64 encoded.
16
17 This greatly simplifies things when you have a complex, nested objects with objects that do not belong to the classes that JSONKit can serialize.
18
1b123b6 @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
19 It should be noted that the same caching that JSONKit does for the supported class types also applies to the objects of an unsupported class- if the same object is serialized more than once and the object is still in the serialization cache, JSONKit will copy the previous serialization result instead of invoking the delegate or `^` block again. Therefore, you should not expect or depend on your delegate or block being called each time the same object needs to be serialized AND the delegate or block MUST return a "formatted object" that is STRICTLY invariant (that is to say the same object must always return the exact same formatted output).
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
20
21 To serialize NSArray or NSDictionary objects using a delegate–
22
23 **NOTE:** The delegate is based a single argument, the object with the unsupported class, and the supplied `selector` method must be one that accepts a single `id` type argument (i.e., `formatObject:`).
24 **IMPORTANT:** The `^` block MUST return an object with a class that can be serialized by JSONKit, otherwise the serialization will fail.
25
26 <pre>
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
27 &#x200b;- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError \*\*)error;
28 &#x200b;- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingDelegate:(id)delegate selector:(SEL)selector error:(NSError \*\*)error;
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
29 </pre>
30
31 To serialize NSArray or NSDictionary objects using a `^` block&ndash;
32
33 **NOTE:** The block is passed a single argument, the object with the unsupported class.
34 **IMPORTANT:** The `^` block MUST return an object with a class that can be serialized by JSONKit, otherwise the serialization will fail.
35
36 <pre>
f8877a5 @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
37 &#x200b;- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(&#x005E;)(id object))block error:(NSError \*\*)error;
38 &#x200b;- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions serializeUnsupportedClassesUsingBlock:(id(&#x005E;)(id object))block error:(NSError \*\*)error;
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
39 </pre>
40
41 Example using the delegate way:
42
43 <pre>
44 @interface MYFormatter : NSObject {
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
45 NSDateFormatter \*outputFormatter;
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
46 }
47 @end
48 &#x200b;
49 @implementation MYFormatter
50 -(id)init
51 {
52 if((self = [super init]) == NULL) { return(NULL); }
53 if((outputFormatter = [[NSDateFormatter alloc] init]) == NULL) { [self autorelease]; return(NULL); }
54 [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];
55 return(self);
56 }
57 &#x200b;
58 -(void)dealloc
59 {
60 if(outputFormatter != NULL) { [outputFormatter release]; outputFormatter = NULL; }
61 [super dealloc];
62 }
63 &#x200b;
64 -(id)formatObject:(id)object
65 {
66 if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); }
67 return(NULL);
68 }
69 @end
70 &#x200b;
71 {
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
72 MYFormatter \*myFormatter = [[[MYFormatter alloc] init] autorelease];
73 NSArray \*array = [NSArray arrayWithObject:[NSDate dateWithTimeIntervalSinceNow:0.0]];
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
74
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
75 NSString \*jsonString = NULL;
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
76 jsonString = [array JSONStringWithOptions:JKSerializeOptionNone
8bdc6bf @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
77 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serializeUnsupportedClassesUsingDelegate:myFormatter
78 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selector:@selector(formatObject:)
79 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error:NULL];
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
80 NSLog(@"jsonString: '%@'", jsonString);
81 // 2011-03-25 11:42:16.175 formatter_example[59120:903] jsonString: '["2011-03-25T11:42:16.175-0400"]'
82 }
83 </pre>
84
85 Example using the `^` block way:
86
87 <pre>
88 {
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
89 NSDateFormatter \*outputFormatter = [[[NSDateFormatter alloc] init] autorelease];
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
90 [outputFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZ"];
91 &#x200b;
92 jsonString = [array JSONStringWithOptions:encodeOptions
f8877a5 @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
93 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serializeUnsupportedClassesUsingBlock:&#x005E;id(id object) {
8bdc6bf @johnezang More github markdown parsing hackery to CHANGELOG.md...
authored
94 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if([object isKindOfClass:[NSDate class]]) { return([outputFormatter stringFromDate:object]); }
95 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return(NULL);
96 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
97 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error:NULL];
e06349e @johnezang Update CHANGELOG.md and include an example of the new unsupported cla…
authored
98 NSLog(@"jsonString: '%@'", jsonString);
99 // 2011-03-25 11:49:56.434 json_parse[59167:903] jsonString: '["2011-03-25T11:49:56.434-0400"]'
100 }
101 </pre>
102
103 ### Major Changes
104
105 * The way that JSONKit implements the collection classes was modified. Specifically, JSONKit now follows the same strategy that the Cocoa collection classes use, which is to have a single subclass of the mutable collection class. This concrete subclass has an ivar bit that determines whether or not that instance is mutable, and when an immutable instance receives a mutating message, it throws an exception.
106
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
107 ## Version 1.4 2011/23/03
108
109 ### Highlights
110
111 * JSONKit v1.4 significantly improves the performance of serializing and deserializing. Deserializing is 23% faster than Apples binary `.plist`, and an amazing 549% faster than Apples binary `.plist` when serializing.
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
112
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
113 ### New Features
114
115 * JSONKit can now return mutable collection classes.
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
116 * The `JKSerializeOptionFlags` option `JKSerializeOptionPretty` was implemented.
117 * It is now possible to serialize a single [`NSString`][NSString]. This functionality was requested in issue #4 and issue #11.
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
118
119 ### Deprecated Methods
120
121 * The following `JSONDecoder` methods are deprecated beginning with JSONKit v1.4 and will be removed in a later release&ndash;
122
123 <pre>
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
124 &#x200b;- (id)parseUTF8String:(const unsigned char \*)string length:(size_t)length;
3da8086 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks... mi…
authored
125 &#x200b;- (id)parseUTF8String:(const unsigned char \*)string length:(size_t)length error:(NSError \*\*)error;
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
126 &#x200b;- (id)parseJSONData:(NSData \*)jsonData;
3da8086 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks... mi…
authored
127 &#x200b;- (id)parseJSONData:(NSData \*)jsonData error:(NSError \*\*)error;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
128 </pre>
129
130 The JSONKit v1.4 <code>objectWith&hellip;</code> methods should be used instead.
131
132 ### NEW API's
133
134 * The following methods were added to `JSONDecoder`&ndash;
135
136 These methods replace their deprecated <code>parse&hellip;</code> counterparts and return immutable collection objects.
137
138 <pre>
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
139 &#x200b;- (id)objectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length;
140 &#x200b;- (id)objectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length error:(NSError \*\*)error;
141 &#x200b;- (id)objectWithData:(NSData \*)jsonData;
142 &#x200b;- (id)objectWithData:(NSData \*)jsonData error:(NSError \*\*)error;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
143 </pre>
144
145 These methods are the same as their <code>objectWith&hellip;</code> counterparts except they return mutable collection objects.
146
147 <pre>
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
148 &#x200b;- (id)mutableObjectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length;
149 &#x200b;- (id)mutableObjectWithUTF8String:(const unsigned char \*)string length:(NSUInteger)length error:(NSError \*\*)error;
150 &#x200b;- (id)mutableObjectWithData:(NSData \*)jsonData;
151 &#x200b;- (id)mutableObjectWithData:(NSData \*)jsonData error:(NSError \*\*)error;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
152 </pre>
153
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
154 * The following methods were added to `NSString (JSONKitDeserializing)`&ndash;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
155
156 These methods are the same as their <code>objectFrom&hellip;</code> counterparts except they return mutable collection objects.
157
158 <pre>
159 &#x200b;- (id)mutableObjectFromJSONString;
160 &#x200b;- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
161 &#x200b;- (id)mutableObjectFromJSONStringWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError \*\*)error;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
162 </pre>
163
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
164 * The following methods were added to `NSData (JSONKitDeserializing)`&ndash;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
165
166 These methods are the same as their <code>objectFrom&hellip;</code> counterparts except they return mutable collection objects.
167
168 <pre>
169 &#x200b;- (id)mutableObjectFromJSONData;
170 &#x200b;- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags;
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
171 &#x200b;- (id)mutableObjectFromJSONDataWithParseOptions:(JKParseOptionFlags)parseOptionFlags error:(NSError \*\*)error;
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
172 </pre>
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
173
174 * The following methods were added to `NSString (JSONKitSerializing)`&ndash;
175
176 These methods are for those uses that need to serialize a single [`NSString`][NSString]&ndash;
177
178 <pre>
0395bf9 @johnezang Try to clean up githubs markdown parsing of *s in <pre> blocks...
authored
179 &#x200b;- (NSData \*)JSONData;
180 &#x200b;- (NSData \*)JSONDataWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError \*\*)error;
181 &#x200b;- (NSString \*)JSONString;
182 &#x200b;- (NSString \*)JSONStringWithOptions:(JKSerializeOptionFlags)serializeOptions includeQuotes:(BOOL)includeQuotes error:(NSError \*\*)error;
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
183 </pre>
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
184
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
185 ### Bug Fixes
186
187 * JSONKit has a fast and a slow path for parsing JSON Strings. The slow path is needed whenever special string processing is required, such as the conversion of `\` escape sequences or ill-formed UTF-8. Although the slow path had a check for characters < `0x20`, which are not permitted by the [RFC 4627][], there was a bug such that the condition was never actually checked. As a result, JSONKit would have incorrectly accepted JSON that contained characters < `0x20` if it was using the slow path to process a JSON String.
188 * The low surrogate in a <code>\u<i><b>high</b></i>\u<i><b>low</b></i></code> escape sequence in a JSON String was incorrectly treating `dfff` as ill-formed Unicode. This was due to a comparison that used `>= 0xdfff` instead of `> 0xdfff` as it should have.
189 * `JKParseOptionLooseUnicode` was not properly honored when parsing some types of ill-formed Unicode in <code>\u<i><b>HHHH</b></i></code> escapes in JSON Strings.
190
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
191 ### Important Notes
192
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
193 * JSONKit v1.4 now uses custom concrete subclasses of [`NSArray`][NSArray], [`NSMutableArray`][NSMutableArray], [`NSDictionary`][NSDictionary], and [`NSMutableDictionary`][NSMutableDictionary]&mdash; `JKArray`, `JKMutableArray`, `JKDictionary`, and `JKMutableDictionary`. respectively. These classes are internal and private to JSONKit, you should not instantiate objects from these classes directly.
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
194
195 In theory, these custom classes should behave exactly the same as the respective Foundation / Cocoa counterparts.
196
197 As usual, in practice may have non-linear excursions from what theory predicts. It is also virtually impossible to properly test or predict how these custom classes will interact with software in the wild.
198
199 Most likely, if you do encounter a problem, it will happen very quickly, and you should report a bug via the [github.com JSONKit Issue Tracker][bugtracker].
200
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
201 In addition to the required class cluster primitive methods, the custom collection classes also include support for [`NSFastEnumeration`][NSFastEnumeration], along with methods that support the bulk retrieval of the objects contents.
202
203 #### Exceptions Thrown
204
205 The JSONKit collection classes will throw the same exceptions for the same conditions as their respective Foundation counterparts. If you find a discrepancy, please report a bug via the [github.com JSONKit Issue Tracker][bugtracker].
206
207 #### Multithreading Safety
208
209 The same multithreading rules and caveats for the Foundation collection classes apply to the JSONKit collection classes. Specifically, it should be safe to use the immutable collections from multiple threads concurrently.
210
211 The mutable collections can be used from multiple threads as long as you provide some form of mutex barrier that ensures that if a thread needs to mutate the collection, then it has exclusive access to the collection&ndash; no other thread can be reading from or writing to the collection until the mutating thread has finished. Failure to ensure that there are no other threads reading or writing from the mutable collection when a thread mutates the collection will result in `undefined` behavior.
212
213 #### Mutable Collection Notes
214
215 The mutable versions of the collection classes are meant to be used when you need to make minor modifications to the collection. Neither `JKMutableArray` or `JKMutableDictionary` have been optimized for nor are they intended to be used in situations where you are adding a large number of objects or new keys&ndash; these types of operations will cause both classes to frequently reallocate the memory used to hold the objects in the collection.
216
217 #### `JKMutableArray` Usage Notes
218
219 * You should minimize the number of new objects you added to the array. The array is not designed for high performance insertion and removal of objects. If the array does not have any extra capacity it must reallocate the backing store. When the array is forced to grow the backing store, it currently adds an additional 16 slots worth of spare capacity. The array is instantiated without any extra capacity on the assumption that dictionaries are going to be mutated more than arrays. The array never shrinks the backing store.
220
221 * Replacing objects in the array via [`-replaceObjectAtIndex:withObject:`][-replaceObjectAtIndex:withObject:] is very fast since the array simply releases the current object at the index and replaces it with the new object.
222
223 * Inserting an object in to the array via [`-insertObject:atIndex:`][-insertObject:atIndex:] cause the array to [`memmove()`][memmove] all the objects up one slot from the insertion index. This means this operation is fastest when inserting objects at the last index since no objects need to be moved.
224
225 * Removing an object from the array via [`-removeObjectAtIndex:`][-removeObjectAtIndex:] causes the array to [`memmove()`][memmove] all the objects down one slot from the removal index. This means this operation is fastest when removing objects at the last index since no objects need to be moved. The array will not resize its backing store to a smaller size.
226
227 * [`-copy`][-copy] and [`-mutableCopy`][-mutableCopy] will instantiate a new [`NSArray`][NSArray] or [`NSMutableArray`][NSMutableArray] class object, respectively, with the contents of the receiver.
228
229 #### `JKMutableDictionary` Usage Notes
230
231 * You should minimize the number of new keys you add to the dictionary. If the number of items in the dictionary exceeds a threshold value it will trigger a resizing operation. To do this, the dictionary must allocate a new, larger backing store, and then re-add all the items in the dictionary by rehashing them to the size of the newer, larger store. This is an expensive operation. While this is a limitation of nearly all hash tables, the capacity for the hash table used by `JKMutableDictionary` has been chosen to minimize the amount of memory used since it is anticipated that most dictionaries will not grow significantly once they are instantiated.
232
233 * If the key already exists in the dictionary and you change the object associated with it via [`-setObject:forKey:`][-setObject:forKey:], this will not cause any performance problems or trigger a hash table resize.
234
235 * Removing a key from the dictionary via [`-removeObjectForKey:`][-removeObjectForKey:] will not cause any performance problems. However, the dictionary will not resize its backing store to the smaller size.
236
237 * [`-copy`][-copy] and [`-mutableCopy`][-mutableCopy] will instantiate a new [`NSDictionary`][NSDictionary] or [`NSMutableDictionary`][NSMutableDictionary] class object, respectively, with the contents of the receiver.
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
238
239 ### Major Changes
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
240
241 * The `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` pre-processor define flag that was added to JSONKit v1.3 has been removed.
242
243 `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` was added in JSONKit v1.3 as a temporary work around. While the author was aware of other ways to fix the particular problem caused by the usage of "transfer of ownership callbacks" with Core Foundation classes, the fix provided in JSONKit v1.3 was trivial to implement. This allowed people who needed that functionality to use JSONKit while a proper solution to the problem was worked on. JSONKit v1.4 is the result of that work.
244
245 JSONKit v1.4 no longer uses the Core Foundation collection classes [`CFArray`][CFArray] and [`CFDictionary`][CFDictionary]. Instead, JSONKit v1.4 contains a concrete subclass of [`NSArray`][NSArray] and [`NSDictionary`][NSDictionary]&ndash; `JKArray` and `JKDictionary`, respectively. As a result, JSONKit has complete control over the behavior of how items are added and managed within an instantiated collection object. The `JKArray` and `JKDictionary` classes are private to JSONKit, you should not instantiate them direction. Since they are concrete subclasses of their respective collection class cluster, they behave and act exactly the same as [`NSArray`][NSArray] and [`NSDictionary`][NSDictionary].
246
247 The first benefit is that the "transfer of ownership" object ownership policy can now be safely used. Because the JSONKit collection objects understand that some methods, such as [`-mutableCopy`][-mutableCopy], should not inherit the same "transfer of ownership" object ownership policy, but must follow the standard Cocoa object ownership policy. The "transfer of ownership" object ownership policy reduces the number of [`-retain`][-retain] and [`-release`][-release] calls needed to add an object to a collection, and when creating a large number of objects very quickly (as you would expect when parsing JSON), this can result in a non-trivial amount of time. Eliminating these calls means faster JSON parsing.
248
249 A second benefit is that the author encountered some unexpected behavior when using the [`CFDictionaryCreate`][CFDictionaryCreate] function to create a dictionary and the `keys` argument contained duplicate keys. This required JSONKit to de-duplicate the keys and values before calling [`CFDictionaryCreate`][CFDictionaryCreate]. Unfortunately, JSONKit always had to scan all the keys to make sure there were no duplicates, even though 99.99% of the time there were none. This was less than optimal, particularly because one of the solutions to this particular problem is to use a hash table to perform the de-duplication. Now JSONKit can do the de-duplication while it is instantiating the dictionary collection, solving two problems at once.
250
251 Yet another benefit is that the recently instantiated object cache that JSONKit uses can be used to cache information about the keys used to create dictionary collections, in particular a keys [`-hash`][-hash] value. For a lot of real world JSON, this effectively means that the [`-hash`][-hash] for a key is calculated once, and that value is reused again and again when creating dictionaries. Because all the information required to create the hash table used by `JKDictionary` is already determined at the time the `JKDictionary` object is instantiated, populating the `JKDictionary` is now a very tight loop that only has to call [`-isEqual:`][-isEqual:] on the rare occasions that the JSON being parsed contains duplicate keys. Since the functions that handle this logic are all declared `static` and are internal to JSONKit, the compiler can heavily optimize this code.
252
253 What does this mean in terms of performance? JSONKit was already fast, but now, it's even faster. Below is some benchmark times for [`twitter_public_timeline.json`][twitter_public_timeline.json] in [samsoffes / json-benchmarks](https://github.com/samsoffes/json-benchmarks), where _read_ means to convert the JSON to native Objective-C objects, and _write_ means to convert the native Objective-C to JSON&mdash;
254
255 <pre>
256 v1.3 read : min: 456.000 us, avg: 460.056 us, char/s: 53341332.36 / 50.870 MB/s
257 v1.3 write: min: 150.000 us, avg: 151.816 us, char/s: 161643041.58 / 154.155 MB/s</pre>
258
259 <pre>
260 v1.4 read : min: 285.000 us, avg: 288.603 us, char/s: 85030301.14 / 81.091 MB/s
261 v1.4 write: min: 127.000 us, avg: 129.617 us, char/s: 189327017.29 / 180.556 MB/s</pre>
262
263 JSONKit v1.4 is nearly 60% faster at reading and 17% faster at writing than v1.3.
264
265 The following is the JSON test file taken from the project available at [this blog post](http://psionides.jogger.pl/2010/12/12/cocoa-json-parsing-libraries-part-2/). The keys and information contained in the JSON was anonymized with random characters. Since JSONKit relies on its recently instantiated object cache for a lot of its performance, this JSON happens to be "the worst corner case possible".
266
267 <pre>
268 v1.3 read : min: 5222.000 us, avg: 5262.344 us, char/s: 15585260.10 / 14.863 MB/s
269 v1.3 write: min: 1253.000 us, avg: 1259.914 us, char/s: 65095712.88 / 62.080 MB/s</pre>
270
271 <pre>
272 v1.4 read : min: 4096.000 us, avg: 4122.240 us, char/s: 19895736.30 / 18.974 MB/s
273 v1.4 write: min: 1319.000 us, avg: 1335.538 us, char/s: 61409709.05 / 58.565 MB/s</pre>
274
275 JSONKit v1.4 is 28% faster at reading and 6% faster at writing that v1.3 in this worst-case torture test.
276
277 While your milage may vary, you will likely see improvements in the 50% for reading and 10% for writing on your real world JSON. The nature of JSONKits cache means performance improvements is statistical in nature and depends on the particular properties of the JSON being parsed.
278
279 For comparison, [json-framework][], a popular Objective-C JSON parsing library, turns in the following benchmark times for [`twitter_public_timeline.json`][twitter_public_timeline.json]&mdash;
280
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
281 <pre>
282 &#x200b; read : min: 1670.000 us, avg: 1682.461 us, char/s: 14585776.43 / 13.910 MB/s
283 &#x200b; write: min: 1021.000 us, avg: 1028.970 us, char/s: 23849091.81 / 22.744 MB/s</pre>
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
284
285 Since the benchmark for JSONKit and [json-framework][] was done on the same computer, it's safe to compare the timing results. The version of [json-framework][] used was the latest v3.0 available via the master branch at the time of this writing on github.com.
286
287 JSONKit v1.4 is 483% faster at reading and 694% faster at writing than [json-framework][].
288
289 ### Other Changes
290
291 * Added a `__clang_analyzer__` pre-processor conditional around some code that the `clang` static analyzer was giving false positives for. However, `clang` versions &le; 1.5 do not define `__clang_analyzer__` and therefore will continue to emit analyzer warnings.
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
292 * The cache now uses a Galois Linear Feedback Shift Register PRNG to select which item in the cache to randomly age. This should age items in the cache more fairly.
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
293 * To promote better L1 cache locality, the cache age structure was rearranged slightly along with modifying when an item is randomly chosen to be aged.
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
294 * Removed a lot of internal and private data structures from `JSONKit.h` and put them in `JSONKit.m`.
295 * Modified the way floating point values are serialized. Previously, the [`printf`][printf] format conversion `%.16g` was used. This was changed to `%.17g` which should theoretically allow for up to a full `float`, or [IEEE 754 Single 32-bit floating-point][Single Precision], of precision when converting floating point values to decimal representation.
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
296 * The usual sundry of inconsequential tidies and what not, such as updating the `README.md`, etc.
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
297 * The catagory additions to the Cocoa classes were changed from `JSONKit` to `JSONKitDeserializing` and `JSONKitSerializing`, as appropriate.
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
298
299 ## Version 1.3 2011/05/02
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
300
301 ### New Features
302
303 * Added the `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` pre-processor define flag.
304
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
305 This is typically enabled by adding `-DJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` to the compilers command line arguments or in `Xcode.app` by adding `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` to a projects / targets `Pre-Processor Macros` settings.
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
306
307 The `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` option enables the use of custom Core Foundation collection call backs which omit the [`CFRetain`][CFRetain] calls. This results in saving several [`CFRetain`][CFRetain] and [`CFRelease`][CFRelease] calls typically needed for every single object from the parsed JSON. While the author has used this technique for years without any issues, an unexpected interaction with the Foundation [`-mutableCopy`][-mutableCopy] method and Core Foundation Toll-Free Bridging resulting in a condition in which the objects contained in the collection to be over released. This problem does not occur with the use of [`-copy`][-copy] due to the fact that the objects created by JSONKit are immutable, and therefore [`-copy`][-copy] does not require creating a completely new object and copying the contents, instead [`-copy`][-copy] simply returns a [`-retain`][-retain]'d version of the immutable object which is significantly faster along with the obvious reduction in memory usage.
308
309 Prior to version 1.3, JSONKit always used custom "Transfer of Ownership Collection Callbacks", and thus `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` was effectively implicitly defined.
310
311 Beginning with version 1.3, the default behavior of JSONKit is to use the standard Core Foundation collection callbacks ([`kCFTypeArrayCallBacks`][kCFTypeArrayCallBacks], [`kCFTypeDictionaryKeyCallBacks`][kCFTypeDictionaryKeyCallBacks], and [`kCFTypeDictionaryValueCallBacks`][kCFTypeDictionaryValueCallBacks]). The intention is to follow "the principle of least surprise", and the author believes the use of the standard Core Foundation collection callbacks as the default behavior for JSONKit results in the least surprise.
312
313 **NOTE**: `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` is only applicable to `(CF|NS)` `Dictionary` and `Array` class objects.
314
315 For the vast majority of users, the author believes JSONKits custom "Transfer of Ownership Collection Callbacks" will not cause any problems. As previously stated, the author has used this technique in performance critical code for years and has never had a problem. Until a user reported a problem with [`-mutableCopy`][-mutableCopy], the author was unaware that the use of the custom callbacks could even cause a problem. This is probably due to the fact that the vast majority of time the typical usage pattern tends to be "iterate the contents of the collection" and very rarely mutate the returned collection directly (although this last part is likely to vary significantly from programmer to programmer). The author tends to avoid the use of [`-mutableCopy`][-mutableCopy] as it results in a significant performance and memory consumption penalty. The reason for this is in "typical" Cocoa coding patterns, using [`-mutableCopy`][-mutableCopy] will instantiate an identical, albeit mutable, version of the original object. This requires both memory for the new object and time to iterate the contents of the original object and add them to the new object. Furthermore, under "typical" Cocoa coding patterns, the original collection object continues to consume memory until the autorelease pool is released. However, clearly there are cases where the use of [`-mutableCopy`][-mutableCopy] makes sense or may be used by an external library which is out of your direct control.
316
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
317 The use of the standard Core Foundation collection callbacks results in a 9% to 23% reduction in parsing performance, with an "eye-balled average" of around 13% according to some benchmarking done by the author using Real World&trade; JSON (i.e., actual JSON from various web services, such as Twitter, etc) using `gcc-4.2 -arch x86_64 -O3 -DNS_BLOCK_ASSERTIONS` with the only change being the addition of `-DJK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS`.
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
318
319 `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS` is only applicable to parsing / deserializing (i.e. converting from) of JSON. Serializing (i.e., converting to JSON) is completely unaffected by this change.
320
321 ### Bug Fixes
322
323 * Fixed a [bug report regarding `-mutableCopy`](https://github.com/johnezang/JSONKit/issues#issue/3). This is related to the addition of the pre-processor define flag `JK_ENABLE_CF_TRANSFER_OWNERSHIP_CALLBACKS`.
324
325 ### Other Changes
326
327 * Added `JK_EXPECTED` optimization hints around several conditionals.
328 * When serializing objects, JSONKit first starts with a small, on stack buffer. If the encoded JSON exceeds the size of the stack buffer, JSONKit switches to a heap allocated buffer. If JSONKit switched to a heap allocated buffer, [`CFDataCreateWithBytesNoCopy`][CFDataCreateWithBytesNoCopy] is used to create the [`NSData`][NSData] object, which in most cases causes the heap allocated buffer to "transfer" to the [`NSData`][NSData] object which is substantially faster than allocating a new buffer and copying the bytes.
329 * Added a pre-processor check in `JSONKit.m` to see if Objective-C Garbage Collection is enabled and issue a `#error` notice that JSONKit does not support Objective-C Garbage Collection.
330 * Various other minor or trivial modifications, such as updating `README.md`.
331
332 ### Other Issues
333
334 * When using the `clang` static analyzer (the version used at the time of this writing was `Apple clang version 1.5 (tags/Apple/clang-60)`), the static analyzer reports a number of problems with `JSONKit.m`.
335
336 The author has investigated these issues and determined that the problems reported by the current version of the static analyzer are "false positives". Not only that, the reported problems are not only "false positives", they are very clearly and obviously wrong. Therefore, the author has made the decision that no action will be taken on these non-problems, which includes not modifying the code for the sole purpose of silencing the static analyzer. The justification for this is "the dog wags the tail, not the other way around."
337
8339b27 @johnezang Fixed a serious crashing bug. Fixed a memory leak. Fixed an off by …
authored
338 ## Version 1.2 2011/01/08
339
340 ### Bug Fixes
341
342 * When JSONKit attempted to parse and decode JSON that contained `{"key": value}` dictionaries that contained the same key more than once would likely result in a crash. This was a serious bug.
343 * Under some conditions, JSONKit could potentially leak memory.
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
344 * There was an off by one error in the code that checked whether or not the parser was at the end of the `UTF8` buffer. This could result in JSONKit reading one by past the buffer bounds in some cases.
8339b27 @johnezang Fixed a serious crashing bug. Fixed a memory leak. Fixed an off by …
authored
345
346 ### Other Changes
347
348 * Some of the methods were missing `NULL` pointer checks for some of their arguments. This was fixed. In generally, when JSONKit encounters invalid arguments, it throws a `NSInvalidArgumentException` exception.
349 * Various other minor changes such as tightening up numeric literals with `UL` or `L` qualification, assertion check tweaks and additions, etc.
350 * The README.md file was updated with additional information.
351
352 ### Version 1.1
353
354 No change log information was kept for versions prior to 1.2.
355
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
356 [bugtracker]: https://github.com/johnezang/JSONKit/issues
357 [RFC 4627]: http://tools.ietf.org/html/rfc4627
358 [twitter_public_timeline.json]: https://github.com/samsoffes/json-benchmarks/blob/master/Resources/twitter_public_timeline.json
359 [json-framework]: https://github.com/stig/json-framework
360 [Single Precision]: http://en.wikipedia.org/wiki/Single_precision
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
361 [kCFTypeArrayCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html#//apple_ref/c/data/kCFTypeArrayCallBacks
362 [kCFTypeDictionaryKeyCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/data/kCFTypeDictionaryKeyCallBacks
363 [kCFTypeDictionaryValueCallBacks]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/data/kCFTypeDictionaryValueCallBacks
364 [CFRetain]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFTypeRef/Reference/reference.html#//apple_ref/c/func/CFRetain
365 [CFRelease]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFTypeRef/Reference/reference.html#//apple_ref/c/func/CFRelease
366 [CFDataCreateWithBytesNoCopy]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDataRef/Reference/reference.html#//apple_ref/c/func/CFDataCreateWithBytesNoCopy
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
367 [CFArray]: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFArrayRef/Reference/reference.html
368 [CFDictionary]: http://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html
369 [CFDictionaryCreate]: http://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFDictionaryRef/Reference/reference.html#//apple_ref/c/func/CFDictionaryCreate
370 [-mutableCopy]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSObject/mutableCopy
371 [-copy]: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html%23//apple_ref/occ/instm/NSObject/copy
372 [-retain]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/retain
373 [-release]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/release
374 [-isEqual:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/isEqual:
375 [-hash]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html#//apple_ref/occ/intfm/NSObject/hash
376 [NSArray]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/index.html
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
377 [NSMutableArray]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/index.html
378 [-insertObject:atIndex:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/insertObject:atIndex:
379 [-removeObjectAtIndex:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/removeObjectAtIndex:
380 [-replaceObjectAtIndex:withObject:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableArray_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableArray/replaceObjectAtIndex:withObject:
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
381 [NSDictionary]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/index.html
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
382 [NSMutableDictionary]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/index.html
383 [-setObject:forKey:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/setObject:forKey:
384 [-removeObjectForKey:]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/removeObjectForKey:
762cfc5 @johnezang Version 1.3. See CHANGELOG.md for details.
authored
385 [NSData]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/index.html
0d5ea3f @johnezang Update CHANGELOG.md to refelct the latest changes.
authored
386 [NSFastEnumeration]: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSFastEnumeration_protocol/Reference/NSFastEnumeration.html
9993011 @johnezang Record a few more things in the changelog for v1.4.
authored
387 [NSString]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html
e58f2a6 @johnezang Initial push of JSONKit v1.4. May not be the final v1.4 commit. See…
authored
388 [printf]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/printf.3.html
33f8aea @johnezang JSONKit v1.4 can now return mutable collection objects. See the CHAN…
authored
389 [memmove]: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/memmove.3.html
Something went wrong with that request. Please try again.