RestKit/RestKit — pull request #2082 by carllindberg (2014-11-09 22:30:23+00:00)
Title: Few changes to applyRelationshipMappings

Another pull request part of the #2065 optimizations, though this one is pretty minor. They are all changes in RKMappingOperation's applyRelationshipMappings method.

First, there is a temporary array created which ends up only being used for its count, so changed to an NSUInteger. Just a small speedup in the test application, but it's there. It may have a larger effect for a deeply-nested tree, rather than one more shallow like the test app.

This also may fix a bug. In one section (probably rarely called), the code was getting the key path "mapping.propertyMappings.sourceKeyPath" on an RKRelationshipMapping, where if the mapping property happens to be an RKDynamicMapping, I think would throw an exception. The code immediately above has already determined the correct RKObjectMapping, so it seems easier to just call the propertyMappings method directly. It also seems easier to to then iterate over the mappings rather than using valueForKeyPath to create a temporary array, which avoids that object allocation. This code is not called with the test app so there is no apparent speedup.

Also avoided a double call to RKObjectIsCollection, though that is a pretty minimal speedup.

Timings before:
(Device) Mapping 5000 students with relationship mapping: 16.131188
(Simulator) Mapping 5000 students with relationship mapping: 2.287875

and after:
(Device) Mapping 5000 students with relationship mapping: 16.064542
(Simulator) Mapping 5000 students with relationship mapping: 2.274153