From 83c9f9df7da331460c8511c145d181e3a98e30f0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 18 Jun 2009 12:12:52 +0000 Subject: =?UTF-8?q?=E2=80=A2=20further=20tiny=20improvements=20for=20query?= =?UTF-8?q?String's=20speed=20-=20cStringFromString=20function=20pointer?= =?UTF-8?q?=20is=20cached=20-=20if=20utf8=20encoding=20make=20usage=20of?= =?UTF-8?q?=20UTF8String=20but=20implemented=20inside=20of=20queryString?= =?UTF-8?q?=20(otherwise=20no=20effect)=20=E2=80=A2=20tiny=20code=20cosmet?= =?UTF-8?q?ics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMMCPConnection.h | 1 + Source/CMMCPConnection.m | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 26590d85..4005c19b 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -76,6 +76,7 @@ BOOL delegateResponseToWillQueryString; BOOL consoleLoggingEnabled; + IMP cStringPtr; IMP willQueryStringPtr; } diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index b976c3a7..bf3eac18 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -138,6 +138,8 @@ static void forcePingTimeout(int signalNumber); if (![NSBundle loadNibNamed:@"ConnectionErrorDialog" owner:self]) { NSLog(@"Connection error dialog could not be loaded; connection failure handling will not function correctly."); } + + cStringPtr = [self methodForSelector:@selector(cStringFromString:usingEncoding:)]; } /* @@ -746,9 +748,17 @@ static void forcePingTimeout(int signalNumber); (void)(NSString*)(*willQueryStringPtr)(delegate, @selector(willQueryString:), query); // Derive the query string in the correct encoding - theCQuery = [self cStringFromString:query usingEncoding:encoding]; - // Set the length of the current query + 1 (\0) - theCQueryLength = strlen(theCQuery)+1; + switch(encoding) { + case NSUTF8StringEncoding: + theCQuery = [query UTF8String]; + break; + default: + theCQuery = (const char*)(NSString*)(int)(*cStringPtr)(self, @selector(cStringFromString:), query, encoding); + //[self cStringFromString:query usingEncoding:encoding]; + } + + // Set the length of the current query + theCQueryLength = strlen(theCQuery); // Check query length against max_allowed_packet; if it is larger, the // query would error, so if max_allowed_packet is editable for the user @@ -849,7 +859,7 @@ static void forcePingTimeout(int signalNumber); lastQueryAffectedRows = queryAffectedRows; // If an error occurred, inform the delegate - if (0 != queryResultCode && delegate && [delegate respondsToSelector:@selector(queryGaveError:)]) + if (queryResultCode & delegateResponseToWillQueryString) [delegate queryGaveError:lastQueryErrorMessage]; [self startKeepAliveTimerResettingState:YES]; -- cgit v1.2.3