From eeb440fa1c05088a010b50e30e8fefbc4b2e5d0b Mon Sep 17 00:00:00 2001 From: michael starke Date: Sat, 16 Nov 2013 00:02:54 +0100 Subject: [PATCH] Sped up table view creation to reuse date formatter --- MacPass/MPAutotypeCommand.h | 13 +++++++++++++ MacPass/MPAutotypeCommand.m | 13 +++++++++++++ MacPass/MPEntryViewController.m | 19 ++++++++++++------- 3 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 MacPass/MPAutotypeCommand.h create mode 100644 MacPass/MPAutotypeCommand.m diff --git a/MacPass/MPAutotypeCommand.h b/MacPass/MPAutotypeCommand.h new file mode 100644 index 00000000..7d97a492 --- /dev/null +++ b/MacPass/MPAutotypeCommand.h @@ -0,0 +1,13 @@ +// +// MPAutotypeCommand.h +// MacPass +// +// Created by Michael Starke on 10/11/13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import + +@interface MPAutotypeCommand : NSObject + +@end diff --git a/MacPass/MPAutotypeCommand.m b/MacPass/MPAutotypeCommand.m new file mode 100644 index 00000000..34dca682 --- /dev/null +++ b/MacPass/MPAutotypeCommand.m @@ -0,0 +1,13 @@ +// +// MPAutotypeCommand.m +// MacPass +// +// Created by Michael Starke on 10/11/13. +// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved. +// + +#import "MPAutotypeCommand.h" + +@implementation MPAutotypeCommand + +@end diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 82adeee1..e77ef701 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -111,7 +111,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; _entryArrayController = [[NSArrayController alloc] init]; _dataSource = [[MPEntryTableDataSource alloc] init]; _dataSource.viewController = self; - _menuDelegate = [[MPEntryContextMenuDelegate alloc] init]; + _menuDelegate = [[MPEntryContextMenuDelegate alloc] init]; _selectedEntry = nil; } return self; @@ -207,8 +207,8 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; - (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row { /* - bind bakground color to entry color - */ + bind bakground color to entry color + */ } - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { @@ -249,9 +249,14 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; } if(isModifedColumn) { if(![[view textField] formatter]) { - NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; - [formatter setDateStyle:NSDateFormatterMediumStyle]; - [formatter setTimeStyle:NSDateFormatterMediumStyle]; + /* Just use one formatter instance since it's expensive to create */ + static NSDateFormatter *formatter = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + formatter = [[NSDateFormatter alloc] init]; + [formatter setDateStyle:NSDateFormatterMediumStyle]; + [formatter setTimeStyle:NSDateFormatterMediumStyle]; + }); [textField setFormatter:formatter]; } [textField bind:NSValueBinding toObject:entry.timeInfo withKeyPath:@"lastModificationTime" options:nil]; @@ -287,7 +292,7 @@ NSString *const _MPTAbleSecurCellView = @"PasswordCell"; #pragma mark Notifications - (void)_didChangeCurrentItem:(NSNotification *)notification { MPDocument *document = [notification object]; - + if(!document.selectedGroup) { /* No group, this only can happen in filtering, just return */ return;