Author: rfm
Date: Fri Jul 1 17:22:02 2016
New Revision: 39956
URL: http://svn.gna.org/viewcvs/gnustep?rev=39956&view=rev
Log:
Optimisation for ICU access to immutable NSString objects ... we don't need to
call -length every time because we can keep the length in the UText state.
Modified:
libs/base/trunk/ChangeLog
libs/base/trunk/Source/GSICUString.m
Modified: libs/base/trunk/ChangeLog
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/ChangeLog?rev=39956&r1=39955&r2=39956&view=diff
==============================================================================
--- libs/base/trunk/ChangeLog (original)
+++ libs/base/trunk/ChangeLog Fri Jul 1 17:22:02 2016
@@ -1,3 +1,8 @@
+2016-07-01 Richard Frith-Macdonald <[email protected]>
+
+ * Source/GSICUString.m: For immutable strings, cache the string
+ length in the UText structure to avoid repeated calls to -length
+
2016-06-30 Richard Frith-Macdonald <[email protected]>
* Source/GSICUString.m: Re-implement the function to let ICU access
Modified: libs/base/trunk/Source/GSICUString.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/trunk/Source/GSICUString.m?rev=39956&r1=39955&r2=39956&view=diff
==============================================================================
--- libs/base/trunk/Source/GSICUString.m (original)
+++ libs/base/trunk/Source/GSICUString.m Fri Jul 1 17:22:02 2016
@@ -40,7 +40,10 @@
static int64_t
UTextNSStringNativeLength(UText *ut)
{
- return [(NSString*)ut->p length];
+ /* For constant strings the length is stored in ut->c, but for mutable
+ * strings this is set to -1 and we must check the length every time.
+ */
+ return (-1 == ut->c) ? [(NSString*)ut->p length] : ut->c;
}
@@ -52,7 +55,7 @@
UTextNSStringAccess(UText *ut, int64_t nativeIndex, UBool forward)
{
NSString *str = (NSString*)ut->p;
- NSUInteger length = [str length];
+ NSUInteger length = (-1 == ut->c) ? [str length] : ut->c;
NSUInteger nativeStart = ut->chunkNativeStart;
NSUInteger nativeLimit = ut->chunkNativeLimit;
NSRange r;
@@ -153,9 +156,10 @@
}
else
{
- replacement = [replacement initWithCharactersNoCopy:
(unichar*)replacementText
- length: replacmentLength
- freeWhenDone: NO];
+ replacement = [replacement
+ initWithCharactersNoCopy: (unichar*)replacementText
+ length: replacmentLength
+ freeWhenDone: NO];
}
[str replaceCharactersInRange: r withString: replacement];
@@ -185,34 +189,35 @@
int32_t destCapacity,
UErrorCode *status)
{
- NSString *str;
- NSUInteger length;
- NSRange r;
-
/* If we're loading no characters, we are expected to return the number of
* characters that we could load if requested.
*/
- if (destCapacity == 0)
+ if (destCapacity <= 0)
{
return nativeLimit - nativeStart;
}
- str = (NSString*)ut->p;
- length = [str length];
- if (nativeLimit > length)
- {
- nativeLimit = length;
- }
- r = NSMakeRange(nativeStart, nativeLimit - nativeStart );
- if (destCapacity < r.length)
- {
- r.length = destCapacity;
- }
- [str getCharacters: dest range: r];
- if (destCapacity > r.length)
- {
- dest[r.length] = 0;
- }
- return r.length;
+ else
+ {
+ NSString *str = (NSString*)ut->p;
+ NSUInteger length = (-1 == ut->c) ? [str length] : ut->c;
+ NSRange r;
+
+ if (nativeLimit > length)
+ {
+ nativeLimit = length;
+ }
+ r = NSMakeRange(nativeStart, nativeLimit - nativeStart );
+ if (destCapacity < r.length)
+ {
+ r.length = destCapacity;
+ }
+ [str getCharacters: dest range: r];
+ if (destCapacity > r.length)
+ {
+ dest[r.length] = 0;
+ }
+ return r.length;
+ }
}
/**
@@ -226,7 +231,7 @@
UErrorCode *status)
{
NSMutableString *str = (NSMutableString*)ut->p;
- NSUInteger length = [str length];
+ NSUInteger length = (-1 == ut->c) ? [str length] : ut->c;
NSRange r;
NSString *substr;
@@ -374,7 +379,7 @@
txt->pFuncs = &NSMutableStringFuncs;
txt->chunkContents = txt->pExtra;
txt->nativeIndexingLimit = INT32_MAX;
-
+ txt->c = -1; // Need to fetch length every time
txt->providerProperties = 1<<UTEXT_PROVIDER_WRITABLE;
return txt;
@@ -395,6 +400,7 @@
txt->pFuncs = &NSStringFuncs;
txt->chunkContents = txt->pExtra;
txt->nativeIndexingLimit = INT32_MAX;
+ txt->c = [str length];
return txt;
}
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs