ICU-1027 move fLength back from Replaceable to UnicodeString, add virtual Rep::getLength()

X-SVN-Rev: 5156
This commit is contained in:
Markus Scherer 2001-07-02 20:58:14 +00:00
parent db3c833b55
commit 2fc1e2ef98
4 changed files with 40 additions and 32 deletions

View File

@ -160,39 +160,28 @@ protected:
Replaceable();
/**
* Constructor with initial length.
* Virtual version of length().
*/
Replaceable(int32_t initialLength);
virtual int32_t getLength() const = 0;
/**
* Virtual version of charAt().
* This allows UnicodeString::charAt() to be inline again (see jitterbug 709).
*/
virtual UChar getCharAt(UTextOffset offset) const = 0;
/**
* Virtual version of char32At().
* This allows UnicodeString::char32At() to be inline again (see jitterbug 709).
*/
virtual UChar32 getChar32At(UTextOffset offset) const = 0;
/**
* This field must always reflect the number of UChars in the text
* object. A subclass must keep this up to date.
* Moved here from UnicodeString so that length() can be inline (see jitterbug 709).
*/
int32_t fLength; // number characters in fArray
};
inline Replaceable::Replaceable() : fLength(0) {}
inline Replaceable::Replaceable(int32_t initialLength) : fLength(initialLength) {}
inline Replaceable::Replaceable() {}
inline Replaceable::~Replaceable() {}
inline int32_t
Replaceable::length() const {
return fLength;
return getLength();
}
inline UChar

View File

@ -2203,6 +2203,11 @@ public:
//========================================
protected:
/**
* Implement Replaceable::getLength() (see jitterbug 1027).
*/
virtual int32_t getLength() const;
/**
* The change in Replaceable to use virtual getCharAt() allows
* UnicodeString::charAt() to be inline again (see jitterbug 709).
@ -2422,8 +2427,7 @@ private:
* on 64-bit machines (8-byte pointers), it should be 40 bytes.
*/
// (implicit) *vtable;
// fLength is moved into the superclass Replaceable (jitterbug 709)
// int32_t fLength; // number characters in fArray
int32_t fLength; // number of characters in fArray
int32_t fCapacity; // sizeof fArray
UChar *fArray; // the Unicode data
uint16_t fFlags; // bit flags: see constants above

View File

@ -94,13 +94,15 @@ UConverter* UnicodeString::fgDefaultConverter = 0;
// Constructors
//========================================
UnicodeString::UnicodeString()
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{}
UnicodeString::UnicodeString(int32_t capacity, UChar32 c, int32_t count)
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(0),
fFlags(0)
{
@ -164,7 +166,7 @@ UnicodeString::UnicodeString(int32_t capacity, UChar32 c, int32_t count)
}
UnicodeString::UnicodeString(UChar ch)
: Replaceable(1),
: fLength(1),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
@ -173,7 +175,7 @@ UnicodeString::UnicodeString(UChar ch)
}
UnicodeString::UnicodeString(UChar32 ch)
: Replaceable(1),
: fLength(1),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
@ -184,7 +186,8 @@ UnicodeString::UnicodeString(UChar32 ch)
}
UnicodeString::UnicodeString(const UChar *text)
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
@ -193,7 +196,8 @@ UnicodeString::UnicodeString(const UChar *text)
UnicodeString::UnicodeString(const UChar *text,
int32_t textLength)
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
@ -203,7 +207,7 @@ UnicodeString::UnicodeString(const UChar *text,
UnicodeString::UnicodeString(UBool isTerminated,
const UChar *text,
int32_t textLength)
: Replaceable(textLength),
: fLength(textLength),
fCapacity(isTerminated ? textLength + 1 : textLength),
fArray((UChar *)text),
fFlags(kReadonlyAlias)
@ -220,7 +224,7 @@ UnicodeString::UnicodeString(UBool isTerminated,
UnicodeString::UnicodeString(UChar *buff,
int32_t bufLength,
int32_t buffCapacity)
: Replaceable(bufLength),
: fLength(bufLength),
fCapacity(buffCapacity),
fArray(buff),
fFlags(kWriteableAlias)
@ -232,7 +236,8 @@ UnicodeString::UnicodeString(UChar *buff,
UnicodeString::UnicodeString(const char *codepageData,
const char *codepage)
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
@ -245,7 +250,8 @@ UnicodeString::UnicodeString(const char *codepageData,
UnicodeString::UnicodeString(const char *codepageData,
int32_t dataLength,
const char *codepage)
: fCapacity(US_STACKBUF_SIZE),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
@ -255,7 +261,7 @@ UnicodeString::UnicodeString(const char *codepageData,
}
UnicodeString::UnicodeString(const UnicodeString& that)
: Replaceable(),
: fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
@ -618,6 +624,11 @@ UnicodeString::doCaseCompare(UTextOffset start,
}
}
int32_t
UnicodeString::getLength() const {
return length();
}
UChar
UnicodeString::getCharAt(UTextOffset offset) const {
return charAt(offset);

View File

@ -52,6 +52,8 @@ public:
protected:
virtual int32_t getLength() const;
virtual UChar getCharAt(UTextOffset offset) const;
virtual UChar32 getChar32At(UTextOffset offset) const;
@ -60,7 +62,7 @@ protected:
ReplaceableGlue::ReplaceableGlue(UReplaceable *replaceable,
UReplaceableCallbacks *funcCallback)
: Replaceable((*funcCallback->length)(replaceable))
: Replaceable()
{
this->rep = replaceable;
this->func = funcCallback;
@ -72,6 +74,10 @@ ReplaceableGlue::~ReplaceableGlue() {
delete[] buf;
}
int32_t ReplaceableGlue::getLength() const {
return (*func->length)(rep);
}
UChar ReplaceableGlue::getCharAt(UTextOffset offset) const {
return (*func->charAt)(rep, offset);
}
@ -91,12 +97,10 @@ void ReplaceableGlue::handleReplaceBetween(UTextOffset start,
}
text.extract(0, len, buf);
(*func->replace)(rep, start, limit, buf, len);
fLength = (*func->length)(rep);
}
void ReplaceableGlue::copy(int32_t start, int32_t limit, int32_t dest) {
(*func->copy)(rep, start, limit, dest);
fLength = (*func->length)(rep);
}
/********************************************************************