bug 233485 : add 'size' parameter to nsAutoBuffer (patch for customers) : r=ccarlen, sr=rbs)
git-svn-id: svn://10.0.0.236/trunk@235864 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -95,10 +95,12 @@
|
||||
#include "nsICollation.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsAutoBuffer.h"
|
||||
|
||||
|
||||
#include "nsIParser.h" // for kCharsetFromBookmarks
|
||||
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include <shlobj.h>
|
||||
#include <intshcut.h>
|
||||
@@ -414,67 +416,6 @@ bm_ReleaseGlobals()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class nsSpillableStackBuffer
|
||||
{
|
||||
protected:
|
||||
|
||||
enum {
|
||||
kStackBufferSize = 256
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
nsSpillableStackBuffer() :
|
||||
mBufferPtr(mBuffer),
|
||||
mCurCapacity(kStackBufferSize)
|
||||
{ }
|
||||
|
||||
~nsSpillableStackBuffer()
|
||||
{
|
||||
DeleteBuffer();
|
||||
}
|
||||
|
||||
PRBool EnsureCapacity(PRInt32 inCharsCapacity)
|
||||
{
|
||||
if (inCharsCapacity < mCurCapacity)
|
||||
return PR_TRUE;
|
||||
|
||||
if (inCharsCapacity > kStackBufferSize)
|
||||
{
|
||||
DeleteBuffer();
|
||||
mBufferPtr = (PRUnichar*)nsMemory::Alloc(inCharsCapacity * sizeof(PRUnichar));
|
||||
mCurCapacity = inCharsCapacity;
|
||||
return (mBufferPtr != NULL);
|
||||
}
|
||||
|
||||
mCurCapacity = kStackBufferSize;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRUnichar* GetBuffer() { return mBufferPtr; }
|
||||
PRInt32 GetCapacity() { return mCurCapacity; }
|
||||
|
||||
protected:
|
||||
|
||||
void DeleteBuffer()
|
||||
{
|
||||
if (mBufferPtr != mBuffer)
|
||||
{
|
||||
nsMemory::Free(mBufferPtr);
|
||||
mBufferPtr = mBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
PRUnichar *mBufferPtr;
|
||||
PRUnichar mBuffer[kStackBufferSize];
|
||||
PRInt32 mCurCapacity;
|
||||
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@@ -785,17 +726,17 @@ BookmarkParser::DecodeBuffer(nsString &line, char *buf, PRUint32 aLength)
|
||||
PRInt32 unicharBufLen = 0;
|
||||
mUnicodeDecoder->GetMaxLength(aBuffer, aLength, &unicharBufLen);
|
||||
|
||||
nsSpillableStackBuffer stackBuffer;
|
||||
if (!stackBuffer.EnsureCapacity(unicharBufLen + 1))
|
||||
nsAutoBuffer<PRUnichar, 256> stackBuffer;
|
||||
if (!stackBuffer.EnsureElemCapacity(unicharBufLen + 1))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
do
|
||||
{
|
||||
PRInt32 srcLength = aLength;
|
||||
PRInt32 unicharLength = unicharBufLen;
|
||||
PRUnichar *unichars = stackBuffer.GetBuffer();
|
||||
PRUnichar *unichars = stackBuffer.get();
|
||||
|
||||
rv = mUnicodeDecoder->Convert(aBuffer, &srcLength, stackBuffer.GetBuffer(), &unicharLength);
|
||||
rv = mUnicodeDecoder->Convert(aBuffer, &srcLength, stackBuffer.get(), &unicharLength);
|
||||
unichars[unicharLength]=0; //add this since the unicode converters can't be trusted to do so.
|
||||
|
||||
// Move the nsParser.cpp 00 -> space hack to here so it won't break UCS2 file
|
||||
|
||||
Reference in New Issue
Block a user