Improved safety of section metrics array
Improved safety of section metrics array

_metrics is now a struct containing a const struct KKSectionMetrics
array and a const NSUInteger count. The idea behind this is that neither
the count nor the array can be modified without replacing the entire
_metrics object; as a result, the count is more likely to be correct at
all times.

Additionally, -_reloadMetrics now only frees and reallocates the
KKSectionMetrics array if it isn't already of the correct size
(_metrics.count != _numberOfSections). Otherwise, the existing array can
be modified in-place.

Moreover, memory management for the calloc'd array is refactoree into
-_cleanupMetrics (which is called from both -_reloadMetrics and
-dealloc).

Finally, there were some loops on ∀ i ∈ [0.._numberOfSections], but
accessed _metrics.sections[i] without bounds checks. I've changed these
to be upwardly bounded on _metrics.count instead; this shouldn't result
in any change in behavior.

kolinkrewinkel/KKGridView,kolinkrewinkel/KKGridView,kundanjadhav/KKGridView