Prefixed GSTextStorage ivars with underscore; implement length for speed

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8552 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Nicola Pero 2001-01-10 20:20:47 +00:00
parent bec90cee55
commit 04a00a7269
2 changed files with 44 additions and 34 deletions

View file

@ -1,3 +1,8 @@
Wed Jan 10 19:42:22 2001 Nicola Pero <n.pero@mi.flashnet.it>
* Source/GSTextStorage.m ([-length]): Added for speed.
* Source/GSTextStorage.m: Prefixed ivars with underscore.
Tue Jan 9 11:24:32 2001 Nicola Pero <n.pero@mi.flashnet.it> Tue Jan 9 11:24:32 2001 Nicola Pero <n.pero@mi.flashnet.it>
* Tools/Functions.m: Include AppKit/DPSOperators.h so it * Tools/Functions.m: Include AppKit/DPSOperators.h so it

View file

@ -123,8 +123,8 @@ unCacheAttributes(NSDictionary *attrs)
@interface GSTextStorage : NSTextStorage @interface GSTextStorage : NSTextStorage
{ {
NSMutableString *textChars; NSMutableString *_textChars;
NSMutableArray *infoArray; NSMutableArray *_infoArray;
} }
@end @end
@ -220,10 +220,10 @@ static IMP oatImp;
static void (*remImp)(); static void (*remImp)();
#define NEWINFO(Z,O,L) ((*infImp)(infCls, infSel, (Z), (O), (L))) #define NEWINFO(Z,O,L) ((*infImp)(infCls, infSel, (Z), (O), (L)))
#define ADDOBJECT(O) ((*addImp)(infoArray, addSel, (O))) #define ADDOBJECT(O) ((*addImp)(_infoArray, addSel, (O)))
#define INSOBJECT(O,I) ((*insImp)(infoArray, insSel, (O), (I))) #define INSOBJECT(O,I) ((*insImp)(_infoArray, insSel, (O), (I)))
#define OBJECTAT(I) ((*oatImp)(infoArray, oatSel, (I))) #define OBJECTAT(I) ((*oatImp)(_infoArray, oatSel, (I)))
#define REMOVEAT(I) ((*remImp)(infoArray, remSel, (I))) #define REMOVEAT(I) ((*remImp)(_infoArray, remSel, (I)))
static inline NSDictionary *attrDict(GSTextInfo* info) static inline NSDictionary *attrDict(GSTextInfo* info)
{ {
@ -264,9 +264,9 @@ static void
_setAttributesFrom( _setAttributesFrom(
NSAttributedString *attributedString, NSAttributedString *attributedString,
NSRange aRange, NSRange aRange,
NSMutableArray *infoArray) NSMutableArray *_infoArray)
{ {
NSZone *z = [infoArray zone]; NSZone *z = [_infoArray zone];
NSRange range; NSRange range;
NSDictionary *attr; NSDictionary *attr;
GSTextInfo *info; GSTextInfo *info;
@ -275,7 +275,7 @@ _setAttributesFrom(
/* /*
* remove any old attributes of the string. * remove any old attributes of the string.
*/ */
[infoArray removeAllObjects]; [_infoArray removeAllObjects];
if (aRange.length <= 0) if (aRange.length <= 0)
return; return;
@ -303,13 +303,13 @@ _attributesAtIndexEffectiveRange(
unsigned int index, unsigned int index,
NSRange *aRange, NSRange *aRange,
unsigned int tmpLength, unsigned int tmpLength,
NSMutableArray *infoArray, NSMutableArray *_infoArray,
unsigned int *foundIndex) unsigned int *foundIndex)
{ {
unsigned low, high, used, cnt, nextLoc; unsigned low, high, used, cnt, nextLoc;
GSTextInfo *found = nil; GSTextInfo *found = nil;
used = (*cntImp)(infoArray, cntSel); used = (*cntImp)(_infoArray, cntSel);
NSCAssert(used > 0, NSInternalInconsistencyException); NSCAssert(used > 0, NSInternalInconsistencyException);
high = used - 1; high = used - 1;
@ -393,8 +393,8 @@ _attributesAtIndexEffectiveRange(
GSTextInfo *info; GSTextInfo *info;
unsigned i; unsigned i;
unsigned l = 0; unsigned l = 0;
unsigned len = [textChars length]; unsigned len = [_textChars length];
unsigned c = (*cntImp)(infoArray, cntSel); unsigned c = (*cntImp)(_infoArray, cntSel);
NSAssert(c > 0, NSInternalInconsistencyException); NSAssert(c > 0, NSInternalInconsistencyException);
info = OBJECTAT(0); info = OBJECTAT(0);
@ -454,15 +454,15 @@ _attributesAtIndexEffectiveRange(
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];
[aCoder encodeValueOfObjCType: @encode(id) at: &textChars]; [aCoder encodeValueOfObjCType: @encode(id) at: &_textChars];
[aCoder encodeValueOfObjCType: @encode(id) at: &infoArray]; [aCoder encodeValueOfObjCType: @encode(id) at: &_infoArray];
} }
- (id) initWithCoder: (NSCoder*)aCoder - (id) initWithCoder: (NSCoder*)aCoder
{ {
self = [super initWithCoder: aCoder]; self = [super initWithCoder: aCoder];
[aCoder decodeValueOfObjCType: @encode(id) at: &textChars]; [aCoder decodeValueOfObjCType: @encode(id) at: &_textChars];
[aCoder decodeValueOfObjCType: @encode(id) at: &infoArray]; [aCoder decodeValueOfObjCType: @encode(id) at: &_infoArray];
return self; return self;
} }
@ -472,13 +472,13 @@ _attributesAtIndexEffectiveRange(
NSZone *z = [self zone]; NSZone *z = [self zone];
self = [super initWithString: aString attributes: attributes]; self = [super initWithString: aString attributes: attributes];
infoArray = [[NSMutableArray allocWithZone: z] initWithCapacity: 1]; _infoArray = [[NSMutableArray allocWithZone: z] initWithCapacity: 1];
if (aString != nil && [aString isKindOfClass: [NSAttributedString class]]) if (aString != nil && [aString isKindOfClass: [NSAttributedString class]])
{ {
NSAttributedString *as = (NSAttributedString*)aString; NSAttributedString *as = (NSAttributedString*)aString;
aString = [as string]; aString = [as string];
_setAttributesFrom(as, NSMakeRange(0, [aString length]), infoArray); _setAttributesFrom(as, NSMakeRange(0, [aString length]), _infoArray);
} }
else else
{ {
@ -494,15 +494,15 @@ _attributesAtIndexEffectiveRange(
RELEASE(info); RELEASE(info);
} }
if (aString == nil) if (aString == nil)
textChars = [[NSMutableString allocWithZone: z] init]; _textChars = [[NSMutableString allocWithZone: z] init];
else else
textChars = [aString mutableCopyWithZone: z]; _textChars = [aString mutableCopyWithZone: z];
return self; return self;
} }
- (NSString*) string - (NSString*) string
{ {
return AUTORELEASE([textChars copyWithZone: NSDefaultMallocZone()]); return AUTORELEASE([_textChars copyWithZone: NSDefaultMallocZone()]);
} }
- (NSDictionary*) attributesAtIndex: (unsigned)index - (NSDictionary*) attributesAtIndex: (unsigned)index
@ -511,7 +511,7 @@ _attributesAtIndexEffectiveRange(
unsigned dummy; unsigned dummy;
return _attributesAtIndexEffectiveRange( return _attributesAtIndexEffectiveRange(
index, aRange, [textChars length], infoArray, &dummy); index, aRange, [_textChars length], _infoArray, &dummy);
} }
/* /*
@ -545,9 +545,9 @@ _attributesAtIndexEffectiveRange(
} }
attributes = cacheAttributes(attributes); attributes = cacheAttributes(attributes);
SANITY(); SANITY();
tmpLength = [textChars length]; tmpLength = [_textChars length];
GS_RANGE_CHECK(range, tmpLength); GS_RANGE_CHECK(range, tmpLength);
arraySize = (*cntImp)(infoArray, cntSel); arraySize = (*cntImp)(_infoArray, cntSel);
beginRangeLoc = range.location; beginRangeLoc = range.location;
afterRangeLoc = NSMaxRange(range); afterRangeLoc = NSMaxRange(range);
if (afterRangeLoc < tmpLength) if (afterRangeLoc < tmpLength)
@ -556,7 +556,7 @@ SANITY();
* Locate the first range that extends beyond our range. * Locate the first range that extends beyond our range.
*/ */
attrs = _attributesAtIndexEffectiveRange( attrs = _attributesAtIndexEffectiveRange(
afterRangeLoc, &effectiveRange, tmpLength, infoArray, &arrayIndex); afterRangeLoc, &effectiveRange, tmpLength, _infoArray, &arrayIndex);
if (attrs == attributes) if (attrs == attributes)
{ {
/* /*
@ -666,7 +666,7 @@ SANITY();
{ {
aString = @""; aString = @"";
} }
tmpLength = [textChars length]; tmpLength = [_textChars length];
GS_RANGE_CHECK(range, tmpLength); GS_RANGE_CHECK(range, tmpLength);
if (range.location == tmpLength) if (range.location == tmpLength)
{ {
@ -674,18 +674,18 @@ SANITY();
* Special case - replacing a zero length string at the end * Special case - replacing a zero length string at the end
* simply appends the new string and attributes are inherited. * simply appends the new string and attributes are inherited.
*/ */
[textChars appendString: aString]; [_textChars appendString: aString];
goto finish; goto finish;
} }
arraySize = (*cntImp)(infoArray, cntSel); arraySize = (*cntImp)(_infoArray, cntSel);
if (arraySize == 1) if (arraySize == 1)
{ {
/* /*
* Special case - if the string has only one set of attributes * Special case - if the string has only one set of attributes
* then the replacement characters will get them too. * then the replacement characters will get them too.
*/ */
[textChars replaceCharactersInRange: range withString: aString]; [_textChars replaceCharactersInRange: range withString: aString];
goto finish; goto finish;
} }
@ -700,7 +700,7 @@ SANITY();
else else
start = range.location; start = range.location;
attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange, attrs = _attributesAtIndexEffectiveRange(start, &effectiveRange,
tmpLength, infoArray, &arrayIndex); tmpLength, _infoArray, &arrayIndex);
arrayIndex++; arrayIndex++;
if (NSMaxRange(effectiveRange) < NSMaxRange(range)) if (NSMaxRange(effectiveRange) < NSMaxRange(range))
@ -758,7 +758,7 @@ SANITY();
info->loc += moveLocations; info->loc += moveLocations;
arrayIndex++; arrayIndex++;
} }
[textChars replaceCharactersInRange: range withString: aString]; [_textChars replaceCharactersInRange: range withString: aString];
finish: finish:
SANITY(); SANITY();
@ -769,9 +769,14 @@ changeInLength: [aString length] - range.length];
- (void) dealloc - (void) dealloc
{ {
RELEASE(textChars); RELEASE(_textChars);
RELEASE(infoArray); RELEASE(_infoArray);
[super dealloc]; [super dealloc];
} }
// The superclass implementation is correct but too slow
- (unsigned int) length
{
return [_textChars length];
}
@end @end