mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
minor performance tweaks
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35865 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f0fa7fbe28
commit
17bdc5cfe2
4 changed files with 55 additions and 39 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2012-12-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSHTTPCookieStorage.m: Don't read store if it doesn't exist.
|
||||||
|
* Source/GSTLS.h: Use time interval for caching
|
||||||
|
* Source/GSTLS.m: More efficient caching
|
||||||
|
|
||||||
2012-12-06 Richard Frith-Macdonald <rfm@gnu.org>
|
2012-12-06 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSPropertyList.m: remove a couple of useless debug logs.
|
* Source/NSPropertyList.m: remove a couple of useless debug logs.
|
||||||
|
|
|
@ -63,7 +63,7 @@ extern NSString * const GSTLSVerify;
|
||||||
*/
|
*/
|
||||||
@interface GSTLSDHParams : GSTLSObject
|
@interface GSTLSDHParams : GSTLSObject
|
||||||
{
|
{
|
||||||
NSDate *when;
|
NSTimeInterval when;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
gnutls_dh_params_t params;
|
gnutls_dh_params_t params;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ extern NSString * const GSTLSVerify;
|
||||||
*/
|
*/
|
||||||
@interface GSTLSCertificateList : GSTLSObject
|
@interface GSTLSCertificateList : GSTLSObject
|
||||||
{
|
{
|
||||||
NSDate *when;
|
NSTimeInterval when;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
gnutls_x509_crt_t *crts;
|
gnutls_x509_crt_t *crts;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
|
@ -104,7 +104,7 @@ extern NSString * const GSTLSVerify;
|
||||||
*/
|
*/
|
||||||
@interface GSTLSPrivateKey : GSTLSObject
|
@interface GSTLSPrivateKey : GSTLSObject
|
||||||
{
|
{
|
||||||
NSDate *when;
|
NSTimeInterval when;
|
||||||
NSString *path;
|
NSString *path;
|
||||||
NSString *password;
|
NSString *password;
|
||||||
gnutls_x509_privkey_t key;
|
gnutls_x509_privkey_t key;
|
||||||
|
@ -117,7 +117,7 @@ extern NSString * const GSTLSVerify;
|
||||||
*/
|
*/
|
||||||
@interface GSTLSCredentials : GSTLSObject
|
@interface GSTLSCredentials : GSTLSObject
|
||||||
{
|
{
|
||||||
NSDate *when;
|
NSTimeInterval when;
|
||||||
NSString *name;
|
NSString *name;
|
||||||
GSTLSPrivateKey *key;
|
GSTLSPrivateKey *key;
|
||||||
GSTLSCertificateList *list;
|
GSTLSCertificateList *list;
|
||||||
|
|
|
@ -314,7 +314,7 @@ static gnutls_anon_client_credentials_t anoncred;
|
||||||
@implementation GSTLSDHParams
|
@implementation GSTLSDHParams
|
||||||
static NSLock *paramsLock = nil;
|
static NSLock *paramsLock = nil;
|
||||||
static NSMutableDictionary *paramsCache = nil;
|
static NSMutableDictionary *paramsCache = nil;
|
||||||
static NSDate *paramsWhen = nil;
|
static NSTimeInterval paramsWhen = 0.0;
|
||||||
static BOOL paramsGenerating = NO;
|
static BOOL paramsGenerating = NO;
|
||||||
static GSTLSDHParams *paramsCurrent = nil;
|
static GSTLSDHParams *paramsCurrent = nil;
|
||||||
|
|
||||||
|
@ -366,18 +366,18 @@ static GSTLSDHParams *paramsCurrent = nil;
|
||||||
[paramsLock lock];
|
[paramsLock lock];
|
||||||
[paramsCurrent release];
|
[paramsCurrent release];
|
||||||
paramsCurrent = p;
|
paramsCurrent = p;
|
||||||
ASSIGN(paramsWhen, [NSDate date]);
|
paramsWhen = [NSDate timeIntervalSinceReferenceDate];
|
||||||
paramsGenerating = NO;
|
paramsGenerating = NO;
|
||||||
[paramsLock unlock];
|
[paramsLock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void) housekeeping: (NSNotification*)n
|
+ (void) housekeeping: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator;
|
NSEnumerator *enumerator;
|
||||||
NSString *key;
|
NSString *key;
|
||||||
NSDate *now;
|
NSTimeInterval now;
|
||||||
|
|
||||||
now = [NSDate date];
|
now = [NSDate timeIntervalSinceReferenceDate];
|
||||||
[paramsLock lock];
|
[paramsLock lock];
|
||||||
|
|
||||||
enumerator = [[paramsCache allKeys] objectEnumerator];
|
enumerator = [[paramsCache allKeys] objectEnumerator];
|
||||||
|
@ -387,7 +387,7 @@ static GSTLSDHParams *paramsCurrent = nil;
|
||||||
|
|
||||||
p = [paramsCache objectForKey: key];
|
p = [paramsCache objectForKey: key];
|
||||||
|
|
||||||
if ([now timeIntervalSinceDate: p->when] > 300.0)
|
if (now - p->when > 300.0)
|
||||||
{
|
{
|
||||||
[paramsCache removeObjectForKey: key];
|
[paramsCache removeObjectForKey: key];
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ static GSTLSDHParams *paramsCurrent = nil;
|
||||||
* thread since it's likely to be rather slow.
|
* thread since it's likely to be rather slow.
|
||||||
*/
|
*/
|
||||||
if (nil != paramsCurrent && NO == paramsGenerating
|
if (nil != paramsCurrent && NO == paramsGenerating
|
||||||
&& [now timeIntervalSinceDate: paramsWhen] > 24 * 60 * 60)
|
&& (now = paramsWhen) > 24.0 * 60.0 * 60.0)
|
||||||
{
|
{
|
||||||
[NSThread detachNewThreadSelector: @selector(generate)
|
[NSThread detachNewThreadSelector: @selector(generate)
|
||||||
toTarget: self
|
toTarget: self
|
||||||
|
@ -411,7 +411,7 @@ static GSTLSDHParams *paramsCurrent = nil;
|
||||||
if (nil == paramsLock)
|
if (nil == paramsLock)
|
||||||
{
|
{
|
||||||
paramsLock = [NSLock new];
|
paramsLock = [NSLock new];
|
||||||
paramsWhen = [NSDate new];
|
paramsWhen = [NSDate timeIntervalSinceReferenceDate];
|
||||||
paramsCache = [NSMutableDictionary new];
|
paramsCache = [NSMutableDictionary new];
|
||||||
[[NSNotificationCenter defaultCenter] addObserver: self
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
selector: @selector(housekeeping:)
|
selector: @selector(housekeeping:)
|
||||||
|
@ -448,7 +448,7 @@ static GSTLSDHParams *paramsCurrent = nil;
|
||||||
datum.size = (unsigned int)[data length];
|
datum.size = (unsigned int)[data length];
|
||||||
|
|
||||||
p = [self alloc];
|
p = [self alloc];
|
||||||
p->when = [NSDate new];
|
p->when = [NSDate timeIntervalSinceReferenceDate];
|
||||||
p->path = [f copy];
|
p->path = [f copy];
|
||||||
gnutls_dh_params_init(&p->params);
|
gnutls_dh_params_init(&p->params);
|
||||||
ret = gnutls_dh_params_import_pkcs3(p->params, &datum,
|
ret = gnutls_dh_params_import_pkcs3(p->params, &datum,
|
||||||
|
@ -490,11 +490,11 @@ static NSMutableDictionary *certificateListCache = nil;
|
||||||
*/
|
*/
|
||||||
+ (void) housekeeping: (NSNotification*)n
|
+ (void) housekeeping: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator;
|
NSEnumerator *enumerator;
|
||||||
NSString *key;
|
NSString *key;
|
||||||
NSDate *now;
|
NSTimeInterval now;
|
||||||
|
|
||||||
now = [NSDate date];
|
now = [NSDate timeIntervalSinceReferenceDate];
|
||||||
[certificateListLock lock];
|
[certificateListLock lock];
|
||||||
enumerator = [[certificateListCache allKeys] objectEnumerator];
|
enumerator = [[certificateListCache allKeys] objectEnumerator];
|
||||||
while (nil != (key = [enumerator nextObject]))
|
while (nil != (key = [enumerator nextObject]))
|
||||||
|
@ -503,7 +503,7 @@ static NSMutableDictionary *certificateListCache = nil;
|
||||||
|
|
||||||
list = [certificateListCache objectForKey: key];
|
list = [certificateListCache objectForKey: key];
|
||||||
|
|
||||||
if ([now timeIntervalSinceDate: list->when] > 300.0)
|
if (now - list->when > 300.0)
|
||||||
{
|
{
|
||||||
[certificateListCache removeObjectForKey: key];
|
[certificateListCache removeObjectForKey: key];
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ static NSMutableDictionary *certificateListCache = nil;
|
||||||
datum.size = (unsigned int)[data length];
|
datum.size = (unsigned int)[data length];
|
||||||
|
|
||||||
l = [self alloc];
|
l = [self alloc];
|
||||||
l->when = [NSDate new];
|
l->when = [NSDate timeIntervalSinceReferenceDate];
|
||||||
l->path = [f copy];
|
l->path = [f copy];
|
||||||
ret = gnutls_x509_crt_list_import(crts, &count, &datum,
|
ret = gnutls_x509_crt_list_import(crts, &count, &datum,
|
||||||
GNUTLS_X509_FMT_PEM,
|
GNUTLS_X509_FMT_PEM,
|
||||||
|
@ -593,7 +593,6 @@ static NSMutableDictionary *certificateListCache = nil;
|
||||||
{
|
{
|
||||||
if (nil != path)
|
if (nil != path)
|
||||||
{
|
{
|
||||||
DESTROY(when);
|
|
||||||
DESTROY(path);
|
DESTROY(path);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
|
@ -620,11 +619,11 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
*/
|
*/
|
||||||
+ (void) housekeeping: (NSNotification*)n
|
+ (void) housekeeping: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSEnumerator *outer;
|
NSEnumerator *outer;
|
||||||
NSString *oKey;
|
NSString *oKey;
|
||||||
NSDate *now;
|
NSTimeInterval now;
|
||||||
|
|
||||||
now = [NSDate date];
|
now = [NSDate timeIntervalSinceReferenceDate];
|
||||||
[privateKeyLock lock];
|
[privateKeyLock lock];
|
||||||
outer = [[privateKeyCache0 allKeys] objectEnumerator];
|
outer = [[privateKeyCache0 allKeys] objectEnumerator];
|
||||||
while (nil != (oKey = [outer nextObject]))
|
while (nil != (oKey = [outer nextObject]))
|
||||||
|
@ -632,7 +631,7 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
GSTLSPrivateKey *key;
|
GSTLSPrivateKey *key;
|
||||||
|
|
||||||
key = [privateKeyCache0 objectForKey: oKey];
|
key = [privateKeyCache0 objectForKey: oKey];
|
||||||
if ([now timeIntervalSinceDate: key->when] > 300.0)
|
if (now - key->when > 300.0)
|
||||||
{
|
{
|
||||||
[privateKeyCache0 removeObjectForKey: oKey];
|
[privateKeyCache0 removeObjectForKey: oKey];
|
||||||
}
|
}
|
||||||
|
@ -650,7 +649,7 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
{
|
{
|
||||||
GSTLSPrivateKey *key = [m objectForKey: iKey];
|
GSTLSPrivateKey *key = [m objectForKey: iKey];
|
||||||
|
|
||||||
if ([now timeIntervalSinceDate: key->when] > 300.0)
|
if (now - key->when > 300.0)
|
||||||
{
|
{
|
||||||
[m removeObjectForKey: iKey];
|
[m removeObjectForKey: iKey];
|
||||||
if (0 == [m count])
|
if (0 == [m count])
|
||||||
|
@ -724,7 +723,7 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
datum.size = (unsigned int)[data length];
|
datum.size = (unsigned int)[data length];
|
||||||
|
|
||||||
k = [self alloc];
|
k = [self alloc];
|
||||||
k->when = [NSDate new];
|
k->when = [NSDate timeIntervalSinceReferenceDate];
|
||||||
k->path = [f copy];
|
k->path = [f copy];
|
||||||
k->password = [p copy];
|
k->password = [p copy];
|
||||||
gnutls_x509_privkey_init(&k->key);
|
gnutls_x509_privkey_init(&k->key);
|
||||||
|
@ -774,7 +773,6 @@ static NSMutableDictionary *privateKeyCache1 = nil;
|
||||||
{
|
{
|
||||||
if (nil != path)
|
if (nil != path)
|
||||||
{
|
{
|
||||||
DESTROY(when);
|
|
||||||
DESTROY(path);
|
DESTROY(path);
|
||||||
DESTROY(password);
|
DESTROY(password);
|
||||||
gnutls_x509_privkey_deinit(key);
|
gnutls_x509_privkey_deinit(key);
|
||||||
|
@ -798,11 +796,11 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
*/
|
*/
|
||||||
+ (void) housekeeping: (NSNotification*)n
|
+ (void) housekeeping: (NSNotification*)n
|
||||||
{
|
{
|
||||||
NSEnumerator *enumerator;
|
NSEnumerator *enumerator;
|
||||||
NSDictionary *key;
|
NSDictionary *key;
|
||||||
NSDate *now;
|
NSTimeInterval now;
|
||||||
|
|
||||||
now = [NSDate date];
|
now = [NSDate timeIntervalSinceReferenceDate];
|
||||||
[credentialsLock lock];
|
[credentialsLock lock];
|
||||||
enumerator = [[credentialsCache allKeys] objectEnumerator];
|
enumerator = [[credentialsCache allKeys] objectEnumerator];
|
||||||
while (nil != (key = [enumerator nextObject]))
|
while (nil != (key = [enumerator nextObject]))
|
||||||
|
@ -810,7 +808,7 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
GSTLSCredentials *cred;
|
GSTLSCredentials *cred;
|
||||||
|
|
||||||
cred = [credentialsCache objectForKey: key];
|
cred = [credentialsCache objectForKey: key];
|
||||||
if ([now timeIntervalSinceDate: cred->when] > 300.0)
|
if (now - cred->when > 300.0)
|
||||||
{
|
{
|
||||||
[credentialsCache removeObjectForKey: key];
|
[credentialsCache removeObjectForKey: key];
|
||||||
}
|
}
|
||||||
|
@ -844,6 +842,9 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
GSTLSCredentials *c;
|
GSTLSCredentials *c;
|
||||||
NSMutableString *k;
|
NSMutableString *k;
|
||||||
|
|
||||||
|
/* Build a unique key for the credentials based on all the
|
||||||
|
* information (file names and password) used to build them.
|
||||||
|
*/
|
||||||
k = [NSMutableString stringWithCapacity: 1024];
|
k = [NSMutableString stringWithCapacity: 1024];
|
||||||
ca = [ca stringByStandardizingPath];
|
ca = [ca stringByStandardizingPath];
|
||||||
if (nil != ca) [k appendString: ca];
|
if (nil != ca) [k appendString: ca];
|
||||||
|
@ -877,7 +878,7 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
{
|
{
|
||||||
c = [self new];
|
c = [self new];
|
||||||
c->name = [k copy];
|
c->name = [k copy];
|
||||||
c->when = [NSDate new];
|
c->when = [NSDate timeIntervalSinceReferenceDate];
|
||||||
|
|
||||||
gnutls_certificate_allocate_credentials(&c->certcred);
|
gnutls_certificate_allocate_credentials(&c->certcred);
|
||||||
|
|
||||||
|
@ -994,6 +995,8 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the key for our sertificat .. if one is specified.
|
||||||
|
*/
|
||||||
if (nil != ck)
|
if (nil != ck)
|
||||||
{
|
{
|
||||||
c->key = [[GSTLSPrivateKey keyFromFile: ck
|
c->key = [[GSTLSPrivateKey keyFromFile: ck
|
||||||
|
@ -1005,6 +1008,8 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Load our certificate (may be a list) ifthe file is specified.
|
||||||
|
*/
|
||||||
if (nil != cf)
|
if (nil != cf)
|
||||||
{
|
{
|
||||||
c->list = [[GSTLSCertificateList listFromFile: cf] retain];
|
c->list = [[GSTLSCertificateList listFromFile: cf] retain];
|
||||||
|
@ -1015,6 +1020,9 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we have loaded a certificate, we add it to the credentials
|
||||||
|
* using the certificate key so we can use it.
|
||||||
|
*/
|
||||||
if (nil != c->list)
|
if (nil != c->list)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1053,10 +1061,9 @@ static NSMutableDictionary *credentialsCache = nil;
|
||||||
|
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
if (nil != when)
|
if (nil != key)
|
||||||
{
|
{
|
||||||
gnutls_certificate_free_credentials(certcred);
|
gnutls_certificate_free_credentials(certcred);
|
||||||
DESTROY(when);
|
|
||||||
DESTROY(key);
|
DESTROY(key);
|
||||||
DESTROY(list);
|
DESTROY(list);
|
||||||
DESTROY(dhParams);
|
DESTROY(dhParams);
|
||||||
|
|
|
@ -123,7 +123,7 @@ static NSHTTPCookieStorage *storage = nil;
|
||||||
NSUserDomainMask, YES);
|
NSUserDomainMask, YES);
|
||||||
path = [[dirs objectAtIndex: 0] stringByAppendingPathComponent: @"Cookies"];
|
path = [[dirs objectAtIndex: 0] stringByAppendingPathComponent: @"Cookies"];
|
||||||
if ([[NSFileManager defaultManager]
|
if ([[NSFileManager defaultManager]
|
||||||
fileExistsAtPath: path isDirectory: &isDir] == NO || isDir == NO)
|
fileExistsAtPath: path isDirectory: &isDir] == NO || isDir == NO)
|
||||||
{
|
{
|
||||||
BOOL ok;
|
BOOL ok;
|
||||||
|
|
||||||
|
@ -173,7 +173,10 @@ static NSHTTPCookieStorage *storage = nil;
|
||||||
}
|
}
|
||||||
properties = nil;
|
properties = nil;
|
||||||
NS_DURING
|
NS_DURING
|
||||||
properties = [[NSString stringWithContentsOfFile: path] propertyList];
|
if (YES == [[NSFileManager defaultManager] fileExistsAtPath: path])
|
||||||
|
{
|
||||||
|
properties = [[NSString stringWithContentsOfFile: path] propertyList];
|
||||||
|
}
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NSLog(@"NSHTTPCookieStorage: Error reading cookies plist");
|
NSLog(@"NSHTTPCookieStorage: Error reading cookies plist");
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue