Revision: 4747
http://skim-app.svn.sourceforge.net/skim-app/?rev=4747&view=rev
Author: amaxwell
Date: 2008-10-07 03:26:18 +0000 (Tue, 07 Oct 2008)
Log Message:
-----------
Minor simplifications and performance tweak; using CFCharacterSet is 3x slower
than a comparison function for this simplistic charset. Note radar number.
Modified Paths:
--------------
trunk/NSCharacterSet_SKExtensions.h
trunk/NSCharacterSet_SKExtensions.m
trunk/NSString_SKExtensions.m
Modified: trunk/NSCharacterSet_SKExtensions.h
===================================================================
--- trunk/NSCharacterSet_SKExtensions.h 2008-10-06 22:58:24 UTC (rev 4746)
+++ trunk/NSCharacterSet_SKExtensions.h 2008-10-07 03:26:18 UTC (rev 4747)
@@ -42,5 +42,4 @@
@interface NSCharacterSet (SKExtensions)
+ (id)nonWhitespaceCharacterSet;
+ (id)nonWhitespaceAndNewlineCharacterSet;
-+ (id)privateUseCharacterSet;
@end
Modified: trunk/NSCharacterSet_SKExtensions.m
===================================================================
--- trunk/NSCharacterSet_SKExtensions.m 2008-10-06 22:58:24 UTC (rev 4746)
+++ trunk/NSCharacterSet_SKExtensions.m 2008-10-07 03:26:18 UTC (rev 4747)
@@ -68,20 +68,6 @@
return nonWhitespaceAndNewlineCharacterSet;
}
-+ (id)privateUseCharacterSet {
- static NSCharacterSet *privateUseCharacterSet = nil;
- if (nil == privateUseCharacterSet) {
- // supplementary private use B
- NSMutableCharacterSet *mcs = [NSMutableCharacterSet
characterSetWithRange:NSMakeRange(0x100000, 0x10FFFF-0x100000)];
- // supplementary private use A
- [mcs addCharactersInRange:NSMakeRange(0xF0000, 0xFFFFF-0xF0000)];
- // private use area
- [mcs addCharactersInRange:NSMakeRange(0xE000, 0xF8FF-0xE000)];
- privateUseCharacterSet = [mcs copy];
- }
- return privateUseCharacterSet;
-}
-
+ (void)load {
SKAddClassMethodImplementationFromSelector(self,
@selector(newlineCharacterSet), @selector(replacementNewlineCharacterSet));
}
Modified: trunk/NSString_SKExtensions.m
===================================================================
--- trunk/NSString_SKExtensions.m 2008-10-06 22:58:24 UTC (rev 4746)
+++ trunk/NSString_SKExtensions.m 2008-10-07 03:26:18 UTC (rev 4747)
@@ -143,43 +143,49 @@
return
[(id)SKStringCreateByCollapsingAndTrimmingWhitespaceAndNewlines(CFAllocatorGetDefault(),
(CFStringRef)self) autorelease];
}
-// NS and CF character sets won't find these, due to the way CFString handles
surrogate pairs. These inlines were borrowed from CFCharacterSetPriv.h in
CF-lite-476.13.
-static inline bool __SKIsSurrogateHighCharacter(UniChar character) {
+// NS and CF character sets won't find these, due to the way CFString handles
surrogate pairs. The surrogate pair inlines were borrowed from
CFCharacterSetPriv.h in CF-lite-476.13.
+static inline bool __SKIsSurrogateHighCharacter(const UniChar character) {
return ((character >= 0xD800UL) && (character <= 0xDBFFUL) ? true : false);
}
-static inline bool __SKIsSurrogateLowCharacter(UniChar character) {
+static inline bool __SKIsSurrogateLowCharacter(const UniChar character) {
return ((character >= 0xDC00UL) && (character <= 0xDFFFUL) ? true : false);
}
-static inline UTF32Char __SKGetLongCharacterForSurrogatePair(UniChar
surrogateHigh, UniChar surrogateLow) {
+static inline UTF32Char __SKGetLongCharacterForSurrogatePair(const UniChar
surrogateHigh, const UniChar surrogateLow) {
return ((surrogateHigh - 0xD800UL) << 10) + (surrogateLow - 0xDC00UL) +
0x0010000UL;
}
+static inline bool __SKIsPrivateUseCharacter(const UTF32Char ch)
+{
+ return ((ch >= 0xE000UL && ch <= 0xF8FFUL) || /* private use area */
+ (ch >= 0xF0000UL && ch <= 0xFFFFFUL) || /* supplementary private
use A */
+ (ch >= 0x100000UL && ch <= 0x10FFFFUL)); /* supplementary private
use B */
+}
+
#define SURROGATE_START 0xD800
#define SURROGATE_END 0xDFFF
-// remove anything in the private use planes, and/or malformed surrogate pair
sequences
+// Remove anything in the private use planes, and/or malformed surrogate pair
sequences rdar://problem/6273932
- (NSString *)stringByRemovingAliens {
// make a mutable copy only if needed
- CFMutableStringRef theString = NULL;
+ CFMutableStringRef theString = (void *)self;
CFStringInlineBuffer inlineBuffer;
- CFIndex length = CFStringGetLength((void *)self);
+ CFIndex length = CFStringGetLength(theString);
// use the current mutable string with the inline buffer, but make a new
mutable copy if needed
- CFStringInitInlineBuffer((void *)self, &inlineBuffer, CFRangeMake(0,
length));
+ CFStringInitInlineBuffer(theString, &inlineBuffer, CFRangeMake(0, length));
UniChar ch;
- NSCharacterSet *privateUse = [NSCharacterSet privateUseCharacterSet];
-#define LAZY_COPY do{if(NULL==theString){theString=(void*)[[self mutableCopy]
autorelease];}} while(0)
+#define LAZY_COPY do{if((void*)self==theString){theString=(void*)[[self
mutableCopyWithZone:[self zone]] autorelease];}} while(0)
// idx is current index into the inline buffer, and delIdx is current
index in the mutable string
CFIndex idx = 0, delIdx = 0;
while(idx < length){
ch = CFStringGetCharacterFromInlineBuffer(&inlineBuffer, idx);
- if ([privateUse characterIsMember:ch]) {
+ if (__SKIsPrivateUseCharacter(ch)) {
LAZY_COPY;
CFStringDelete(theString, CFRangeMake(delIdx, 1));
} else if ((ch >= SURROGATE_START) && (ch <= SURROGATE_END)) {
@@ -194,7 +200,7 @@
LAZY_COPY;
CFStringDelete(theString, CFRangeMake(delIdx, 1));
// only deleted a single char, so don't need to adjust idx
- } else if
(CFCharacterSetIsLongCharacterMember((CFCharacterSetRef)privateUse, longChar)) {
+ } else if (__SKIsPrivateUseCharacter(longChar)) {
LAZY_COPY;
// remove the pair; can't display private use characters
CFStringDelete(theString, CFRangeMake(delIdx, 2));
@@ -219,7 +225,7 @@
idx++;
}
- return (NULL == theString ? self : (id)theString);
+ return (id)theString;
}
- (NSString *)stringByAppendingEllipsis;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit