From 70558850380b1ea9bb8e7410bc3e77a7cff64263 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 28 Jan 2010 13:48:45 +0000 Subject: =?UTF-8?q?=E2=80=A2=20ESC=20completion=20-=20speed=20up=20gatheri?= =?UTF-8?q?ng=20data=20by=20avoiding=20the=20check=20for=20uniqueness=20if?= =?UTF-8?q?=20not=20necessary,=20make=20usage=20of=20NSMutableSet=20to=20c?= =?UTF-8?q?ollect=20unique=20data=20automatically,=20and=20rely=20on=20NSS?= =?UTF-8?q?ubTextStorage=20to=20get=20all=20words=20from=20the=20text=20bu?= =?UTF-8?q?ffer=20(if=20text=20buffer=20size=20less=20than=206MB)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.m | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Source/CMTextView.m b/Source/CMTextView.m index c656be13..1d75eb93 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -171,18 +171,20 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) // If caret is not inside backticks add keywords and all words coming from the view. if(!dbBrowseMode) { - // Only parse for words if text size is less than 60kB - if([[self string] length] && [[self string] length]<60000) + // Only parse for words if text size is less than 6MB + if([[self string] length] && [[self string] length]<6000000) { - NSMutableArray *uniqueArray = [NSMutableArray array]; - [uniqueArray addObjectsFromArray:[NSSet setWithArray:[[self string] componentsMatchedByRegex:@"\\w+"]]]; + NSMutableSet *uniqueArray = [NSMutableSet setWithCapacity:5]; + for(id w in [[self textStorage] words]) + [uniqueArray addObject:[w string]]; // Remove current word from list + [uniqueArray removeObject:currentWord]; NSInteger reverseSort = NO; - NSArray *sortedArray = [[[uniqueArray mutableCopy] autorelease] sortedArrayUsingFunction:alphabeticSort context:&reverseSort]; - for(id w in sortedArray) + + for(id w in [[uniqueArray allObjects] sortedArrayUsingFunction:alphabeticSort context:&reverseSort]) [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:w, @"display", @"dummy-small", @"image", nil]]; } @@ -379,15 +381,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) } } - // Make suggestions unique - NSMutableArray *compl = [[NSMutableArray alloc] initWithCapacity:32]; - for(id suggestion in possibleCompletions) - if(![compl containsObject:suggestion]) - [compl addObject:suggestion]; - - [possibleCompletions release]; - - return [compl autorelease]; + return [possibleCompletions autorelease]; } -- cgit v1.2.3