我有一些这样的代码:
-(void)updateString: (NSString*)str {
self.buffer = [self.buffer stringByAppendingString:str];
self.string = [self.buffer stringByAppendingString:@"Always at the end of self.string"];
}
输入:
self.buffer: "blah\n"
self.string: "Always at the end of self.string"
str: "Hello\n"
输出:
self.buffer: "blah\nHello\n"
self.string: "blah\nHello\nAlways at the end of self.string"
如果updateString
被频繁调用,是否会随着self.buffer
越来越大而导致性能问题?看起来这将遭受类似于Schlemiel the Painter 算法的低效率。
如果是这样,我能做些什么来改进我的幼稚实现?用于?NSMutableString
_self.buffer