mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Limit clipboard history to about 10,000 items
Once we reach the threshold we delete half the history to ensure a good amortized time complexity.
This commit is contained in:
@@ -428,6 +428,13 @@ static NSMutableDictionary* SharedInstances = [NSMutableDictionary new];
|
||||
|
||||
if(createNewEntry)
|
||||
{
|
||||
static NSInteger const kHistorySize = 10000;
|
||||
if([self.entries count] > kHistorySize)
|
||||
{
|
||||
for(OakPasteboardEntry* entry in [self.entries objectsAtIndexes:[[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, [self.entries count] - kHistorySize/2)]])
|
||||
[entry.managedObjectContext deleteObject:entry];
|
||||
}
|
||||
|
||||
NSMutableOrderedSet* entries = [self mutableOrderedSetValueForKey:@"entries"];
|
||||
[entries addObject:[OakPasteboardEntry pasteboardEntryWithString:aString andOptions:someOptions inContext:self.managedObjectContext]];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user