diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMMCPConnection.m | 10 | ||||
-rw-r--r-- | Source/CMTextView.m | 3 | ||||
-rw-r--r-- | Source/SPStringAdditions.h | 14 |
3 files changed, 22 insertions, 5 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index bf3eac18..4cc2fccf 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -24,6 +24,7 @@ // More info at <http://code.google.com/p/sequel-pro/> #import "CMMCPConnection.h" +#import "SPStringAdditions.h" #include <unistd.h> #include <setjmp.h> @@ -140,6 +141,7 @@ static void forcePingTimeout(int signalNumber); } cStringPtr = [self methodForSelector:@selector(cStringFromString:usingEncoding:)]; + } /* @@ -446,7 +448,7 @@ static void forcePingTimeout(int signalNumber); [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", currentEncoding]]; [self setEncoding:[CMMCPConnection encodingForMySQLEncoding:[currentEncoding UTF8String]]]; if (currentEncodingUsesLatin1Transport) { - [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"]; + [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"]; } } } else if (parentWindow) { @@ -750,10 +752,10 @@ static void forcePingTimeout(int signalNumber); // Derive the query string in the correct encoding switch(encoding) { case NSUTF8StringEncoding: - theCQuery = [query UTF8String]; - break; + theCQuery = NSStringUTF8String(query); + break; default: - theCQuery = (const char*)(NSString*)(int)(*cStringPtr)(self, @selector(cStringFromString:), query, encoding); + theCQuery = (const char*)(NSString*)(int)(*cStringPtr)(self, @selector(cStringFromString:), query, encoding); //[self cStringFromString:query usingEncoding:encoding]; } diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 142663bd..8e891b20 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -2185,7 +2185,8 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) //initialise flex yyuoffset = textRange.location; yyuleng = 0; - yy_switch_to_buffer(yy_scan_string([[[self string] substringWithRange:textRange] UTF8String])); + // yy_switch_to_buffer(yy_scan_string([[[self string] substringWithRange:textRange] UTF8String])); + yy_switch_to_buffer(yy_scan_string(NSStringUTF8String([[self string] substringWithRange:textRange]))); //now loop through all the tokens while (token=yylex()){ diff --git a/Source/SPStringAdditions.h b/Source/SPStringAdditions.h index 318e8d4d..3b6805e2 100644 --- a/Source/SPStringAdditions.h +++ b/Source/SPStringAdditions.h @@ -25,6 +25,20 @@ #import <Cocoa/Cocoa.h> +/* + * NSStringUTF8String(@"a String") function can be used to speed up + * the convertion from a NSString to NSData or const char* resp. + * NSData *d = [aStr UTF8String]; :== NSData *d = NSStringUTF8String(aStr); + */ +static inline const char* NSStringUTF8String(NSString* self) { + typedef const char* (*SPUTF8StringMethodPtr)(NSString*, SEL); + static SPUTF8StringMethodPtr SPNSStringGetUTF8String; + if (!SPNSStringGetUTF8String) SPNSStringGetUTF8String = (SPUTF8StringMethodPtr)[NSString instanceMethodForSelector:@selector(UTF8String)]; + const char* to_return = SPNSStringGetUTF8String(self, @selector(UTF8String)); + return to_return; +} + + @interface NSString (SPStringAdditions) + (NSString *)stringForByteSize:(int)byteSize; |