Bug 394691. nsTArray should not do default initialization of POD elements. Also, switch nsAutoBuffer users to nsAutoTArray. patch by Chris Pearce, r=bsmedberg, sr=roc, a=bzbarsky

This commit is contained in:
roc+%cs.cmu.edu 2007-09-18 23:12:10 +00:00
Родитель d60ceed109
Коммит df1d8efba7
16 изменённых файлов: 153 добавлений и 150 удалений

Просмотреть файл

@ -64,7 +64,7 @@
#include "nsSafariProfileMigrator.h"
#include "nsToolkitCompsCID.h"
#include "nsNetUtil.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include <Carbon/Carbon.h>
@ -311,12 +311,12 @@ GetDictionaryStringValue(CFDictionaryRef aDictionary, CFStringRef aKey,
{
CFStringRef value = (CFStringRef)::CFDictionaryGetValue(aDictionary, aKey);
if (value) {
nsAutoBuffer<UniChar, 1024> buffer;
nsAutoTArray<UniChar, 1024> buffer;
CFIndex valueLength = ::CFStringGetLength(value);
buffer.EnsureElemCapacity(valueLength);
buffer.SetLength(valueLength);
::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.get());
aResult.Assign(buffer.get(), valueLength);
::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.Elements());
aResult.Assign(buffer.Elements(), valueLength);
return PR_TRUE;
}
return PR_FALSE;
@ -328,12 +328,12 @@ GetDictionaryCStringValue(CFDictionaryRef aDictionary, CFStringRef aKey,
{
CFStringRef value = (CFStringRef)::CFDictionaryGetValue(aDictionary, aKey);
if (value) {
nsAutoBuffer<char, 1024> buffer;
nsAutoTArray<char, 1024> buffer;
CFIndex valueLength = ::CFStringGetLength(value);
buffer.EnsureElemCapacity(valueLength + 1);
buffer.SetLength(valueLength + 1);
if (::CFStringGetCString(value, buffer.get(), valueLength + 1, aEncoding)) {
aResult = buffer.get();
if (::CFStringGetCString(value, buffer.Elements(), valueLength + 1, aEncoding)) {
aResult = buffer.Elements();
return PR_TRUE;
}
}
@ -345,12 +345,12 @@ GetArrayStringValue(CFArrayRef aArray, PRInt32 aIndex, nsAString& aResult)
{
CFStringRef value = (CFStringRef)::CFArrayGetValueAtIndex(aArray, aIndex);
if (value) {
nsAutoBuffer<UniChar, 1024> buffer;
nsAutoTArray<UniChar, 1024> buffer;
CFIndex valueLength = ::CFStringGetLength(value);
buffer.EnsureElemCapacity(valueLength);
buffer.SetLength(valueLength);
::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.get());
aResult.Assign(buffer.get(), valueLength);
::CFStringGetCharacters(value, CFRangeMake(0, valueLength), buffer.Elements());
aResult.Assign(buffer.Elements(), valueLength);
return PR_TRUE;
}
return PR_FALSE;

Просмотреть файл

@ -52,7 +52,7 @@
#include "nsIPrintSettingsX.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsPDECommon.h"
@ -98,11 +98,11 @@ static CFDictionaryRef ExtractCustomSettingsDict(PMPrintSettings nativePrintSett
OSStatus status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kAppPrintDialogAppOnlyKey, &bytesNeeded, NULL);
if (status == noErr) {
nsAutoBuffer<UInt8, 512> dataBuffer;
if (dataBuffer.EnsureElemCapacity(bytesNeeded)) {
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kAppPrintDialogAppOnlyKey, &bytesNeeded, dataBuffer.get());
nsAutoTArray<UInt8, 512> dataBuffer;
if (dataBuffer.SetLength(bytesNeeded)) {
status = ::PMGetPrintSettingsExtendedData(nativePrintSettings, kAppPrintDialogAppOnlyKey, &bytesNeeded, dataBuffer.Elements());
if (status == noErr) {
CFDataRef xmlData = ::CFDataCreate(kCFAllocatorDefault, dataBuffer.get(), bytesNeeded);
CFDataRef xmlData = ::CFDataCreate(kCFAllocatorDefault, dataBuffer.Elements(), bytesNeeded);
if (xmlData) {
resultDict = (CFDictionaryRef)::CFPropertyListCreateFromXMLData(
kCFAllocatorDefault,
@ -128,10 +128,10 @@ GetDictionaryStringValue(CFDictionaryRef aDictionary, CFStringRef aKey, nsAStrin
{
CFIndex stringLen = CFStringGetLength((CFStringRef)dictValue);
nsAutoBuffer<UniChar, 256> stringBuffer;
if (stringBuffer.EnsureElemCapacity(stringLen + 1)) {
::CFStringGetCharacters((CFStringRef)dictValue, CFRangeMake(0, stringLen), stringBuffer.get());
aResult.Assign(stringBuffer.get(), stringLen);
nsAutoTArray<UniChar, 256> stringBuffer;
if (stringBuffer.SetLength(stringLen + 1)) {
::CFStringGetCharacters((CFStringRef)dictValue, CFRangeMake(0, stringLen), stringBuffer.Elements());
aResult.Assign(stringBuffer.Elements(), stringLen);
return PR_TRUE;
}
}

Просмотреть файл

@ -52,7 +52,7 @@
#include "nsIDOMWindowInternal.h"
#include "nsIAttribute.h"
#include "nsIStringBundle.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsIEventStateManager.h"
#include "prmem.h"
#include "nsISchema.h"
@ -442,7 +442,7 @@ nsXFormsUploadElement::HandleChildElements(nsILocalFile *aFile,
return rv;
}
typedef nsAutoBuffer<char, 256> nsAutoCharBuffer;
typedef nsAutoTArray<char, 256> nsAutoCharBuffer;
static void
ReportEncodingMemoryError(nsIDOMElement* aElement, nsIFile *aFile,
@ -478,13 +478,13 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, PRUint16 aType,
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCharBuffer fileData;
if (!fileData.EnsureElemCapacity(size + 1)) {
if (!fileData.SetLength(size + 1)) {
ReportEncodingMemoryError(mElement, aFile, size + 1);
return NS_ERROR_OUT_OF_MEMORY;
}
PRUint32 bytesRead;
rv = fileStream->Read(fileData.get(), size, &bytesRead);
rv = fileStream->Read(fileData.Elements(), size, &bytesRead);
NS_ASSERTION(NS_SUCCEEDED(rv) && bytesRead == size,
"fileStream->Read failed");
@ -492,7 +492,7 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, PRUint16 aType,
if (aType == nsISchemaBuiltinType::BUILTIN_TYPE_BASE64BINARY) {
// encode file contents
*aResult = nsnull;
char *buffer = PL_Base64Encode(fileData.get(), bytesRead, nsnull);
char *buffer = PL_Base64Encode(fileData.Elements(), bytesRead, nsnull);
if (buffer) {
*aResult = ToNewUnicode(nsDependentCString(buffer));
PR_Free(buffer);
@ -513,7 +513,7 @@ nsXFormsUploadElement::EncodeFileContents(nsIFile *aFile, PRUint16 aType,
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
// encode file contents
BinaryToHex(fileData.get(), bytesRead, &fileDataHex);
BinaryToHex(fileData.Elements(), bytesRead, &fileDataHex);
fileDataHex[bytesRead * 2] = 0;
*aResult = fileDataHex;
}

Просмотреть файл

@ -58,7 +58,7 @@
#include "prprf.h"
#include "nsReadableUtils.h"
#include "nsUnicodeRange.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#define DEFAULT_TTF_SYMBOL_ENCODING "windows-1252"
#define IS_RTL_PRESENTATION_FORM(c) ((0xfb1d <= (c)) && ((c)<= 0xfefc))
@ -283,8 +283,8 @@ static nsFontCleanupObserver *gFontCleanupObserver;
#undef CHAR_BUFFER_SIZE
#define CHAR_BUFFER_SIZE 1024
typedef nsAutoBuffer<char, CHAR_BUFFER_SIZE> nsAutoCharBuffer;
typedef nsAutoBuffer<PRUnichar, CHAR_BUFFER_SIZE> nsAutoChar16Buffer;
typedef nsAutoTArray<char, CHAR_BUFFER_SIZE> nsAutoCharBuffer;
typedef nsAutoTArray<PRUnichar, CHAR_BUFFER_SIZE> nsAutoChar16Buffer;
class nsFontSubset : public nsFontWin
{
@ -701,10 +701,10 @@ GetNAME(HDC aDC, nsString* aName, PRBool* aIsSymbolEncoding = nsnull)
return eGetName_OtherError;
}
nsAutoFontDataBuffer buffer;
if (!buffer.EnsureElemCapacity(len)) {
if (!buffer.SetLength(len)) {
return eGetName_OtherError;
}
PRUint8* buf = buffer.get();
PRUint8* buf = buffer.Elements();
DWORD newLen = GetFontData(aDC, NAME, 0, buf, len);
if (newLen != len) {
@ -805,10 +805,10 @@ GetSpaces(HDC aDC, PRBool* aIsCFFOutline, PRUint32* aMaxGlyph,
if ((len == GDI_ERROR) || (!len)) {
return NS_ERROR_FAILURE;
}
if (!aIsSpace.EnsureElemCapacity(len)) {
if (!aIsSpace.SetLength(len)) {
return NS_ERROR_OUT_OF_MEMORY;
}
PRUint8* buf = aIsSpace.get();
PRUint8* buf = aIsSpace.Elements();
DWORD newLen = GetFontData(aDC, LOCA, 0, buf, len);
if (newLen != len) {
return NS_ERROR_FAILURE;
@ -1429,8 +1429,8 @@ ConvertUnicodeToGlyph(const PRUnichar* aSrc, PRInt32 aSrcLength,
return NS_ERROR_UNEXPECTED;
}
if (!aResult.EnsureElemCapacity(aDestLength)) return NS_ERROR_OUT_OF_MEMORY;
char* str = aResult.get();
if (!aResult.SetLength(aDestLength)) return NS_ERROR_OUT_OF_MEMORY;
char* str = aResult.Elements();
aConverter->Convert(aSrc, &aSrcLength, str, &aDestLength);
@ -1680,10 +1680,10 @@ nsFontMetricsWin::GetFontCCMAP(HDC aDC, const char* aShortName,
return nsnull;
}
nsAutoFontDataBuffer buffer;
if (!buffer.EnsureElemCapacity(len)) {
if (!buffer.SetLength(len)) {
return nsnull;
}
PRUint8* buf = buffer.get();
PRUint8* buf = buffer.Elements();
DWORD newLen = GetFontData(aDC, CMAP, 0, buf, len);
if (newLen != len) {
return nsnull;
@ -1938,10 +1938,10 @@ GetGlyphIndices(HDC aDC,
if ((len == GDI_ERROR) || (!len)) {
return NS_ERROR_UNEXPECTED;
}
if (!buffer.EnsureElemCapacity(len)) {
if (!buffer.SetLength(len)) {
return NS_ERROR_OUT_OF_MEMORY;
}
buf = buffer.get();
buf = buffer.Elements();
DWORD newLen = GetFontData(aDC, CMAP, 0, buf, len);
if (newLen != len) {
return NS_ERROR_UNEXPECTED;
@ -2034,10 +2034,10 @@ GetGlyphIndices(HDC aDC,
PRUint16* idDelta = startCode + segCount;
PRUint16* idRangeOffset = idDelta + segCount;
if (!aResult.EnsureElemCapacity(aLength)) {
if (!aResult.SetLength(aLength)) {
return NS_ERROR_OUT_OF_MEMORY;
}
PRUnichar* result = aResult.get();
PRUnichar* result = aResult.Elements();
for (i = 0; i < aLength; ++i) {
result[i] = GetGlyphIndex(segCount, endCode, startCode,
idRangeOffset, idDelta, end,
@ -2146,7 +2146,7 @@ nsGlyphAgent::GetGlyphMetrics(HDC aDC,
if (0 == aGlyphIndex) { // caller doesn't know the glyph index, so find it
nsAutoChar16Buffer buf;
if (NS_SUCCEEDED(GetGlyphIndices(aDC, nsnull, &aChar, 1, buf)))
aGlyphIndex = *(buf.get());
aGlyphIndex = *(buf.Elements());
}
if (0 < aGlyphIndex) {
return GetGlyphOutlineA(aDC, aGlyphIndex, GGO_METRICS | GGO_GLYPH_INDEX, aGlyphMetrics, 0, nsnull, &mMat);
@ -4394,7 +4394,7 @@ nsFontWinUnicode::GetBoundingMetrics(HDC aDC,
}
}
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, aString, aLength, aBoundingMetrics, buffer.get());
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, aString, aLength, aBoundingMetrics, buffer.Elements());
}
#ifdef NS_DEBUG
@ -4433,9 +4433,9 @@ nsFontWinNonUnicode::GetWidth(HDC aDC, const PRUnichar* aString,
SIZE size;
if (!mIsWide)
::GetTextExtentPoint32A(aDC, buffer.get(), destLength, &size);
::GetTextExtentPoint32A(aDC, buffer.Elements(), destLength, &size);
else
::GetTextExtentPoint32W(aDC, (const PRUnichar*) buffer.get(), destLength / 2, &size);
::GetTextExtentPoint32W(aDC, (const PRUnichar*) buffer.Elements(), destLength / 2, &size);
size.cx -= mOverhangCorrection;
return size.cx;
@ -4455,9 +4455,9 @@ nsFontWinNonUnicode::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
}
if (!mIsWide)
NS_ExtTextOutA(aDC, this, aX, aY, 0, NULL, buffer.get(), aLength, NULL);
NS_ExtTextOutA(aDC, this, aX, aY, 0, NULL, buffer.Elements(), aLength, NULL);
else
NS_ExtTextOutW(aDC, this, aX, aY, 0, NULL, (const PRUnichar*) buffer.get(), destLength / 2, NULL);
NS_ExtTextOutW(aDC, this, aX, aY, 0, NULL, (const PRUnichar*) buffer.Elements(), destLength / 2, NULL);
}
#ifdef MOZ_MATHML
@ -4486,7 +4486,7 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
if (gGlyphAgent.GetState() != eGlyphAgent_UNICODE) {
// we are on a platform that doesn't implement GetGlyphOutlineW()
// we need to use glyph indices
rv = GetGlyphIndices(aDC, &mCMAP, (const PRUnichar*)buffer.get(), destLength / 2, buf);
rv = GetGlyphIndices(aDC, &mCMAP, (const PRUnichar*)buffer.Elements(), destLength / 2, buf);
if (NS_FAILED(rv)) {
return rv;
}
@ -4494,12 +4494,12 @@ nsFontWinNonUnicode::GetBoundingMetrics(HDC aDC,
// buffer.mBuffer is now a pseudo-Unicode string so that we can use
// GetBoundingMetricsCommon() also used by nsFontWinUnicode.
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, (const PRUnichar*)buffer.get(),
destLength / 2, aBoundingMetrics, buf.get());
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, (const PRUnichar*)buffer.Elements(),
destLength / 2, aBoundingMetrics, buf.Elements());
}
return GetBoundingMetricsCommonA(aDC, mOverhangCorrection, buffer.get(), destLength,
return GetBoundingMetricsCommonA(aDC, mOverhangCorrection, buffer.Elements(), destLength,
aBoundingMetrics);
}
@ -4544,11 +4544,11 @@ SubstituteChars(PRBool aDisplayUnicode,
#ifdef WINCE
// Unicode backend on WINCE... Substitute nothing.
if (!aResult.EnsureElemCapacity(aLength))
if (!aResult.SetLength(aLength))
return NS_ERROR_OUT_OF_MEMORY;
*aCount = aLength;
memcpy(aResult.get(), aString, aLength * sizeof(PRUnichar));
memcpy(aResult.Elements(), aString, aLength * sizeof(PRUnichar));
return NS_OK;
#else
@ -4582,10 +4582,10 @@ SubstituteChars(PRBool aDisplayUnicode,
if (NS_SUCCEEDED(res)) {
*aCount = conv.Length();
if (*aCount > 0) {
if (!aResult.EnsureElemCapacity(*aCount)) {
if (!aResult.SetLength(*aCount)) {
return NS_ERROR_OUT_OF_MEMORY;
}
result = aResult.get();
result = aResult.Elements();
PRUnichar* u = result;
const char* c = conv.get();
for (; *c; ++c, ++u) {
@ -4597,8 +4597,8 @@ SubstituteChars(PRBool aDisplayUnicode,
}
// we reach here if we couldn't transliterate, so fallback to question marks
if (!aResult.EnsureElemCapacity(aLength)) return NS_ERROR_OUT_OF_MEMORY;
result = aResult.get();
if (!aResult.SetLength(aLength)) return NS_ERROR_OUT_OF_MEMORY;
result = aResult.Elements();
for (PRUint32 i = 0; i < aLength; i++) {
result[i] = NS_REPLACEMENT_CHAR;
}
@ -4618,7 +4618,7 @@ nsFontWinSubstitute::GetWidth(HDC aDC, const PRUnichar* aString,
if (NS_FAILED(rv) || !aLength) return 0;
SIZE size;
::GetTextExtentPoint32W(aDC, buffer.get(), aLength, &size);
::GetTextExtentPoint32W(aDC, buffer.Elements(), aLength, &size);
size.cx -= mOverhangCorrection;
return size.cx;
@ -4634,7 +4634,7 @@ nsFontWinSubstitute::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
nsresult rv = SubstituteChars(PR_FALSE, aString, aLength, buffer, &aLength);
if (NS_FAILED(rv) || !aLength) return;
NS_ExtTextOutW(aDC, this, aX, aY, 0, NULL, buffer.get(), aLength, NULL);
NS_ExtTextOutW(aDC, this, aX, aY, 0, NULL, buffer.Elements(), aLength, NULL);
}
#ifdef MOZ_MATHML
@ -4661,14 +4661,14 @@ nsFontWinSubstitute::GetBoundingMetrics(HDC aDC,
if (gGlyphAgent.GetState() != eGlyphAgent_UNICODE) {
// we are on a platform that doesn't implement GetGlyphOutlineW()
// we better get all glyph indices in one swoop
rv = GetGlyphIndices(aDC, &mCMAP, buffer.get(), aLength, buf);
rv = GetGlyphIndices(aDC, &mCMAP, buffer.Elements(), aLength, buf);
if (NS_FAILED(rv)) {
return rv;
}
}
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, buffer.get(), aLength,
aBoundingMetrics, buf.get());
return GetBoundingMetricsCommon(aDC, mOverhangCorrection, buffer.Elements(), aLength,
aBoundingMetrics, buf.Elements());
}
#ifdef NS_DEBUG
@ -4800,8 +4800,8 @@ nsFontSubset::Convert(const PRUnichar* aString, PRUint32 aLength,
int nb = WideCharToMultiByte(mCodePage, 0, aString, aLength,
nsnull, 0, nsnull, nsnull);
if (!nb || !aResult.EnsureElemCapacity(nb)) return;
char* buf = aResult.get();
if (!nb || !aResult.SetLength(nb)) return;
char* buf = aResult.Elements();
// Convert the Unicode string to ANSI
*aResultLength = WideCharToMultiByte(mCodePage, 0, aString, aLength,
buf, nb, nsnull, nsnull);
@ -4814,7 +4814,7 @@ nsFontSubset::GetWidth(HDC aDC, const PRUnichar* aString, PRUint32 aLength)
Convert(aString, aLength, buffer, &aLength);
if (aLength) {
SIZE size;
::GetTextExtentPoint32A(aDC, buffer.get(), aLength, &size);
::GetTextExtentPoint32A(aDC, buffer.Elements(), aLength, &size);
size.cx -= mOverhangCorrection;
return size.cx;
}
@ -4828,7 +4828,7 @@ nsFontSubset::DrawString(HDC aDC, PRInt32 aX, PRInt32 aY,
nsAutoCharBuffer buffer;
Convert(aString, aLength, buffer, &aLength);
if (aLength) {
NS_ExtTextOutA(aDC, this, aX, aY, 0, NULL, buffer.get(), aLength, NULL);
NS_ExtTextOutA(aDC, this, aX, aY, 0, NULL, buffer.Elements(), aLength, NULL);
}
}
@ -4843,7 +4843,7 @@ nsFontSubset::GetBoundingMetrics(HDC aDC,
nsAutoCharBuffer buffer;
Convert(aString, aLength, buffer, &aLength);
if (aLength) {
return GetBoundingMetricsCommonA(aDC, mOverhangCorrection, buffer.get(), aLength,
return GetBoundingMetricsCommonA(aDC, mOverhangCorrection, buffer.Elements(), aLength,
aBoundingMetrics);
}
return NS_OK;
@ -4926,11 +4926,11 @@ nsFontSubsetSubstitute::Convert(const PRUnichar* aString, PRUint32 aLength,
}
if (!aLength) {
// this is the case where the substitute string collapsed to nothingness
*(aResult.get()) = '\0';
*(aResult.Elements()) = '\0';
*aResultLength = 0;
return;
}
nsFontSubset::Convert(buffer.get(), aLength, aResult, aResultLength);
nsFontSubset::Convert(buffer.Elements(), aLength, aResult, aResultLength);
}
nsFontWinA::nsFontWinA(LOGFONT* aLogFont, HFONT aFont, PRUint16* aCCMap)

Просмотреть файл

@ -49,7 +49,6 @@
#include "cairo-ft.h" // includes fontconfig.h, too
#include <freetype/tttables.h>
#include "nsAutoBuffer.h"
#include "nsICharsetConverterManager.h"
class gfxOS2Font : public gfxFont {

Просмотреть файл

@ -58,7 +58,7 @@
#include <windows.h>
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsUnicodeRange.h"
#include "nsUnicharUtils.h"
@ -651,15 +651,15 @@ SetupTextRunFromGlyphs(gfxTextRun *aRun, WCHAR *aGlyphs, HDC aDC,
return PR_FALSE;
SIZE size;
nsAutoBuffer<int,500> partialWidthArray;
if (!partialWidthArray.EnsureElemCapacity(length))
nsAutoTArray<int,500> partialWidthArray;
if (!partialWidthArray.SetLength(length))
return PR_FALSE;
BOOL success = GetTextExtentExPointI(aDC,
(WORD*) aGlyphs,
length,
INT_MAX,
NULL,
partialWidthArray.get(),
partialWidthArray.Elements(),
&size);
if (!success)
return PR_FALSE;
@ -701,14 +701,14 @@ gfxWindowsFontGroup::InitTextRunGDI(gfxContext *aContext, gfxTextRun *aRun,
nsRefPtr<gfxWindowsFont> font = GetFontAt(0);
DCFromContext dc(aContext);
if (SetupDCFont(dc, font)) {
nsAutoBuffer<WCHAR,500> glyphArray;
if (!glyphArray.EnsureElemCapacity(aLength))
nsAutoTArray<WCHAR,500> glyphArray;
if (!glyphArray.SetLength(aLength))
return;
DWORD ret = GetGlyphIndicesA(dc, aString, aLength, (WORD*) glyphArray.get(),
DWORD ret = GetGlyphIndicesA(dc, aString, aLength, (WORD*) glyphArray.Elements(),
GGI_MARK_NONEXISTING_GLYPHS);
if (ret != GDI_ERROR &&
SetupTextRunFromGlyphs(aRun, glyphArray.get(), dc, font))
SetupTextRunFromGlyphs(aRun, glyphArray.Elements(), dc, font))
return;
}
@ -725,14 +725,14 @@ gfxWindowsFontGroup::InitTextRunGDI(gfxContext *aContext, gfxTextRun *aRun,
nsRefPtr<gfxWindowsFont> font = GetFontAt(0);
DCFromContext dc(aContext);
if (SetupDCFont(dc, font)) {
nsAutoBuffer<WCHAR,500> glyphArray;
if (!glyphArray.EnsureElemCapacity(aLength))
nsAutoTArray<WCHAR,500> glyphArray;
if (!glyphArray.SetLength(aLength))
return;
DWORD ret = GetGlyphIndicesW(dc, aString, aLength, (WORD*) glyphArray.get(),
DWORD ret = GetGlyphIndicesW(dc, aString, aLength, (WORD*) glyphArray.Elements(),
GGI_MARK_NONEXISTING_GLYPHS);
if (ret != GDI_ERROR &&
SetupTextRunFromGlyphs(aRun, glyphArray.get(), dc, font))
SetupTextRunFromGlyphs(aRun, glyphArray.Elements(), dc, font))
return;
}
@ -886,9 +886,9 @@ public:
mNumGlyphs(0), mMaxGlyphs((int)(1.5 * aLength) + 16),
mFontSelected(PR_FALSE)
{
mGlyphs.EnsureElemCapacity(mMaxGlyphs);
mClusters.EnsureElemCapacity(mItemLength + 1);
mAttr.EnsureElemCapacity(mMaxGlyphs);
mGlyphs.SetLength(mMaxGlyphs);
mClusters.SetLength(mItemLength + 1);
mAttr.SetLength(mMaxGlyphs);
}
~UniscribeItem() {
@ -926,12 +926,12 @@ public:
rv = ScriptShape(shapeDC, mCurrentFont->ScriptCache(),
str, mRangeLength,
mMaxGlyphs, &sa,
mGlyphs.get(), mClusters.get(),
mAttr.get(), &mNumGlyphs);
mGlyphs.Elements(), mClusters.Elements(),
mAttr.Elements(), &mNumGlyphs);
if (rv == E_OUTOFMEMORY) {
mGlyphs.AddElemCapacity(mMaxGlyphs);
mAttr.AddElemCapacity(mMaxGlyphs);
mGlyphs.SetLength(mMaxGlyphs);
mAttr.SetLength(mMaxGlyphs);
mMaxGlyphs *= 2;
continue;
}
@ -949,7 +949,7 @@ public:
}
#ifdef DEBUG_pavlov
if (rv == USP_E_SCRIPT_NOT_IN_FONT) {
ScriptGetCMap(mDC, mCurrentFont->ScriptCache(), str, mRangeString, 0, mGlyphs.get());
ScriptGetCMap(mDC, mCurrentFont->ScriptCache(), str, mRangeString, 0, mGlyphs.Elements());
PRUnichar foo[LF_FACESIZE+1];
GetTextFaceW(mDC, LF_FACESIZE, foo);
printf("bah\n");
@ -989,16 +989,16 @@ public:
HRESULT Place() {
HRESULT rv;
mOffsets.EnsureElemCapacity(mNumGlyphs);
mAdvances.EnsureElemCapacity(mNumGlyphs);
mOffsets.SetLength(mNumGlyphs);
mAdvances.SetLength(mNumGlyphs);
HDC placeDC = nsnull;
while (PR_TRUE) {
rv = ScriptPlace(placeDC, mCurrentFont->ScriptCache(),
mGlyphs.get(), mNumGlyphs,
mAttr.get(), &mScriptItem->a,
mAdvances.get(), mOffsets.get(), NULL);
mGlyphs.Elements(), mNumGlyphs,
mAttr.Elements(), &mScriptItem->a,
mAdvances.Elements(), mOffsets.Elements(), NULL);
if (rv == E_PENDING) {
SelectFont();
@ -1457,12 +1457,12 @@ private:
#define AVERAGE_ITEM_LENGTH 40
nsAutoBuffer<WORD, PRUint32(1.5 * AVERAGE_ITEM_LENGTH) + 16> mGlyphs;
nsAutoBuffer<WORD, AVERAGE_ITEM_LENGTH + 1> mClusters;
nsAutoBuffer<SCRIPT_VISATTR, PRUint32(1.5 * AVERAGE_ITEM_LENGTH) + 16> mAttr;
nsAutoTArray<WORD, PRUint32(1.5 * AVERAGE_ITEM_LENGTH) + 16> mGlyphs;
nsAutoTArray<WORD, AVERAGE_ITEM_LENGTH + 1> mClusters;
nsAutoTArray<SCRIPT_VISATTR, PRUint32(1.5 * AVERAGE_ITEM_LENGTH) + 16> mAttr;
nsAutoBuffer<GOFFSET, 2 * AVERAGE_ITEM_LENGTH> mOffsets;
nsAutoBuffer<int, 2 * AVERAGE_ITEM_LENGTH> mAdvances;
nsAutoTArray<GOFFSET, 2 * AVERAGE_ITEM_LENGTH> mOffsets;
nsAutoTArray<int, 2 * AVERAGE_ITEM_LENGTH> mAdvances;
#undef AVERAGE_ITEM_LENGTH

Просмотреть файл

@ -44,7 +44,7 @@
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "prprf.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include <ctype.h>
@ -265,16 +265,16 @@ nsLocaleService::nsLocaleService(void)
CFStringRef userLocaleStr = ::CFLocaleGetIdentifier(userLocaleRef);
::CFRetain(userLocaleStr);
nsAutoBuffer<UniChar, 32> buffer;
nsAutoTArray<UniChar, 32> buffer;
int size = ::CFStringGetLength(userLocaleStr);
if (buffer.EnsureElemCapacity(size))
if (buffer.SetLength(size))
{
CFRange range = ::CFRangeMake(0, size);
::CFStringGetCharacters(userLocaleStr, range, buffer.get());
buffer.get()[size] = 0;
::CFStringGetCharacters(userLocaleStr, range, buffer.Elements());
buffer[size] = 0;
// Convert the locale string to the format that Mozilla expects
nsAutoString xpLocale(buffer.get());
nsAutoString xpLocale(buffer.Elements());
xpLocale.ReplaceChar('_', '-');
nsresult rv = NewLocale(xpLocale, getter_AddRefs(mSystemLocale));

Просмотреть файл

@ -57,7 +57,7 @@
#include "nsILocalFileMac.h"
#include "nsIFileURL.h"
#include "nsInt64.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include <Cocoa/Cocoa.h>
@ -313,11 +313,11 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBloc
// create our buffer
PRInt32 bufferCapacity = 2 + desiredImageSize * desiredImageSize * 4;
nsAutoBuffer<PRUint8, 3 + 16 * 16 * 5> iconBuffer; // initial size is for 16x16
if (!iconBuffer.EnsureElemCapacity(bufferCapacity))
nsAutoTArray<PRUint8, 3 + 16 * 16 * 5> iconBuffer; // initial size is for 16x16
if (!iconBuffer.SetLength(bufferCapacity))
return NS_ERROR_OUT_OF_MEMORY;
PRUint8* iconBufferPtr = iconBuffer.get();
PRUint8* iconBufferPtr = iconBuffer.Elements();
// write header data into buffer
*iconBufferPtr++ = desiredImageSize;
@ -348,7 +348,7 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBloc
#endif
}
NS_ASSERTION(iconBufferPtr == iconBuffer.get() + bufferCapacity,
NS_ASSERTION(iconBufferPtr == iconBuffer.Elements() + bufferCapacity,
"buffer size miscalculation");
// Now, create a pipe and stuff our data into it
@ -358,7 +358,7 @@ nsresult nsIconChannel::MakeInputStream(nsIInputStream** _retval, PRBool nonBloc
if (NS_SUCCEEDED(rv)) {
PRUint32 written;
rv = outStream->Write((char*)iconBuffer.get(), bufferCapacity, &written);
rv = outStream->Write((char*)iconBuffer.Elements(), bufferCapacity, &written);
if (NS_SUCCEEDED(rv))
NS_IF_ADDREF(*_retval = inStream);
}

Просмотреть файл

@ -95,7 +95,7 @@
#include "nsICollation.h"
#include "nsVoidArray.h"
#include "nsUnicharUtils.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsINetUtil.h"
#if defined(XP_WIN) || defined(XP_OS2)
@ -742,17 +742,17 @@ BookmarkParser::DecodeBuffer(nsString &line, char *buf, PRUint32 aLength)
PRInt32 unicharBufLen = 0;
mUnicodeDecoder->GetMaxLength(aBuffer, aLength, &unicharBufLen);
nsAutoBuffer<PRUnichar, 256> stackBuffer;
if (!stackBuffer.EnsureElemCapacity(unicharBufLen + 1))
nsAutoTArray<PRUnichar, 256> stackBuffer;
if (!stackBuffer.SetLength(unicharBufLen + 1))
return NS_ERROR_OUT_OF_MEMORY;
do
{
PRInt32 srcLength = aLength;
PRInt32 unicharLength = unicharBufLen;
PRUnichar *unichars = stackBuffer.get();
PRUnichar *unichars = stackBuffer.Elements();
rv = mUnicodeDecoder->Convert(aBuffer, &srcLength, stackBuffer.get(), &unicharLength);
rv = mUnicodeDecoder->Convert(aBuffer, &srcLength, stackBuffer.Elements(), &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

Просмотреть файл

@ -40,7 +40,7 @@
#include "nsOSHelperAppService.h"
#include "nsISupports.h"
#include "nsString.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsXPIDLString.h"
#include "nsIURL.h"
#include "nsILocalFile.h"
@ -125,12 +125,12 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
(CFStringRef)::CFBundleGetValueForInfoDictionaryKey(handlerBundle,
kCFBundleNameKey);
if (bundleName) {
nsAutoBuffer<UniChar, 255> buffer;
nsAutoTArray<UniChar, 255> buffer;
CFIndex bundleNameLength = ::CFStringGetLength(bundleName);
buffer.EnsureElemCapacity(bundleNameLength);
buffer.SetLength(bundleNameLength);
::CFStringGetCharacters(bundleName, CFRangeMake(0, bundleNameLength),
buffer.get());
_retval.Assign(buffer.get(), bundleNameLength);
buffer.Elements());
_retval.Assign(buffer.Elements(), bundleNameLength);
rv = NS_OK;
}

Просмотреть файл

@ -147,12 +147,12 @@ WideCharToMultiByte(int aCodePage, const PRUnichar* aSrc,
if (NS_FAILED(uco->GetMaxLength(aSrc, aSrcLength, &aResultLength))) {
return NS_ERROR_UNEXPECTED;
}
if (!aResult.EnsureElemCapacity(aResultLength + 1))
if (!aResult.SetLength(aResultLength + 1))
return NS_ERROR_OUT_OF_MEMORY;
char* str = aResult.get();
char* str = aResult.Elements();
rv = uco->Convert(aSrc, &aSrcLength, str, &aResultLength);
aResult.get()[aResultLength] = '\0';
aResult[aResultLength] = '\0';
return rv;
}
@ -171,11 +171,11 @@ MultiByteToWideChar(int aCodePage, const char* aSrc,
if (NS_FAILED(uco->GetMaxLength(aSrc, aSrcLength, &aResultLength))) {
return NS_ERROR_UNEXPECTED;
}
if (!aResult.EnsureElemCapacity(aResultLength + 1))
if (!aResult.SetLength(aResultLength + 1))
return NS_ERROR_OUT_OF_MEMORY;
PRUnichar* str = aResult.get();
PRUnichar* str = aResult.Elements();
rv = uco->Convert(aSrc, &aSrcLength, str, &aResultLength);
aResult.get()[aResultLength] = '\0';
aResult[aResultLength] = '\0';
return rv;
}

Просмотреть файл

@ -40,7 +40,7 @@
#define INCL_WIN
#include <os2.h>
#include <uconv.h>
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsICharsetConverterManager.h"
#include "gfxCore.h"
@ -58,8 +58,8 @@ private:
};
#define CHAR_BUFFER_SIZE 1024
typedef nsAutoBuffer<char, CHAR_BUFFER_SIZE> nsAutoCharBuffer;
typedef nsAutoBuffer<PRUnichar, CHAR_BUFFER_SIZE> nsAutoChar16Buffer;
typedef nsAutoTArray<char, CHAR_BUFFER_SIZE> nsAutoCharBuffer;
typedef nsAutoTArray<PRUnichar, CHAR_BUFFER_SIZE> nsAutoChar16Buffer;
nsresult WideCharToMultiByte(int aCodePage, const PRUnichar* aSrc,
PRInt32 aSrcLength, nsAutoCharBuffer& aResult,

Просмотреть файл

@ -107,7 +107,6 @@ EXPORTS = \
nsTextFormatter.h \
nsValueArray.h \
nsStringEnumerator.h \
nsAutoBuffer.h \
nsHashPropertyBag.h \
nsWhitespaceTokenizer.h \
$(NULL)

Просмотреть файл

@ -180,7 +180,12 @@ class nsTArrayElementTraits {
public:
// Invoke the default constructor in place.
static inline void Construct(E *e) {
new (static_cast<void *>(e)) E();
// Do NOT call "E()"! That triggers C++ "default initialization"
// which zeroes out POD ("plain old data") types such as regular ints.
// We don't want that because it can be a performance issue and people
// don't expect it; nsTArray should work like a regular C/C++ array in
// this respect.
new (static_cast<void *>(e)) E;
}
// Invoke the copy-constructor in place.
template<class A>

Просмотреть файл

@ -58,7 +58,7 @@
#include "MoreFilesX.h"
#include "FSCopyObject.h"
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#include "nsTraceRefcntImpl.h"
// Mac Includes
@ -483,7 +483,7 @@ NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions)
CFURLRef pathURLRef = mBaseRef;
FSRef pathFSRef;
CFStringRef leafStrRef = nsnull;
nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
nsAutoTArray<UniChar, FILENAME_BUFFER_SIZE> buffer;
Boolean success;
// Work backwards through the path to find the last node which
@ -494,11 +494,11 @@ NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions)
if (!leafStrRef)
break;
CFIndex leafLen = ::CFStringGetLength(leafStrRef);
if (!buffer.EnsureElemCapacity(leafLen + 1))
if (!buffer.SetLength(leafLen + 1))
break;
::CFStringGetCharacters(leafStrRef, CFRangeMake(0, leafLen), buffer.get());
buffer.get()[leafLen] = '\0';
nonExtantNodes.AppendString(nsString(nsDependentString(buffer.get())));
::CFStringGetCharacters(leafStrRef, CFRangeMake(0, leafLen), buffer.Elements());
buffer[leafLen] = '\0';
nonExtantNodes.AppendString(nsString(nsDependentString(buffer.Elements())));
::CFRelease(leafStrRef);
leafStrRef = nsnull;
@ -2499,12 +2499,12 @@ static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult)
if (chars)
aResult.Assign(chars, length);
else {
nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
if (!buffer.EnsureElemCapacity(length))
nsAutoTArray<UniChar, FILENAME_BUFFER_SIZE> buffer;
if (!buffer.SetLength(length))
CopyUTF8toUTF16(aSrc, aResult);
else {
CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.get());
aResult.Assign(buffer.get(), length);
CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.Elements());
aResult.Assign(buffer.Elements(), length);
}
}
CFRelease(inStr);

Просмотреть файл

@ -50,7 +50,7 @@
#include "xpcom-private.h"
#include "nsError.h"
#include "prio.h" /* for PR_Rename */
#include "nsAutoBuffer.h"
#include "nsTArray.h"
#if defined(_SCO_DS)
#define _SVID3 /* for statvfs.h */
@ -764,10 +764,10 @@ static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult)
if (chars)
aResult.Assign(chars, length);
else {
nsAutoBuffer<UniChar, 512> buffer;
if (buffer.EnsureElemCapacity(length)) {
CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.get());
aResult.Assign(buffer.get(), length);
nsAutoTArray<UniChar, 512> buffer;
if (buffer.SetLength(length)) {
CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.Elements());
aResult.Assign(buffer.Elements(), length);
}
else
CopyUTF8toUTF16(aSrc, aResult);