ICU-709 resolve virtual/inline conflict, details see jitterbug response

X-SVN-Rev: 3625
This commit is contained in:
Markus Scherer 2001-02-14 18:02:44 +00:00
parent a5b8dad588
commit 55b780688e
4 changed files with 108 additions and 50 deletions

View file

@ -54,18 +54,18 @@ public:
/**
* Return the number of characters in the text.
* @return number of characters in text
* @draft
* @draft ICU 1.8
*/
virtual int32_t length() const = 0;
inline int32_t length() const;
/**
* Return the Unicode code unit at the given offset into the text.
* @param offset an integer between 0 and <code>length()</code>-1
* inclusive
* @return code unit of text at given offset
* @draft
* @draft ICU 1.8
*/
virtual UChar charAt(UTextOffset offset) const = 0;
inline UChar charAt(UTextOffset offset) const;
/**
* Return the Unicode code point that contains the code unit
@ -74,9 +74,9 @@ public:
* inclusive that indicates the text offset of any of the code units
* that will be assembled into a code point (21-bit value) and returned
* @return code point of text at given offset
* @draft
* @draft ICU 1.8
*/
virtual UChar32 char32At(UTextOffset offset) const = 0;
inline UChar32 char32At(UTextOffset offset) const;
/**
* Copy characters from this object into the destination character
@ -158,10 +158,51 @@ protected:
* Default constructor.
*/
Replaceable();
/**
* Constructor with initial length.
*/
Replaceable(int32_t initialLength);
/**
* 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() {}
inline Replaceable::Replaceable() : fLength(0) {}
inline Replaceable::Replaceable(int32_t initialLength) : fLength(initialLength) {}
inline Replaceable::~Replaceable() {}
inline int32_t
Replaceable::length() const {
return fLength;
}
inline UChar
Replaceable::charAt(UTextOffset offset) const {
return getCharAt(offset);
}
inline UChar32
Replaceable::char32At(UTextOffset offset) const {
return getChar32At(offset);
}
#endif

View file

@ -2214,6 +2214,19 @@ public:
// Implementation methods
//========================================
protected:
/**
* The change in Replaceable to use virtual getCharAt() allows
* UnicodeString::charAt() to be inline again (see jitterbug 709).
*/
virtual UChar getCharAt(UTextOffset offset) const;
/**
* The change in Replaceable to use virtual getChar32At() allows
* UnicodeString::char32At() to be inline again (see jitterbug 709).
*/
virtual UChar32 getChar32At(UTextOffset offset) const;
private:
inline int8_t
@ -2425,9 +2438,10 @@ private:
* on 64-bit machines (8-byte pointers), it should be 40 bytes.
*/
// (implicit) *vtable;
UChar *fArray; // the Unicode data
int32_t fLength; // number characters in fArray
// fLength is moved into the superclass Replaceable (jitterbug 709)
// int32_t fLength; // number characters in fArray
int32_t fCapacity; // sizeof fArray
UChar *fArray; // the Unicode data
uint16_t fFlags; // bit flags: see constants above
#if UTF_SIZE==32
uint16_t fPadding; // padding to align the fStackBuffer for UTF-32

View file

@ -92,16 +92,14 @@ UConverter* UnicodeString::fgDefaultConverter = 0;
// Constructors
//========================================
UnicodeString::UnicodeString()
: fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{}
UnicodeString::UnicodeString(int32_t capacity, UChar32 c, int32_t count)
: fArray(0),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(0),
fFlags(0)
{
if(count <= 0) {
@ -164,18 +162,18 @@ UnicodeString::UnicodeString(int32_t capacity, UChar32 c, int32_t count)
}
UnicodeString::UnicodeString(UChar ch)
: fArray(fStackBuffer),
fLength(1),
: Replaceable(1),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
fStackBuffer[0] = ch;
}
UnicodeString::UnicodeString(UChar32 ch)
: fArray(fStackBuffer),
fLength(1),
: Replaceable(1),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
UTextOffset i = 0;
@ -184,9 +182,8 @@ UnicodeString::UnicodeString(UChar32 ch)
}
UnicodeString::UnicodeString(const UChar *text)
: fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
doReplace(0, 0, text, 0, u_strlen(text));
@ -194,9 +191,8 @@ UnicodeString::UnicodeString(const UChar *text)
UnicodeString::UnicodeString(const UChar *text,
int32_t textLength)
: fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
doReplace(0, 0, text, 0, textLength);
@ -205,9 +201,9 @@ UnicodeString::UnicodeString(const UChar *text,
UnicodeString::UnicodeString(UBool isTerminated,
const UChar *text,
int32_t textLength)
: fArray((UChar *)text),
fLength(textLength),
: Replaceable(textLength),
fCapacity(isTerminated ? textLength + 1 : textLength),
fArray((UChar *)text),
fFlags(kReadonlyAlias)
{
if(text == 0 || textLength < -1 || textLength == -1 && !isTerminated) {
@ -222,9 +218,9 @@ UnicodeString::UnicodeString(UBool isTerminated,
UnicodeString::UnicodeString(UChar *buff,
int32_t bufLength,
int32_t buffCapacity)
: fArray(buff),
fLength(bufLength),
: Replaceable(bufLength),
fCapacity(buffCapacity),
fArray(buff),
fFlags(kWriteableAlias)
{
if(buff == 0 || bufLength < 0 || bufLength > buffCapacity) {
@ -234,9 +230,8 @@ UnicodeString::UnicodeString(UChar *buff,
UnicodeString::UnicodeString(const char *codepageData,
const char *codepage)
: fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
if(codepageData != 0) {
@ -248,9 +243,8 @@ UnicodeString::UnicodeString(const char *codepageData,
UnicodeString::UnicodeString(const char *codepageData,
int32_t dataLength,
const char *codepage)
: fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
: fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
if(codepageData != 0) {
@ -260,9 +254,8 @@ UnicodeString::UnicodeString(const char *codepageData,
UnicodeString::UnicodeString(const UnicodeString& that)
: Replaceable(),
fArray(fStackBuffer),
fLength(0),
fCapacity(US_STACKBUF_SIZE),
fArray(fStackBuffer),
fFlags(kShortString)
{
*this = that;
@ -642,6 +635,16 @@ UnicodeString::doCaseCompare(UTextOffset start,
}
}
UChar
UnicodeString::getCharAt(UTextOffset offset) const {
return charAt(offset);
}
UChar32
UnicodeString::getChar32At(UTextOffset offset) const {
return char32At(offset);
}
void
UnicodeString::doExtract(UTextOffset start,
int32_t length,

View file

@ -44,22 +44,24 @@ public:
virtual ~ReplaceableGlue();
virtual int32_t length() const;
virtual UChar charAt(UTextOffset offset) const;
virtual UChar32 char32At(UTextOffset offset) const;
virtual void handleReplaceBetween(UTextOffset start,
UTextOffset limit,
const UnicodeString& text);
virtual void copy(int32_t start, int32_t limit, int32_t dest);
protected:
virtual UChar getCharAt(UTextOffset offset) const;
virtual UChar32 getChar32At(UTextOffset offset) const;
};
ReplaceableGlue::ReplaceableGlue(UReplaceable *replaceable,
UReplaceableCallbacks *funcCallback) {
UReplaceableCallbacks *funcCallback)
: Replaceable((*funcCallback->length)(replaceable))
{
this->rep = replaceable;
this->func = funcCallback;
buf = 0;
@ -70,15 +72,11 @@ ReplaceableGlue::~ReplaceableGlue() {
delete[] buf;
}
int32_t ReplaceableGlue::length() const {
return (*func->length)(rep);
}
UChar ReplaceableGlue::charAt(UTextOffset offset) const {
UChar ReplaceableGlue::getCharAt(UTextOffset offset) const {
return (*func->charAt)(rep, offset);
}
UChar32 ReplaceableGlue::char32At(UTextOffset offset) const {
UChar32 ReplaceableGlue::getChar32At(UTextOffset offset) const {
return (*func->char32At)(rep, offset);
}
@ -93,10 +91,12 @@ 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);
}
/********************************************************************