NSMutableString & re-initing...
NSMutableString & re-initing...
- Subject: NSMutableString & re-initing...
- From: Jeff Knee <email@hidden>
- Date: Wed, 13 Nov 2002 18:42:45 -0500
All,
Here is some code that I've hopefully trimmed down and still left
readable that I was trying to speed up a little bit.
NSFileHandle *wordFile = [NSFileHandle
fileHandleForReadingAtPath:@"./some.txt"];
NSMutableString *wordString = [NSMutableString alloc];
int readLength = 8192;
NSData *wordData = [wordFile readDataOfLength:readLength];
while (0 != [wordData length])
{
wordString = [[NSMutableString alloc] initWith
Data:wordData
encoding:NSASCIIStringEncoding];
// [snipped out other stuff]
wordData = [wordFile readDataOfLength:readLength];
}
I was pulling other object allocations to outside the loop and things
were getting faster. I wanted to pull the [NSMutable alloc] out of the
loop also. So, I'd have:
wordString = [wordString initWith
Data:wordData
encoding:NSASCIIStringEncoding];
But, I found that on the second pass of the loop I'd get a run time
error (SIGTRAP) if I did so.
Is the problem that NSMutableString can't be "re-inited"? Is there
something I could do to the NSMutableString so that it would be 'happy'
being "re-inited"?
Is there another way to get the NSData into a NSMutableString that I'm
not catching?
Or, is "receiver = [receiver selector];" not a valid idiom for some
reason? (I've rewritten objects that allow themselves to be re-inited
but in the cases I've done this I've used [self init:blah] type of
code.)
Thanks!
+= Jeff Knee
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.