NSArray and NSNumber-int conversions I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line.

However, when text is inserted on one line, the start indexes of every line afterwards change. So I'm doing this:

 //i = the linenumber of the modified row 
 // self.lineStartIndexes = NSMutableArray
 for (int j = i+1; j &lt; self.lineStartIndexes.count; j++) {
     _lineStartIndexes[j] = @([(NSNumber *)[self.lineStartIndexes objectAtIndex:j] intValue]+text.length);
 }


This takes 12ms on a large text file, and it feels like it could go a lot faster without all NSNumber-conversions. I have thought about using C arrays, but I don't know the size of the array and everything became very complicated to me. What should I do to optimize this?
You could consider creating a class that holds the indices for a larger amount of text (for example a paragraph or a section or a subsection in the text). That class would have the absolute index for where in the file it begins and relative indices within the paragraph/section each line begins. 

Whenever a new line is added or removed only the lines within that paragraph/section would have to be updated and the absolute start index of all the following sections as well. 

(I don't know what text you write or what you use the line starts for). 

You could still find a specific line very easily (and probably very fast) by enumerating the absolute indices of the paragraphs/sections and when you find the right section enumerate it's lines.