From e848a285c483ee10f0e30eaf6983d412d47b231c Mon Sep 17 00:00:00 2001 From: CaS Date: Thu, 10 Nov 2005 22:40:57 +0000 Subject: [PATCH] Performance tweaks git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21985 72102866-910b-0410-8b05-ffd578937521 --- Source/GSPortPrivate.h | 1 + Source/win32/NSMessagePortNameServerWin32.m | 2 +- Source/win32/NSMessagePortWin32.m | 24 ++++++++++++++++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/GSPortPrivate.h b/Source/GSPortPrivate.h index af844bc67..ffa6ec5b8 100644 --- a/Source/GSPortPrivate.h +++ b/Source/GSPortPrivate.h @@ -25,6 +25,7 @@ #if defined(__MINGW32__) @interface NSMessagePort(Private) ++ (id) newWithName: (NSString*)name; - (id) initWithName: (NSString*)name; - (NSString*) name; - (void) receivedEventRead; diff --git a/Source/win32/NSMessagePortNameServerWin32.m b/Source/win32/NSMessagePortNameServerWin32.m index b409af347..067470274 100644 --- a/Source/win32/NSMessagePortNameServerWin32.m +++ b/Source/win32/NSMessagePortNameServerWin32.m @@ -217,7 +217,7 @@ static void clean_up_names(void) n = [[self class] _query: name]; NSDebugLLog(@"NSMessagePort", @"got %@", n); - return AUTORELEASE([[NSMessagePort alloc] initWithName: n]); + return AUTORELEASE([NSMessagePort newWithName: n]); } - (BOOL) registerPort: (NSPort *)port diff --git a/Source/win32/NSMessagePortWin32.m b/Source/win32/NSMessagePortWin32.m index 1e944ec35..5163f3d62 100644 --- a/Source/win32/NSMessagePortWin32.m +++ b/Source/win32/NSMessagePortWin32.m @@ -125,7 +125,7 @@ static NSRecursiveLock *messagePortLock = nil; * Maps port name to NSMessagePort objects. */ static NSMapTable *ports = 0; -static Class messagePortClass; +static Class messagePortClass = 0; #if NEED_WORD_ALIGNMENT static unsigned wordAlign; @@ -186,6 +186,24 @@ static unsigned wordAlign; } } ++ (id) newWithName: (NSString*)name +{ + NSMessagePort *p; + + M_LOCK(messagePortLock); + p = RETAIN((NSMessagePort*)NSMapGet(ports, (void*)name)); + if (p == nil) + { + p = [[self alloc] initWithName: name]; + } + else + { + [p _setupSendPort]; + } + M_UNLOCK(messagePortLock); + return p; +} + - (void) addConnection: (NSConnection*)aConnection toRunLoop: (NSRunLoop*)aLoop forMode: (NSString*)aMode @@ -594,7 +612,7 @@ static unsigned wordAlign; length: 16 encoding: NSASCIIStringEncoding]; NSDebugFLLog(@"NSMessagePort", @"Decoded port as '%@'", n); - rPort = [[NSMessagePort alloc] initWithName: n]; + rPort = [messagePortClass newWithName: n]; RELEASE(n); if (rPort == nil) { @@ -631,7 +649,7 @@ static unsigned wordAlign; length: 16 encoding: NSASCIIStringEncoding]; NSDebugFLLog(@"NSMessagePort", @"Decoded port as '%@'", n); - p = [[NSMessagePort alloc] initWithName: n]; + p = [messagePortClass newWithName: n]; RELEASE(n); if (p == nil) {