Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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 < 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?

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.