From a3be0d07e2ca824fcbd72d2fe3c24541f98ca2fa Mon Sep 17 00:00:00 2001 From: "jshin%mailaps.org" Date: Wed, 12 Sep 2007 17:51:09 +0000 Subject: [PATCH] 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 --- .../suite/browser/src/nsBookmarksService.cpp | 71 ++----------------- 1 file changed, 6 insertions(+), 65 deletions(-) diff --git a/mozilla/suite/browser/src/nsBookmarksService.cpp b/mozilla/suite/browser/src/nsBookmarksService.cpp index 3e40039416b..ec63fef7343 100644 --- a/mozilla/suite/browser/src/nsBookmarksService.cpp +++ b/mozilla/suite/browser/src/nsBookmarksService.cpp @@ -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 #include @@ -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 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