aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-28 13:48:45 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-28 13:48:45 +0000
commit70558850380b1ea9bb8e7410bc3e77a7cff64263 (patch)
tree6adaf77446a9a3cc430c43376e18e3c56c437b4b /Source/CMTextView.m
parentfbd0ed3df36e13e6ffd56b55162e1834be82d4f2 (diff)
downloadsequelpro-70558850380b1ea9bb8e7410bc3e77a7cff64263.tar.gz
sequelpro-70558850380b1ea9bb8e7410bc3e77a7cff64263.tar.bz2
sequelpro-70558850380b1ea9bb8e7410bc3e77a7cff64263.zip
• ESC completion
- speed up gathering data by avoiding the check for uniqueness if not necessary, make usage of NSMutableSet to collect unique data automatically, and rely on NSSubTextStorage to get all words from the text buffer (if text buffer size less than 6MB)
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r--Source/CMTextView.m24
1 files 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];
}