Here is the basic approach I'm using. I commented out the replace code
to focus on the the performance of the actual search. If I set the
granularity such that doubleClickAtIndex: is not used
(FindTypeContains), the performance is reasonable. Otherwise, the
performance is as described earlier. I borrowed the "find word"
technique from a previous posting on here.

The performance was OK on a 1.5MB sample, but seems to really bog down
somewhere between 1.5-3.0MB.

If The FindPanel is also using doubleClickAtIndex:, then I'm guessing
there is something wrong with my code or I'm missing a trick to get
the better performance of the FindPanel.

- (void)exampleReplaceAll:(NSMutableAttributedString*)inoutText
{
        NSRange         aRange;
        NSRange         matchRange;
        NSString*   workString;
        unsigned        searchOptions = NSBackwardsSearch;

        // instance variables used in this routine
        
        //NSString* findString;
        //NSString* replaceString;
        //int granularity;
        
        workString = [inoutText string];
        aRange  = NSMakeRange(0,[workString length]);
        if ([findString length] == 0)
        {
                matchRange = NSMakeRange(0,[workString length]);
        }
        else
        {
                matchRange = [workString rangeOfString:findString
options:searchOptions range:aRange];
        }
        BOOL matchSuccess = NO;
        
        while (matchRange.location != NSNotFound)
        {
                matchSuccess = YES;
                NSRange wordRange;
                
                if (granularity != FindTypeContains)
                {
                        // only do the doubleClickAtIndex: test if we actually 
need it.
                        matchSuccess = NO;
                        [inoutText doubleClickAtIndex:matchRange.location];
                }
                
                if ( (granularity == FindTypeWholeWord) &&
(NSEqualRanges(matchRange, wordRange)) )
                {
                        matchSuccess = YES;
                }
                else if ( (granularity == FindTypeStartsWith) &&
(matchRange.location == wordRange.location) )
                {
                        matchSuccess = YES;
                }
                else if ( (granularity == FindTypeEndsWith) &&
(NSMaxRange(matchRange) == NSMaxRange(wordRange) ) )
                {
                        matchSuccess = YES;
                }
                
                //if (matchSuccess)
                //{
                //      [inoutText replaceCharactersInRange:matchRange 
withString:replaceString];
                //}
                aRange.length = matchRange.location;
                matchRange = [workString rangeOfString:findString
options:searchOptions range:aRange];
        }
}


Any help in understanding this issue is appreciated.

Thanks.

Mark Munz


On Fri, Nov 7, 2008 at 10:16 AM, Douglas Davidson <[EMAIL PROTECTED]> wrote:
>
> On Nov 5, 2008, at 9:37 PM, Mark Munz wrote:
>
>> The same basic test using the FindPanel's ReplaceAll (with Full word
>> option) takes under 1 second to complete on the same text. I thought I
>> read that FindPanel was also using doubleClickAtIndex:. The
>> performance difference seems to hint that it is not, or that I am
>> missing something.
>
> The find panel does currently use doubleClickAtIndex:, but perhaps the usage
> pattern is different from your case.  One alternative you might consider is
> the use of CFStringTokenizer.
>
> Douglas Davidson
>
>



-- 
Mark Munz
unmarked software
http://www.unmarked.com/
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to