mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-23 13:04:28 +00:00
Changed to have the stack buffer embedded in the xformer
This commit is contained in:
parent
064ccf67be
commit
2cdc8576a2
@ -39,12 +39,10 @@ static nsICaseConversion* gCaseConv = nsnull;
|
||||
|
||||
#define MAX_UNIBYTE 127
|
||||
|
||||
nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
nsILineBreaker* aLineBreaker,
|
||||
nsTextTransformer::nsTextTransformer(nsILineBreaker* aLineBreaker,
|
||||
nsIWordBreaker* aWordBreaker)
|
||||
: mAutoBuffer(aBuffer),
|
||||
mBuffer(aBuffer),
|
||||
mBufferLength(aBufLen < 0 ? 0 : aBufLen),
|
||||
: mBuffer(mAutoWordBuffer),
|
||||
mBufferLength(NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE),
|
||||
mHasMultibyte(PR_FALSE),
|
||||
mLineBreaker(aLineBreaker),
|
||||
mWordBreaker(aWordBreaker)
|
||||
@ -53,7 +51,7 @@ nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
|
||||
nsTextTransformer::~nsTextTransformer()
|
||||
{
|
||||
if (mBuffer != mAutoBuffer) {
|
||||
if (mBuffer != mAutoWordBuffer) {
|
||||
delete [] mBuffer;
|
||||
}
|
||||
}
|
||||
@ -63,14 +61,6 @@ nsTextTransformer::Init(nsIFrame* aFrame,
|
||||
nsIContent* aContent,
|
||||
PRInt32 aStartingOffset)
|
||||
{
|
||||
// Make sure we have *some* space in case arguments to the ctor were
|
||||
// bizzare.
|
||||
if (mBufferLength < 100) {
|
||||
if (!GrowBuffer()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the frames text content
|
||||
nsITextContent* tc;
|
||||
if (NS_OK != aContent->QueryInterface(kITextContentIID, (void**) &tc)) {
|
||||
@ -143,8 +133,9 @@ nsTextTransformer::GrowBuffer(PRBool aForNextWord)
|
||||
if(aForNextWord)
|
||||
nsCRT::memcpy(newBuffer, mBuffer, sizeof(PRUnichar) * mBufferLength);
|
||||
else
|
||||
nsCRT::memcpy(&newBuffer[mBufferLength], mBuffer, sizeof(PRUnichar) * mBufferLength);
|
||||
if (mBuffer != mAutoBuffer) {
|
||||
nsCRT::memcpy(&newBuffer[mBufferLength], mBuffer,
|
||||
sizeof(PRUnichar) * mBufferLength);
|
||||
if (mBuffer != mAutoWordBuffer) {
|
||||
delete [] mBuffer;
|
||||
}
|
||||
}
|
||||
@ -678,10 +669,3 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
|
||||
#endif
|
||||
return &(mBuffer[mBufferLength-wordLen]);
|
||||
}
|
||||
|
||||
PRUnichar*
|
||||
nsTextTransformer::GetTextAt(PRInt32 aOffset)
|
||||
{
|
||||
// XXX
|
||||
return mBuffer + aOffset;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ class nsTextRun;
|
||||
class nsILineBreaker;
|
||||
class nsIWordBreaker;
|
||||
|
||||
#define NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE 100
|
||||
|
||||
/**
|
||||
* This object manages the transformation of text:
|
||||
*
|
||||
@ -46,11 +48,10 @@ class nsIWordBreaker;
|
||||
*/
|
||||
class nsTextTransformer {
|
||||
public:
|
||||
|
||||
// The text transformer does not hold a reference to the line breaker
|
||||
// and work breaker objects
|
||||
nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
nsILineBreaker* aLineBreaker, nsIWordBreaker *aWordBreaker);
|
||||
// Note: The text transformer does not hold a reference to the line
|
||||
// breaker and work breaker objects
|
||||
nsTextTransformer(nsILineBreaker* aLineBreaker,
|
||||
nsIWordBreaker *aWordBreaker);
|
||||
|
||||
~nsTextTransformer();
|
||||
|
||||
@ -82,12 +83,17 @@ public:
|
||||
return mHasMultibyte;
|
||||
}
|
||||
|
||||
PRUnichar* GetTextAt(PRInt32 aOffset);
|
||||
PRUnichar* GetWordBuffer() {
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRInt32 GetWordBufferLength() const {
|
||||
return mBufferLength;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRBool GrowBuffer(PRBool aForNextWord=PR_TRUE);
|
||||
PRBool GrowBuffer(PRBool aForNextWord = PR_TRUE);
|
||||
|
||||
PRUnichar* mAutoBuffer;
|
||||
PRUnichar* mBuffer;
|
||||
PRInt32 mBufferLength;
|
||||
PRBool mHasMultibyte;
|
||||
@ -106,6 +112,8 @@ protected:
|
||||
|
||||
nsILineBreaker* mLineBreaker; // does NOT hold reference
|
||||
nsIWordBreaker* mWordBreaker; // does NOT hold reference
|
||||
|
||||
PRUnichar mAutoWordBuffer[NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE];
|
||||
};
|
||||
|
||||
#endif /* nsTextTransformer_h___ */
|
||||
|
@ -39,12 +39,10 @@ static nsICaseConversion* gCaseConv = nsnull;
|
||||
|
||||
#define MAX_UNIBYTE 127
|
||||
|
||||
nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
nsILineBreaker* aLineBreaker,
|
||||
nsTextTransformer::nsTextTransformer(nsILineBreaker* aLineBreaker,
|
||||
nsIWordBreaker* aWordBreaker)
|
||||
: mAutoBuffer(aBuffer),
|
||||
mBuffer(aBuffer),
|
||||
mBufferLength(aBufLen < 0 ? 0 : aBufLen),
|
||||
: mBuffer(mAutoWordBuffer),
|
||||
mBufferLength(NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE),
|
||||
mHasMultibyte(PR_FALSE),
|
||||
mLineBreaker(aLineBreaker),
|
||||
mWordBreaker(aWordBreaker)
|
||||
@ -53,7 +51,7 @@ nsTextTransformer::nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
|
||||
nsTextTransformer::~nsTextTransformer()
|
||||
{
|
||||
if (mBuffer != mAutoBuffer) {
|
||||
if (mBuffer != mAutoWordBuffer) {
|
||||
delete [] mBuffer;
|
||||
}
|
||||
}
|
||||
@ -63,14 +61,6 @@ nsTextTransformer::Init(nsIFrame* aFrame,
|
||||
nsIContent* aContent,
|
||||
PRInt32 aStartingOffset)
|
||||
{
|
||||
// Make sure we have *some* space in case arguments to the ctor were
|
||||
// bizzare.
|
||||
if (mBufferLength < 100) {
|
||||
if (!GrowBuffer()) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the frames text content
|
||||
nsITextContent* tc;
|
||||
if (NS_OK != aContent->QueryInterface(kITextContentIID, (void**) &tc)) {
|
||||
@ -143,8 +133,9 @@ nsTextTransformer::GrowBuffer(PRBool aForNextWord)
|
||||
if(aForNextWord)
|
||||
nsCRT::memcpy(newBuffer, mBuffer, sizeof(PRUnichar) * mBufferLength);
|
||||
else
|
||||
nsCRT::memcpy(&newBuffer[mBufferLength], mBuffer, sizeof(PRUnichar) * mBufferLength);
|
||||
if (mBuffer != mAutoBuffer) {
|
||||
nsCRT::memcpy(&newBuffer[mBufferLength], mBuffer,
|
||||
sizeof(PRUnichar) * mBufferLength);
|
||||
if (mBuffer != mAutoWordBuffer) {
|
||||
delete [] mBuffer;
|
||||
}
|
||||
}
|
||||
@ -678,10 +669,3 @@ nsTextTransformer::GetPrevWord(PRBool aInWord,
|
||||
#endif
|
||||
return &(mBuffer[mBufferLength-wordLen]);
|
||||
}
|
||||
|
||||
PRUnichar*
|
||||
nsTextTransformer::GetTextAt(PRInt32 aOffset)
|
||||
{
|
||||
// XXX
|
||||
return mBuffer + aOffset;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ class nsTextRun;
|
||||
class nsILineBreaker;
|
||||
class nsIWordBreaker;
|
||||
|
||||
#define NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE 100
|
||||
|
||||
/**
|
||||
* This object manages the transformation of text:
|
||||
*
|
||||
@ -46,11 +48,10 @@ class nsIWordBreaker;
|
||||
*/
|
||||
class nsTextTransformer {
|
||||
public:
|
||||
|
||||
// The text transformer does not hold a reference to the line breaker
|
||||
// and work breaker objects
|
||||
nsTextTransformer(PRUnichar* aBuffer, PRInt32 aBufLen,
|
||||
nsILineBreaker* aLineBreaker, nsIWordBreaker *aWordBreaker);
|
||||
// Note: The text transformer does not hold a reference to the line
|
||||
// breaker and work breaker objects
|
||||
nsTextTransformer(nsILineBreaker* aLineBreaker,
|
||||
nsIWordBreaker *aWordBreaker);
|
||||
|
||||
~nsTextTransformer();
|
||||
|
||||
@ -82,12 +83,17 @@ public:
|
||||
return mHasMultibyte;
|
||||
}
|
||||
|
||||
PRUnichar* GetTextAt(PRInt32 aOffset);
|
||||
PRUnichar* GetWordBuffer() {
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRInt32 GetWordBufferLength() const {
|
||||
return mBufferLength;
|
||||
}
|
||||
|
||||
protected:
|
||||
PRBool GrowBuffer(PRBool aForNextWord=PR_TRUE);
|
||||
PRBool GrowBuffer(PRBool aForNextWord = PR_TRUE);
|
||||
|
||||
PRUnichar* mAutoBuffer;
|
||||
PRUnichar* mBuffer;
|
||||
PRInt32 mBufferLength;
|
||||
PRBool mHasMultibyte;
|
||||
@ -106,6 +112,8 @@ protected:
|
||||
|
||||
nsILineBreaker* mLineBreaker; // does NOT hold reference
|
||||
nsIWordBreaker* mWordBreaker; // does NOT hold reference
|
||||
|
||||
PRUnichar mAutoWordBuffer[NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE];
|
||||
};
|
||||
|
||||
#endif /* nsTextTransformer_h___ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user