From 2e1ef0025a2e370731fa2148d7a9887865492f7e Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 8 May 2014 21:03:35 -0400 Subject: [PATCH] Bug 1004098 - Make nsTArray use size_t in its interface (32bitness is fine as an internal detail) - r=froydnj, sr=bsmedberg --- content/base/src/nsXMLNameSpaceMap.cpp | 4 +- content/html/content/src/HTMLFormElement.cpp | 4 +- content/html/content/src/HTMLInputElement.cpp | 2 +- .../media/AudioNodeExternalInputStream.cpp | 8 +-- content/media/AudioNodeExternalInputStream.h | 4 +- content/media/EncodedBufferCache.cpp | 4 +- content/media/MediaCache.cpp | 2 +- .../media/mediasource/SourceBufferResource.h | 2 +- content/media/webaudio/AnalyserNode.cpp | 16 ++--- content/media/webaudio/AudioNode.cpp | 18 +++--- content/media/webaudio/WebAudioUtils.cpp | 2 +- content/media/webaudio/WebAudioUtils.h | 2 +- content/xul/document/src/XULDocument.cpp | 2 +- dom/indexedDB/TransactionThreadPool.cpp | 4 +- dom/ipc/TabChild.cpp | 6 +- dom/workers/WorkerPrivate.cpp | 4 +- dom/xbl/XBLChildrenElement.cpp | 6 +- dom/xbl/nsBindingManager.cpp | 8 +-- dom/xslt/base/txExpandedNameMap.cpp | 9 ++- editor/libeditor/html/nsHTMLEditRules.cpp | 4 +- editor/libeditor/html/nsHTMLEditor.cpp | 4 +- gfx/thebes/gfxXlibSurface.cpp | 2 +- image/src/RasterImage.cpp | 10 +-- image/src/RasterImage.h | 6 +- layout/base/DisplayItemClip.cpp | 4 +- layout/generic/nsTextFrame.cpp | 2 +- layout/style/nsTransitionManager.cpp | 4 +- layout/tables/nsCellMap.cpp | 4 +- layout/tables/nsTableFrame.cpp | 2 +- layout/xul/nsMenuBarFrame.cpp | 4 +- modules/libjar/nsJARProtocolHandler.h | 2 +- toolkit/components/places/nsMaybeWeakPtr.cpp | 2 +- .../components/url-classifier/ChunkSet.cpp | 2 +- .../components/url-classifier/Classifier.cpp | 4 +- widget/xpwidgets/nsTransferable.cpp | 6 +- xpcom/ds/nsExpirationTracker.h | 2 +- xpcom/glue/DeadlockDetector.h | 4 +- xpcom/glue/nsTArray-inl.h | 21 ++++--- xpcom/glue/nsTArray.cpp | 7 +++ xpcom/glue/nsTArray.h | 22 +++---- xpcom/glue/nsTArrayForwardDeclare.h | 6 +- xpcom/glue/nsTObserverArray.h | 16 ++--- xpcom/tests/TestTArray.cpp | 61 ++++++++++--------- 43 files changed, 159 insertions(+), 149 deletions(-) diff --git a/content/base/src/nsXMLNameSpaceMap.cpp b/content/base/src/nsXMLNameSpaceMap.cpp index 8e753898162..d0423e2eeb3 100644 --- a/content/base/src/nsXMLNameSpaceMap.cpp +++ b/content/base/src/nsXMLNameSpaceMap.cpp @@ -79,7 +79,7 @@ nsXMLNameSpaceMap::AddPrefix(nsIAtom *aPrefix, nsString &aURI) int32_t nsXMLNameSpaceMap::FindNameSpaceID(nsIAtom *aPrefix) const { - uint32_t index = mNameSpaces.IndexOf(aPrefix); + size_t index = mNameSpaces.IndexOf(aPrefix); if (index != mNameSpaces.NoIndex) { return mNameSpaces[index].nameSpaceID; } @@ -93,7 +93,7 @@ nsXMLNameSpaceMap::FindNameSpaceID(nsIAtom *aPrefix) const nsIAtom* nsXMLNameSpaceMap::FindPrefix(int32_t aNameSpaceID) const { - uint32_t index = mNameSpaces.IndexOf(aNameSpaceID); + size_t index = mNameSpaces.IndexOf(aNameSpaceID); if (index != mNameSpaces.NoIndex) { return mNameSpaces[index].prefix; } diff --git a/content/html/content/src/HTMLFormElement.cpp b/content/html/content/src/HTMLFormElement.cpp index 40d2fa2eeb7..c8fd4c3c884 100644 --- a/content/html/content/src/HTMLFormElement.cpp +++ b/content/html/content/src/HTMLFormElement.cpp @@ -1252,7 +1252,7 @@ HTMLFormElement::RemoveElement(nsGenericHTMLFormElement* aChild, // Find the index of the child. This will be used later if necessary // to find the default submit. - uint32_t index = controls.IndexOf(aChild); + size_t index = controls.IndexOf(aChild); NS_ENSURE_STATE(index != controls.NoIndex); controls.RemoveElementAt(index); @@ -2339,7 +2339,7 @@ HTMLFormElement::AddImageElementToTable(HTMLImageElement* aChild, nsresult HTMLFormElement::RemoveImageElement(HTMLImageElement* aChild) { - uint32_t index = mImageElements.IndexOf(aChild); + size_t index = mImageElements.IndexOf(aChild); NS_ENSURE_STATE(index != mImageElements.NoIndex); mImageElements.RemoveElementAt(index); diff --git a/content/html/content/src/HTMLInputElement.cpp b/content/html/content/src/HTMLInputElement.cpp index 553821a67d5..ad6933329bb 100644 --- a/content/html/content/src/HTMLInputElement.cpp +++ b/content/html/content/src/HTMLInputElement.cpp @@ -2518,7 +2518,7 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const } } else { nsString count; - count.AppendInt(mFiles.Length()); + count.AppendInt(int(mFiles.Length())); const char16_t* params[] = { count.get() }; nsContentUtils::FormatLocalizedString(nsContentUtils::eFORMS_PROPERTIES, diff --git a/content/media/AudioNodeExternalInputStream.cpp b/content/media/AudioNodeExternalInputStream.cpp index 40e4dad4194..dea58a95421 100644 --- a/content/media/AudioNodeExternalInputStream.cpp +++ b/content/media/AudioNodeExternalInputStream.cpp @@ -31,14 +31,14 @@ AudioNodeExternalInputStream::TrackMapEntry::~TrackMapEntry() } } -uint32_t +size_t AudioNodeExternalInputStream::GetTrackMapEntry(const StreamBuffer::Track& aTrack, GraphTime aFrom) { AudioSegment* segment = aTrack.Get(); // Check the map for an existing entry corresponding to the input track. - for (uint32_t i = 0; i < mTrackMap.Length(); ++i) { + for (size_t i = 0; i < mTrackMap.Length(); ++i) { TrackMapEntry* map = &mTrackMap[i]; if (map->mTrackID == aTrack.GetID()) { return i; @@ -58,7 +58,7 @@ AudioNodeExternalInputStream::GetTrackMapEntry(const StreamBuffer::Track& aTrack // Create a speex resampler with the same sample rate and number of channels // as the track. SpeexResamplerState* resampler = nullptr; - uint32_t channelCount = std::min((*ci).mChannelData.Length(), + size_t channelCount = std::min((*ci).mChannelData.Length(), WebAudioUtils::MaxChannelCount); if (aTrack.GetRate() != mSampleRate) { resampler = speex_resampler_init(channelCount, @@ -340,7 +340,7 @@ AudioNodeExternalInputStream::ProcessInput(GraphTime aFrom, GraphTime aTo, !tracks.IsEnded(); tracks.Next()) { const StreamBuffer::Track& inputTrack = *tracks; // Create a TrackMapEntry if necessary. - uint32_t trackMapIndex = GetTrackMapEntry(inputTrack, aFrom); + size_t trackMapIndex = GetTrackMapEntry(inputTrack, aFrom); // Maybe there's nothing in this track yet. If so, ignore it. (While the // track is only playing silence, we may not be able to determine the // correct number of channels to start resampling.) diff --git a/content/media/AudioNodeExternalInputStream.h b/content/media/AudioNodeExternalInputStream.h index 06134d3752f..88f4e35a7a7 100644 --- a/content/media/AudioNodeExternalInputStream.h +++ b/content/media/AudioNodeExternalInputStream.h @@ -92,8 +92,8 @@ private: * Creates a TrackMapEntry for the track, if needed. Returns the index * of the TrackMapEntry or NoIndex if no entry is needed yet. */ - uint32_t GetTrackMapEntry(const StreamBuffer::Track& aTrack, - GraphTime aFrom); + size_t GetTrackMapEntry(const StreamBuffer::Track& aTrack, + GraphTime aFrom); }; } diff --git a/content/media/EncodedBufferCache.cpp b/content/media/EncodedBufferCache.cpp index 388ac78b371..2b395f8f821 100644 --- a/content/media/EncodedBufferCache.cpp +++ b/content/media/EncodedBufferCache.cpp @@ -29,8 +29,8 @@ EncodedBufferCache::AppendBuffer(nsTArray & aBuf) if (mTempFileEnabled) { // has created temporary file, write buffer in it for (uint32_t i = 0; i < mEncodedBuffers.Length(); i++) { - int64_t amount = PR_Write(mFD, mEncodedBuffers.ElementAt(i).Elements(), mEncodedBuffers.ElementAt(i).Length()); - if (amount < mEncodedBuffers.ElementAt(i).Length()) { + int32_t amount = PR_Write(mFD, mEncodedBuffers.ElementAt(i).Elements(), mEncodedBuffers.ElementAt(i).Length()); + if (amount < 0 || size_t(amount) < mEncodedBuffers.ElementAt(i).Length()) { NS_WARNING("Failed to write media cache block!"); } } diff --git a/content/media/MediaCache.cpp b/content/media/MediaCache.cpp index 598d905e9c0..acf307805ad 100644 --- a/content/media/MediaCache.cpp +++ b/content/media/MediaCache.cpp @@ -779,7 +779,7 @@ MediaCache::FindReusableBlock(TimeStamp aNow, { mReentrantMonitor.AssertCurrentThreadIn(); - uint32_t length = std::min(uint32_t(aMaxSearchBlockIndex), mIndex.Length()); + uint32_t length = std::min(uint32_t(aMaxSearchBlockIndex), uint32_t(mIndex.Length())); if (aForStream && aForStreamBlock > 0 && uint32_t(aForStreamBlock) <= aForStream->mBlocks.Length()) { diff --git a/content/media/mediasource/SourceBufferResource.h b/content/media/mediasource/SourceBufferResource.h index 074d7b9a531..bb2fa5bd2d9 100644 --- a/content/media/mediasource/SourceBufferResource.h +++ b/content/media/mediasource/SourceBufferResource.h @@ -144,7 +144,7 @@ private: uint32_t end = std::min(GetAtOffset(aOffset + aCount, nullptr) + 1, GetSize()); for (uint32_t i = start; i < end; ++i) { ResourceItem* item = ResourceAt(i); - uint32_t bytes = std::min(aCount, item->mData.Length() - offset); + uint32_t bytes = std::min(aCount, uint32_t(item->mData.Length() - offset)); if (bytes != 0) { memcpy(aDest, &item->mData[offset], bytes); offset = 0; diff --git a/content/media/webaudio/AnalyserNode.cpp b/content/media/webaudio/AnalyserNode.cpp index 8edc74c151d..87140beca92 100644 --- a/content/media/webaudio/AnalyserNode.cpp +++ b/content/media/webaudio/AnalyserNode.cpp @@ -172,9 +172,9 @@ AnalyserNode::GetFloatFrequencyData(const Float32Array& aArray) } float* buffer = aArray.Data(); - uint32_t length = std::min(aArray.Length(), mOutputBuffer.Length()); + size_t length = std::min(size_t(aArray.Length()), mOutputBuffer.Length()); - for (uint32_t i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { buffer[i] = WebAudioUtils::ConvertLinearToDecibels(mOutputBuffer[i], mMinDecibels); } } @@ -190,9 +190,9 @@ AnalyserNode::GetByteFrequencyData(const Uint8Array& aArray) const double rangeScaleFactor = 1.0 / (mMaxDecibels - mMinDecibels); unsigned char* buffer = aArray.Data(); - uint32_t length = std::min(aArray.Length(), mOutputBuffer.Length()); + size_t length = std::min(size_t(aArray.Length()), mOutputBuffer.Length()); - for (uint32_t i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { const double decibels = WebAudioUtils::ConvertLinearToDecibels(mOutputBuffer[i], mMinDecibels); // scale down the value to the range of [0, UCHAR_MAX] const double scaled = std::max(0.0, std::min(double(UCHAR_MAX), @@ -205,9 +205,9 @@ void AnalyserNode::GetFloatTimeDomainData(const Float32Array& aArray) { float* buffer = aArray.Data(); - uint32_t length = std::min(aArray.Length(), mBuffer.Length()); + size_t length = std::min(size_t(aArray.Length()), mBuffer.Length()); - for (uint32_t i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { buffer[i] = mBuffer[(i + mWriteIndex) % mBuffer.Length()];; } } @@ -216,9 +216,9 @@ void AnalyserNode::GetByteTimeDomainData(const Uint8Array& aArray) { unsigned char* buffer = aArray.Data(); - uint32_t length = std::min(aArray.Length(), mBuffer.Length()); + size_t length = std::min(size_t(aArray.Length()), mBuffer.Length()); - for (uint32_t i = 0; i < length; ++i) { + for (size_t i = 0; i < length; ++i) { const float value = mBuffer[(i + mWriteIndex) % mBuffer.Length()]; // scale the value to the range of [0, UCHAR_MAX] const float scaled = std::max(0.0f, std::min(float(UCHAR_MAX), diff --git a/content/media/webaudio/AudioNode.cpp b/content/media/webaudio/AudioNode.cpp index a8db696b6e2..3cfb1228b41 100644 --- a/content/media/webaudio/AudioNode.cpp +++ b/content/media/webaudio/AudioNode.cpp @@ -109,10 +109,10 @@ AudioNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const } template -static uint32_t +static size_t FindIndexOfNode(const nsTArray& aInputNodes, const AudioNode* aNode) { - for (uint32_t i = 0; i < aInputNodes.Length(); ++i) { + for (size_t i = 0; i < aInputNodes.Length(); ++i) { if (aInputNodes[i].mInputNode == aNode) { return i; } @@ -121,11 +121,11 @@ FindIndexOfNode(const nsTArray& aInputNodes, const AudioNode* aNode) } template -static uint32_t +static size_t FindIndexOfNodeWithPorts(const nsTArray& aInputNodes, const AudioNode* aNode, uint32_t aInputPort, uint32_t aOutputPort) { - for (uint32_t i = 0; i < aInputNodes.Length(); ++i) { + for (size_t i = 0; i < aInputNodes.Length(); ++i) { if (aInputNodes[i].mInputNode == aNode && aInputNodes[i].mInputPort == aInputPort && aInputNodes[i].mOutputPort == aOutputPort) { @@ -147,27 +147,27 @@ AudioNode::DisconnectFromGraph() // Disconnect inputs. We don't need them anymore. while (!mInputNodes.IsEmpty()) { - uint32_t i = mInputNodes.Length() - 1; + size_t i = mInputNodes.Length() - 1; nsRefPtr input = mInputNodes[i].mInputNode; mInputNodes.RemoveElementAt(i); input->mOutputNodes.RemoveElement(this); } while (!mOutputNodes.IsEmpty()) { - uint32_t i = mOutputNodes.Length() - 1; + size_t i = mOutputNodes.Length() - 1; nsRefPtr output = mOutputNodes[i].forget(); mOutputNodes.RemoveElementAt(i); - uint32_t inputIndex = FindIndexOfNode(output->mInputNodes, this); + size_t inputIndex = FindIndexOfNode(output->mInputNodes, this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->mInputNodes.RemoveElementAt(inputIndex); } while (!mOutputParams.IsEmpty()) { - uint32_t i = mOutputParams.Length() - 1; + size_t i = mOutputParams.Length() - 1; nsRefPtr output = mOutputParams[i].forget(); mOutputParams.RemoveElementAt(i); - uint32_t inputIndex = FindIndexOfNode(output->InputNodes(), this); + size_t inputIndex = FindIndexOfNode(output->InputNodes(), this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->RemoveInputNode(inputIndex); diff --git a/content/media/webaudio/WebAudioUtils.cpp b/content/media/webaudio/WebAudioUtils.cpp index 5e97d460c15..4d5f7cd40cc 100644 --- a/content/media/webaudio/WebAudioUtils.cpp +++ b/content/media/webaudio/WebAudioUtils.cpp @@ -16,7 +16,7 @@ namespace dom { // 32 is the minimum required by the spec and matches what is used by blink. // The limit protects against large memory allocations. -const uint32_t WebAudioUtils::MaxChannelCount = 32; +const size_t WebAudioUtils::MaxChannelCount = 32; struct ConvertTimeToTickHelper { diff --git a/content/media/webaudio/WebAudioUtils.h b/content/media/webaudio/WebAudioUtils.h index 1ec40fdbfb4..771af3888e1 100644 --- a/content/media/webaudio/WebAudioUtils.h +++ b/content/media/webaudio/WebAudioUtils.h @@ -25,7 +25,7 @@ namespace dom { class AudioParamTimeline; struct WebAudioUtils { - static const uint32_t MaxChannelCount; + static const size_t MaxChannelCount; static bool FuzzyEqual(float v1, float v2) { diff --git a/content/xul/document/src/XULDocument.cpp b/content/xul/document/src/XULDocument.cpp index 463e7170b64..c5f9ce15833 100644 --- a/content/xul/document/src/XULDocument.cpp +++ b/content/xul/document/src/XULDocument.cpp @@ -1033,7 +1033,7 @@ XULDocument::AttributeChanged(nsIDocument* aDocument, attrSet, needsAttrChange); - uint32_t index = + size_t index = mDelayedAttrChangeBroadcasts.IndexOf(delayedUpdate, 0, nsDelayedBroadcastUpdate::Comparator()); if (index != mDelayedAttrChangeBroadcasts.NoIndex) { diff --git a/dom/indexedDB/TransactionThreadPool.cpp b/dom/indexedDB/TransactionThreadPool.cpp index ab84efc8a5b..d3bc70c2e62 100644 --- a/dom/indexedDB/TransactionThreadPool.cpp +++ b/dom/indexedDB/TransactionThreadPool.cpp @@ -258,7 +258,7 @@ TransactionThreadPool::FinishTransaction(IDBTransaction* aTransaction) NS_ASSERTION(info, "We've never heard of this transaction?!?"); const nsTArray& objectStoreNames = aTransaction->mObjectStoreNames; - for (uint32_t index = 0, count = objectStoreNames.Length(); index < count; + for (size_t index = 0, count = objectStoreNames.Length(); index < count; index++) { TransactionInfoPair* blockInfo = dbTransactionInfo->blockingTransactions.Get(objectStoreNames[index]); @@ -269,7 +269,7 @@ TransactionThreadPool::FinishTransaction(IDBTransaction* aTransaction) blockInfo->lastBlockingReads = nullptr; } - uint32_t i = blockInfo->lastBlockingWrites.IndexOf(info); + size_t i = blockInfo->lastBlockingWrites.IndexOf(info); if (i != blockInfo->lastBlockingWrites.NoIndex) { blockInfo->lastBlockingWrites.RemoveElementAt(i); } diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index f3a0ed4b1a9..25cdb3a669a 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -1455,7 +1455,7 @@ TabChild::RecvCacheFileDescriptor(const nsString& aPath, // First see if we already have a request for this path. const CachedFileDescriptorInfo search(aPath); - uint32_t index = + size_t index = mCachedFileDescriptorInfos.IndexOf(search, 0, search.PathOnlyComparator()); if (index == mCachedFileDescriptorInfos.NoIndex) { @@ -1507,7 +1507,7 @@ TabChild::GetCachedFileDescriptor(const nsAString& aPath, // First see if we've already received a cached file descriptor for this // path. const CachedFileDescriptorInfo search(aPath); - uint32_t index = + size_t index = mCachedFileDescriptorInfos.IndexOf(search, 0, search.PathOnlyComparator()); if (index == mCachedFileDescriptorInfos.NoIndex) { @@ -1563,7 +1563,7 @@ TabChild::CancelCachedFileDescriptorCallback( } const CachedFileDescriptorInfo search(aPath, aCallback); - uint32_t index = + size_t index = mCachedFileDescriptorInfos.IndexOf(search, 0, search.PathAndCallbackComparator()); if (index == mCachedFileDescriptorInfos.NoIndex) { diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 94797e54b85..01f365ebab4 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -3113,13 +3113,13 @@ WorkerPrivateParent::BroadcastErrorToSharedWorkers( // First fire the error event at all SharedWorker objects. This may include // multiple objects in a single window as well as objects in different // windows. - for (uint32_t index = 0; index < sharedWorkers.Length(); index++) { + for (size_t index = 0; index < sharedWorkers.Length(); index++) { nsRefPtr& sharedWorker = sharedWorkers[index]; // May be null. nsPIDOMWindow* window = sharedWorker->GetOwner(); - uint32_t actionsIndex = windowActions.LastIndexOf(WindowAction(window)); + size_t actionsIndex = windowActions.LastIndexOf(WindowAction(window)); // Get the context for this window so that we can report errors correctly. JSContext* cx; diff --git a/dom/xbl/XBLChildrenElement.cpp b/dom/xbl/XBLChildrenElement.cpp index d6caab73e0e..34fa0f63805 100644 --- a/dom/xbl/XBLChildrenElement.cpp +++ b/dom/xbl/XBLChildrenElement.cpp @@ -179,14 +179,14 @@ nsAnonymousContentList::IndexOf(nsIContent* aContent) return -1; } - uint32_t index = 0; + size_t index = 0; for (nsIContent* child = mParent->GetFirstChild(); child; child = child->GetNextSibling()) { if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) { XBLChildrenElement* point = static_cast(child); if (!point->mInsertedChildren.IsEmpty()) { - uint32_t insIndex = point->mInsertedChildren.IndexOf(aContent); + size_t insIndex = point->mInsertedChildren.IndexOf(aContent); if (insIndex != point->mInsertedChildren.NoIndex) { return index + insIndex; } @@ -195,7 +195,7 @@ nsAnonymousContentList::IndexOf(nsIContent* aContent) else { int32_t insIndex = point->IndexOf(aContent); if (insIndex != -1) { - return index + (uint32_t)insIndex; + return index + (size_t)insIndex; } index += point->GetChildCount(); } diff --git a/dom/xbl/nsBindingManager.cpp b/dom/xbl/nsBindingManager.cpp index 0af38f0d25d..096b05c6c34 100644 --- a/dom/xbl/nsBindingManager.cpp +++ b/dom/xbl/nsBindingManager.cpp @@ -334,7 +334,7 @@ nsBindingManager::RemoveFromAttachedQueue(nsXBLBinding* aBinding) { // Don't remove items here as that could mess up an executing // ProcessAttachedQueue. Instead, null the entry in the queue. - uint32_t index = mAttachedStack.IndexOf(aBinding); + size_t index = mAttachedStack.IndexOf(aBinding); if (index != mAttachedStack.NoIndex) { mAttachedStack[index] = nullptr; } @@ -840,7 +840,7 @@ static void InsertAppendedContent(XBLChildrenElement* aPoint, nsIContent* aFirstNewContent) { - uint32_t insertionIndex; + size_t insertionIndex; if (nsIContent* prevSibling = aFirstNewContent->GetPreviousSibling()) { // If we have a previous sibling, then it must already be in aPoint. Find // it and insert after it. @@ -1083,14 +1083,14 @@ nsBindingManager::HandleChildInsertion(nsIContent* aContainer, // TODO If there were multiple insertion points, this approximation can be // wrong. We need to re-run the distribution algorithm. In the meantime, // this should work well enough. - uint32_t index = aAppend ? point->mInsertedChildren.Length() : 0; + size_t index = aAppend ? point->mInsertedChildren.Length() : 0; for (nsIContent* currentSibling = aChild->GetPreviousSibling(); currentSibling; currentSibling = currentSibling->GetPreviousSibling()) { // If we find one of our previous siblings in the insertion point, the // index following it is the correct insertion point. Otherwise, we guess // based on whether we're appending or inserting. - uint32_t pointIndex = point->IndexOfInsertedChild(currentSibling); + size_t pointIndex = point->IndexOfInsertedChild(currentSibling); if (pointIndex != point->NoIndex) { index = pointIndex + 1; break; diff --git a/dom/xslt/base/txExpandedNameMap.cpp b/dom/xslt/base/txExpandedNameMap.cpp index 46ef9372421..b033d615553 100644 --- a/dom/xslt/base/txExpandedNameMap.cpp +++ b/dom/xslt/base/txExpandedNameMap.cpp @@ -26,7 +26,7 @@ class txMapItemComparator nsresult txExpandedNameMap_base::addItem(const txExpandedName& aKey, void* aValue) { - uint32_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); + size_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); if (pos != mItems.NoIndex) { return NS_ERROR_XSLT_ALREADY_SET; } @@ -53,11 +53,10 @@ nsresult txExpandedNameMap_base::setItem(const txExpandedName& aKey, void** aOldValue) { *aOldValue = nullptr; - uint32_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); + size_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); if (pos != mItems.NoIndex) { *aOldValue = mItems[pos].mValue; mItems[pos].mValue = aValue; - return NS_OK; } @@ -78,7 +77,7 @@ nsresult txExpandedNameMap_base::setItem(const txExpandedName& aKey, */ void* txExpandedNameMap_base::getItem(const txExpandedName& aKey) const { - uint32_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); + size_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); if (pos != mItems.NoIndex) { return mItems[pos].mValue; } @@ -95,7 +94,7 @@ void* txExpandedNameMap_base::getItem(const txExpandedName& aKey) const void* txExpandedNameMap_base::removeItem(const txExpandedName& aKey) { void* value = nullptr; - uint32_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); + size_t pos = mItems.IndexOf(aKey, 0, txMapItemComparator()); if (pos != mItems.NoIndex) { value = mItems[pos].mValue; mItems.RemoveElementAt(pos); diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index ed5b8f48288..e7793968e79 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -8145,8 +8145,8 @@ nsHTMLEditRules::RemoveEmptyNodes() NS_ENSURE_TRUE(node, NS_ERROR_FAILURE); nsINode* parent = node->GetParentNode(); - - uint32_t idx = skipList.IndexOf(node); + + size_t idx = skipList.IndexOf(node); if (idx != skipList.NoIndex) { // this node is on our skip list. Skip processing for this node, // and replace its value in the skip list with the value of its parent diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 0365d1b5aed..b53e1e44d17 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3012,7 +3012,7 @@ nsresult nsHTMLEditor::RemoveStyleSheetFromList(const nsAString &aURL) { // is it already in the list? - uint32_t foundIndex; + size_t foundIndex; foundIndex = mStyleSheetURLs.IndexOf(aURL); if (foundIndex == mStyleSheetURLs.NoIndex) return NS_ERROR_FAILURE; @@ -3032,7 +3032,7 @@ nsHTMLEditor::GetStyleSheetForURL(const nsAString &aURL, *aStyleSheet = 0; // is it already in the list? - uint32_t foundIndex; + size_t foundIndex; foundIndex = mStyleSheetURLs.IndexOf(aURL); if (foundIndex == mStyleSheetURLs.NoIndex) return NS_OK; //No sheet -- don't fail! diff --git a/gfx/thebes/gfxXlibSurface.cpp b/gfx/thebes/gfxXlibSurface.cpp index a6d7f34ed6f..a75e6c16a77 100644 --- a/gfx/thebes/gfxXlibSurface.cpp +++ b/gfx/thebes/gfxXlibSurface.cpp @@ -404,7 +404,7 @@ DisplayTable::GetColormapAndVisual(Screen* aScreen, XRenderPictFormat* aFormat, } nsTArray* displays = &sDisplayTable->mDisplays; - uint32_t d = displays->IndexOf(display, 0, FindDisplay()); + size_t d = displays->IndexOf(display, 0, FindDisplay()); if (d == displays->NoIndex) { d = displays->Length(); diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index 7ca2f8de7f4..b7f15c5c79b 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -2861,7 +2861,7 @@ RasterImage::RequestDiscard() // Flushes up to aMaxBytes to the decoder. nsresult -RasterImage::DecodeSomeData(uint32_t aMaxBytes, DecodeStrategy aStrategy) +RasterImage::DecodeSomeData(size_t aMaxBytes, DecodeStrategy aStrategy) { // We should have a decoder if we get here NS_ABORT_IF_FALSE(mDecoder, "trying to decode without decoder!"); @@ -2886,8 +2886,8 @@ RasterImage::DecodeSomeData(uint32_t aMaxBytes, DecodeStrategy aStrategy) MOZ_ASSERT(mBytesDecoded < mSourceData.Length()); // write the proper amount of data - uint32_t bytesToDecode = std::min(aMaxBytes, - mSourceData.Length() - mBytesDecoded); + size_t bytesToDecode = std::min(aMaxBytes, + mSourceData.Length() - mBytesDecoded); nsresult rv = WriteToDecoder(mSourceData.Elements() + mBytesDecoded, bytesToDecode, aStrategy); @@ -3384,7 +3384,7 @@ RasterImage::DecodePool::DecodeJob::Run() mRequest->mRequestStatus = DecodeRequest::REQUEST_ACTIVE; - uint32_t oldByteCount = mImage->mBytesDecoded; + size_t oldByteCount = mImage->mBytesDecoded; DecodeType type = DECODE_TYPE_UNTIL_DONE_BYTES; @@ -3396,7 +3396,7 @@ RasterImage::DecodePool::DecodeJob::Run() DecodePool::Singleton()->DecodeSomeOfImage(mImage, DECODE_ASYNC, type, mRequest->mBytesToDecode); - uint32_t bytesDecoded = mImage->mBytesDecoded - oldByteCount; + size_t bytesDecoded = mImage->mBytesDecoded - oldByteCount; mRequest->mRequestStatus = DecodeRequest::REQUEST_WORK_DONE; diff --git a/image/src/RasterImage.h b/image/src/RasterImage.h index 8eb957ca14a..678ce60e4d6 100644 --- a/image/src/RasterImage.h +++ b/image/src/RasterImage.h @@ -369,7 +369,7 @@ private: RasterImage* mImage; - uint32_t mBytesToDecode; + size_t mBytesToDecode; enum DecodeRequestStatus { @@ -681,7 +681,7 @@ private: // data // Decoder and friends nsRefPtr mDecoder; nsRefPtr mDecodeRequest; - uint32_t mBytesDecoded; + size_t mBytesDecoded; bool mInDecoder; // END LOCKED MEMBER VARIABLES @@ -729,7 +729,7 @@ private: // data nsresult SyncDecode(); nsresult InitDecoder(bool aDoSizeDecode); nsresult WriteToDecoder(const char *aBuffer, uint32_t aCount, DecodeStrategy aStrategy); - nsresult DecodeSomeData(uint32_t aMaxBytes, DecodeStrategy aStrategy); + nsresult DecodeSomeData(size_t aMaxBytes, DecodeStrategy aStrategy); bool IsDecodeFinished(); TimeStamp mDrawStartTime; diff --git a/layout/base/DisplayItemClip.cpp b/layout/base/DisplayItemClip.cpp index 09154208f64..ef3886f4421 100644 --- a/layout/base/DisplayItemClip.cpp +++ b/layout/base/DisplayItemClip.cpp @@ -316,7 +316,7 @@ uint32_t DisplayItemClip::GetCommonRoundedRectCount(const DisplayItemClip& aOther, uint32_t aMax) const { - uint32_t end = std::min(std::min(mRoundedClipRects.Length(), aMax), + uint32_t end = std::min(std::min(mRoundedClipRects.Length(), size_t(aMax)), aOther.mRoundedClipRects.Length()); uint32_t clipCount = 0; for (; clipCount < end; ++clipCount) { @@ -331,7 +331,7 @@ DisplayItemClip::GetCommonRoundedRectCount(const DisplayItemClip& aOther, void DisplayItemClip::AppendRoundedRects(nsTArray* aArray, uint32_t aCount) const { - uint32_t count = std::min(mRoundedClipRects.Length(), aCount); + uint32_t count = std::min(mRoundedClipRects.Length(), size_t(aCount)); for (uint32_t i = 0; i < count; ++i) { *aArray->AppendElement() = mRoundedClipRects[i]; } diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index e47748754ae..52ed3529e85 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -2117,7 +2117,7 @@ BuildTextRunsScanner::BuildTextRunForFrames(void* aTextBuffer) gfxTextRunFactory::Parameters params = { mContext, finalUserData, &skipChars, textBreakPointsAfterTransform.Elements(), - textBreakPointsAfterTransform.Length(), + uint32_t(textBreakPointsAfterTransform.Length()), int32_t(firstFrame->PresContext()->AppUnitsPerDevPixel())}; if (mDoubleByteText) { diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index 817061e8c22..375adff6d74 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -574,12 +574,12 @@ nsTransitionManager::ConsiderStartingTransition(nsCSSProperty aProperty, 0.5, dummyValue); bool haveCurrentTransition = false; - uint32_t currentIndex = nsTArray::NoIndex; + size_t currentIndex = nsTArray::NoIndex; const ElementPropertyTransition *oldPT = nullptr; if (aElementTransitions) { nsTArray &pts = aElementTransitions->mPropertyTransitions; - for (uint32_t i = 0, i_end = pts.Length(); i < i_end; ++i) { + for (size_t i = 0, i_end = pts.Length(); i < i_end; ++i) { MOZ_ASSERT(pts[i].mProperties.Length() == 1, "Should have one animation property for a transition"); if (pts[i].mProperties[0].mProperty == aProperty) { diff --git a/layout/tables/nsCellMap.cpp b/layout/tables/nsCellMap.cpp index 105da2c707d..46bc6c5bfb4 100644 --- a/layout/tables/nsCellMap.cpp +++ b/layout/tables/nsCellMap.cpp @@ -718,7 +718,7 @@ nsTableCellMap::Dump(char* aString) const const nsColInfo& colInfo = mCols.ElementAt(colX); printf ("%d=%d/%d ", colX, colInfo.mNumCellsOrig, colInfo.mNumCellsSpan); } - printf(" cols in cache %d\n", mTableFrame.GetColCache().Length()); + printf(" cols in cache %d\n", int(mTableFrame.GetColCache().Length())); nsCellMap* cellMap = mFirstMap; while (cellMap) { cellMap->Dump(nullptr != mBCInfo); @@ -2183,7 +2183,7 @@ void nsCellMap::ShrinkWithoutCell(nsTableCellMap& aMap, // endIndexForRow points at the first slot we don't want to clean up. This // makes the aColIndex == 0 case work right with our unsigned int colX. NS_ASSERTION(endColIndex + 1 <= row.Length(), "span beyond the row size!"); - uint32_t endIndexForRow = std::min(endColIndex + 1, row.Length()); + uint32_t endIndexForRow = std::min(endColIndex + 1, uint32_t(row.Length())); // Since endIndexForRow <= row.Length(), enough to compare aColIndex to it. if (uint32_t(aColIndex) < endIndexForRow) { diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index 33fa27e0567..8d1e5a16286 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -2929,7 +2929,7 @@ nsTableFrame::ReflowChildren(nsTableReflowState& aReflowState, } // if the child is a tbody in paginated mode reduce the height by a repeated footer bool allowRepeatedFooter = false; - for (uint32_t childX = 0; childX < rowGroups.Length(); childX++) { + for (size_t childX = 0; childX < rowGroups.Length(); childX++) { nsIFrame* kidFrame = rowGroups[childX]; // Get the frame state bits // See if we should only reflow the dirty child frames diff --git a/layout/xul/nsMenuBarFrame.cpp b/layout/xul/nsMenuBarFrame.cpp index c9e0d465f6c..cf65696f5d5 100644 --- a/layout/xul/nsMenuBarFrame.cpp +++ b/layout/xul/nsMenuBarFrame.cpp @@ -195,7 +195,7 @@ nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent) // Find a most preferred accesskey which should be returned. nsIFrame* foundMenu = nullptr; - uint32_t foundIndex = accessKeys.NoIndex; + size_t foundIndex = accessKeys.NoIndex; nsIFrame* currFrame = immediateParent->GetFirstPrincipalChild(); while (currFrame) { @@ -211,7 +211,7 @@ nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent) const char16_t* start = shortcutKey.BeginReading(); const char16_t* end = shortcutKey.EndReading(); uint32_t ch = UTF16CharEnumerator::NextChar(&start, end); - uint32_t index = accessKeys.IndexOf(ch); + size_t index = accessKeys.IndexOf(ch); if (index != accessKeys.NoIndex && (foundIndex == accessKeys.NoIndex || index < foundIndex)) { foundMenu = currFrame; diff --git a/modules/libjar/nsJARProtocolHandler.h b/modules/libjar/nsJARProtocolHandler.h index 5895ad10f52..40a70b8f85c 100644 --- a/modules/libjar/nsJARProtocolHandler.h +++ b/modules/libjar/nsJARProtocolHandler.h @@ -15,10 +15,10 @@ #include "nsCOMPtr.h" #include "nsClassHashtable.h" #include "nsHashKeys.h" +#include "nsTArrayForwardDeclare.h" class nsIHashable; class nsIRemoteOpenFileListener; -template class nsAutoTArray; class nsJARProtocolHandler : public nsIJARProtocolHandler , public nsSupportsWeakReference diff --git a/toolkit/components/places/nsMaybeWeakPtr.cpp b/toolkit/components/places/nsMaybeWeakPtr.cpp index 5b05d4b33d9..53a1de684e5 100644 --- a/toolkit/components/places/nsMaybeWeakPtr.cpp +++ b/toolkit/components/places/nsMaybeWeakPtr.cpp @@ -55,7 +55,7 @@ nsresult NS_RemoveWeakElementBase(isupports_array_type *aArray, nsISupports *aElement) { - uint32_t index = aArray->IndexOf(aElement); + size_t index = aArray->IndexOf(aElement); if (index != aArray->NoIndex) { aArray->RemoveElementAt(index); return NS_OK; diff --git a/toolkit/components/url-classifier/ChunkSet.cpp b/toolkit/components/url-classifier/ChunkSet.cpp index 82ec618e737..5d48c95ea25 100644 --- a/toolkit/components/url-classifier/ChunkSet.cpp +++ b/toolkit/components/url-classifier/ChunkSet.cpp @@ -39,7 +39,7 @@ ChunkSet::Serialize(nsACString& aChunkStr) nsresult ChunkSet::Set(uint32_t aChunk) { - uint32_t idx = mChunks.BinaryIndexOf(aChunk); + size_t idx = mChunks.BinaryIndexOf(aChunk); if (idx == nsTArray::NoIndex) { mChunks.InsertElementSorted(aChunk); } diff --git a/toolkit/components/url-classifier/Classifier.cpp b/toolkit/components/url-classifier/Classifier.cpp index 020684ca757..0d59d0db841 100644 --- a/toolkit/components/url-classifier/Classifier.cpp +++ b/toolkit/components/url-classifier/Classifier.cpp @@ -737,7 +737,7 @@ Classifier::ReadNoiseEntries(const Prefix& aPrefix, nsresult rv = cache->GetPrefixes(&prefixes); NS_ENSURE_SUCCESS(rv, rv); - uint32_t idx = prefixes.BinaryIndexOf(aPrefix.ToUint32()); + size_t idx = prefixes.BinaryIndexOf(aPrefix.ToUint32()); if (idx == nsTArray::NoIndex) { NS_WARNING("Could not find prefix in PrefixSet during noise lookup"); @@ -746,7 +746,7 @@ Classifier::ReadNoiseEntries(const Prefix& aPrefix, idx -= idx % aCount; - for (uint32_t i = 0; (i < aCount) && ((idx+i) < prefixes.Length()); i++) { + for (size_t i = 0; (i < aCount) && ((idx+i) < prefixes.Length()); i++) { Prefix newPref; newPref.FromUint32(prefixes[idx+i]); if (newPref != aPrefix) { diff --git a/widget/xpwidgets/nsTransferable.cpp b/widget/xpwidgets/nsTransferable.cpp index 094836bf851..0d11cea8bbd 100644 --- a/widget/xpwidgets/nsTransferable.cpp +++ b/widget/xpwidgets/nsTransferable.cpp @@ -37,10 +37,10 @@ Notes to self: NS_IMPL_ISUPPORTS(nsTransferable, nsITransferable) -uint32_t GetDataForFlavor (const nsTArray& aArray, +size_t GetDataForFlavor (const nsTArray& aArray, const char* aDataFlavor) { - for (uint32_t i = 0 ; i < aArray.Length () ; ++i) { + for (size_t i = 0 ; i < aArray.Length () ; ++i) { if (aArray[i].GetFlavor().Equals (aDataFlavor)) return i; } @@ -542,7 +542,7 @@ nsTransferable::FlavorsTransferableCanImport(nsISupportsArray **_retval) uint32_t importListLen; convertedList->Count(&importListLen); - for ( uint32_t i=0; i < importListLen; ++i ) { + for (uint32_t i = 0; i < importListLen; ++i ) { nsCOMPtr genericFlavor; convertedList->GetElementAt ( i, getter_AddRefs(genericFlavor) ); diff --git a/xpcom/ds/nsExpirationTracker.h b/xpcom/ds/nsExpirationTracker.h index 085bcf4d899..6d16c5d6700 100644 --- a/xpcom/ds/nsExpirationTracker.h +++ b/xpcom/ds/nsExpirationTracker.h @@ -177,7 +177,7 @@ template class nsExpirationTracker { // the indexes of objects in this generation to *decrease*, not increase. // So if we start from the end and work our way backwards we are guaranteed // to see each object at least once. - uint32_t index = generation.Length(); + size_t index = generation.Length(); for (;;) { // Objects could have been removed so index could be outside // the array diff --git a/xpcom/glue/DeadlockDetector.h b/xpcom/glue/DeadlockDetector.h index e9b8eb8793f..951585800be 100644 --- a/xpcom/glue/DeadlockDetector.h +++ b/xpcom/glue/DeadlockDetector.h @@ -181,9 +181,7 @@ private: typedef nsTArray HashEntryArray; typedef typename HashEntryArray::index_type index_type; typedef typename HashEntryArray::size_type size_type; - enum { - NoIndex = HashEntryArray::NoIndex - }; + static const HashEntryArray::index_type NoIndex = HashEntryArray::NoIndex; /** * Value type for the ordering table. Contains the other diff --git a/xpcom/glue/nsTArray-inl.h b/xpcom/glue/nsTArray-inl.h index da8661ee322..f2480dc7a4b 100644 --- a/xpcom/glue/nsTArray-inl.h +++ b/xpcom/glue/nsTArray-inl.h @@ -95,6 +95,9 @@ bool nsTArray_base::UsesAutoArrayBuffer() const { return mHdr == GetAutoArrayBuffer(4) || mHdr == GetAutoArrayBuffer(8); } +// defined in nsTArray.cpp +bool +IsTwiceTheRequiredBytesRepresentableAsUint32(size_t capacity, size_t elemSize); template typename Alloc::ResultTypeProxy @@ -105,10 +108,10 @@ nsTArray_base::EnsureCapacity(size_type capacity, size_type elemSiz // If the requested memory allocation exceeds size_type(-1)/2, then // our doubling algorithm may not be able to allocate it. - // Additionally we couldn't fit in the Header::mCapacity - // member. Just bail out in cases like that. We don't want to be - // allocating 2 GB+ arrays anyway. - if ((uint64_t)capacity * elemSize > size_type(-1)/2) { + // Additionally, if it exceeds uint32_t(-1) then we couldn't fit in the + // Header::mCapacity member. Just bail out in cases like that. We don't want + // to be allocating 2 GB+ arrays anyway. + if (!IsTwiceTheRequiredBytesRepresentableAsUint32(capacity, elemSize)) { Alloc::SizeTooBig((size_t)capacity * elemSize); return Alloc::FailureResult(); } @@ -130,11 +133,11 @@ nsTArray_base::EnsureCapacity(size_type capacity, size_type elemSiz // We increase our capacity so |capacity * elemSize + sizeof(Header)| is the // next power of two, if this value is less than pageSize bytes, or otherwise // so it's the next multiple of pageSize. - const uint32_t pageSizeBytes = 12; - const uint32_t pageSize = 1 << pageSizeBytes; + const size_t pageSizeBytes = 12; + const size_t pageSize = 1 << pageSizeBytes; - uint32_t minBytes = capacity * elemSize + sizeof(Header); - uint32_t bytesToAlloc; + size_t minBytes = capacity * elemSize + sizeof(Header); + size_t bytesToAlloc; if (minBytes >= pageSize) { // Round up to the next multiple of pageSize. bytesToAlloc = pageSize * ((minBytes + pageSize - 1) / pageSize); @@ -173,7 +176,7 @@ nsTArray_base::EnsureCapacity(size_type capacity, size_type elemSiz } // How many elements can we fit in bytesToAlloc? - uint32_t newCapacity = (bytesToAlloc - sizeof(Header)) / elemSize; + size_t newCapacity = (bytesToAlloc - sizeof(Header)) / elemSize; MOZ_ASSERT(newCapacity >= capacity, "Didn't enlarge the array enough!"); header->mCapacity = newCapacity; diff --git a/xpcom/glue/nsTArray.cpp b/xpcom/glue/nsTArray.cpp index 3bfe897c7e1..5d7b869ba95 100644 --- a/xpcom/glue/nsTArray.cpp +++ b/xpcom/glue/nsTArray.cpp @@ -8,5 +8,12 @@ #include "nsTArray.h" #include "nsXPCOM.h" #include "nsDebug.h" +#include "mozilla/CheckedInt.h" nsTArrayHeader nsTArrayHeader::sEmptyHdr = { 0, 0, 0 }; + +bool +IsTwiceTheRequiredBytesRepresentableAsUint32(size_t capacity, size_t elemSize) { + using mozilla::CheckedUint32; + return ((CheckedUint32(capacity) * elemSize) * 2).isValid(); +} diff --git a/xpcom/glue/nsTArray.h b/xpcom/glue/nsTArray.h index 0323b0ce6bf..2bafb97ee46 100644 --- a/xpcom/glue/nsTArray.h +++ b/xpcom/glue/nsTArray.h @@ -285,7 +285,7 @@ template struct nsTArray_SafeElementAtHelper { typedef E* elem_type; - typedef uint32_t index_type; + typedef size_t index_type; // No implementation is provided for these two methods, and that is on // purpose, since we don't support these functions on non-pointer type @@ -298,7 +298,7 @@ template struct nsTArray_SafeElementAtHelper { typedef E* elem_type; - typedef uint32_t index_type; + typedef size_t index_type; elem_type SafeElementAt(index_type i) { return static_cast (this)->SafeElementAt(i, nullptr); @@ -315,7 +315,7 @@ template struct nsTArray_SafeElementAtSmartPtrHelper { typedef E* elem_type; - typedef uint32_t index_type; + typedef size_t index_type; elem_type SafeElementAt(index_type i) { return static_cast (this)->SafeElementAt(i, nullptr); @@ -360,8 +360,8 @@ protected: typedef nsTArrayHeader Header; public: - typedef uint32_t size_type; - typedef uint32_t index_type; + typedef size_t size_type; + typedef size_t index_type; // @return The number of elements in the array. size_type Length() const { @@ -417,7 +417,7 @@ protected: // Note that mHdr may actually be sEmptyHdr in the case where a // zero-length array is inserted into our array. But then n should // always be 0. - void IncrementLength(uint32_t n) { + void IncrementLength(size_t n) { if (mHdr == EmptyHdr()) { if (MOZ_UNLIKELY(n != 0)) { // Writing a non-zero length to the empty header would be extremely bad. @@ -1644,8 +1644,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, uint32_t aFlags = 0) { aFlags |= CycleCollectionEdgeNameArrayFlag; - uint32_t length = aField.Length(); - for (uint32_t i = 0; i < length; ++i) { + size_t length = aField.Length(); + for (size_t i = 0; i < length; ++i) { ImplCycleCollectionTraverse(aCallback, aField[i], aName, aFlags); } } @@ -1693,7 +1693,7 @@ public: // nsAutoArrayBase is a base class for AutoFallibleTArray and nsAutoTArray. // You shouldn't use this class directly. // -template +template class nsAutoArrayBase : public TArrayBase { public: @@ -1764,7 +1764,7 @@ private: // Note that you can cast an nsAutoTArray to // |const AutoFallibleTArray&|. // -template +template class nsAutoTArray : public nsAutoArrayBase, N> { typedef nsAutoTArray self_type; @@ -1787,7 +1787,7 @@ public: // AutoFallibleTArray is a fallible vector class with N elements of // inline storage. // -template +template class AutoFallibleTArray : public nsAutoArrayBase, N> { typedef AutoFallibleTArray self_type; diff --git a/xpcom/glue/nsTArrayForwardDeclare.h b/xpcom/glue/nsTArrayForwardDeclare.h index e2dc959704c..5922cf162e1 100644 --- a/xpcom/glue/nsTArrayForwardDeclare.h +++ b/xpcom/glue/nsTArrayForwardDeclare.h @@ -19,7 +19,7 @@ // template parameters. // -#include +#include template class nsTArray; @@ -27,10 +27,10 @@ class nsTArray; template class FallibleTArray; -template +template class nsAutoTArray; -template +template class AutoFallibleTArray; #define InfallibleTArray nsTArray diff --git a/xpcom/glue/nsTObserverArray.h b/xpcom/glue/nsTObserverArray.h index 1f71e884388..9bd4fe592a8 100644 --- a/xpcom/glue/nsTObserverArray.h +++ b/xpcom/glue/nsTObserverArray.h @@ -22,9 +22,9 @@ class NS_COM_GLUE nsTObserverArray_base { public: - typedef uint32_t index_type; - typedef uint32_t size_type; - typedef int32_t diff_type; + typedef size_t index_type; + typedef size_t size_type; + typedef ptrdiff_t diff_type; protected: class Iterator_base { @@ -69,7 +69,7 @@ class NS_COM_GLUE nsTObserverArray_base { mutable Iterator_base* mIterators; }; -template +template class nsAutoTObserverArray : protected nsTObserverArray_base { public: typedef T elem_type; @@ -415,14 +415,14 @@ class nsTObserverArray : public nsAutoTObserverArray { } }; -template +template inline void ImplCycleCollectionUnlink(nsAutoTObserverArray& aField) { aField.Clear(); } -template +template inline void ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, nsAutoTObserverArray& aField, @@ -430,8 +430,8 @@ ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, uint32_t aFlags = 0) { aFlags |= CycleCollectionEdgeNameArrayFlag; - uint32_t length = aField.Length(); - for (uint32_t i = 0; i < length; ++i) { + size_t length = aField.Length(); + for (size_t i = 0; i < length; ++i) { ImplCycleCollectionTraverse(aCallback, aField.ElementAt(i), aName, aFlags); } } diff --git a/xpcom/tests/TestTArray.cpp b/xpcom/tests/TestTArray.cpp index d9d49b73b46..c374dbe3eea 100644 --- a/xpcom/tests/TestTArray.cpp +++ b/xpcom/tests/TestTArray.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "nsTArray.h" #include "nsAutoPtr.h" #include "nsStringAPI.h" @@ -31,8 +32,8 @@ inline bool operator<(const nsCOMPtr& lhs, const nsCOMPtr& rhs) { template static bool test_basic_array(ElementType *data, - uint32_t dataLen, - const ElementType& extra) { + size_t dataLen, + const ElementType& extra) { nsTArray ary; ary.AppendElements(data, dataLen); if (ary.Length() != dataLen) { @@ -41,7 +42,7 @@ static bool test_basic_array(ElementType *data, if (!(ary == ary)) { return false; } - uint32_t i; + size_t i; for (i = 0; i < ary.Length(); ++i) { if (ary[i] != data[i]) return false; @@ -55,7 +56,7 @@ static bool test_basic_array(ElementType *data, return false; // ensure sort results in ascending order ary.Sort(); - uint32_t j = 0, k = ary.IndexOfFirstElementGt(extra); + size_t j = 0, k = ary.IndexOfFirstElementGt(extra); if (k != 0 && ary[k-1] == extra) return false; for (i = 0; i < ary.Length(); ++i) { @@ -81,23 +82,23 @@ static bool test_basic_array(ElementType *data, } if (ary.BinaryIndexOf(extra) != ary.NoIndex) return false; - uint32_t oldLen = ary.Length(); + size_t oldLen = ary.Length(); ary.RemoveElement(data[dataLen / 2]); if (ary.Length() != (oldLen - 1)) return false; if (!(ary == ary)) return false; - uint32_t index = ary.Length() / 2; + size_t index = ary.Length() / 2; if (!ary.InsertElementAt(index, extra)) return false; if (!(ary == ary)) return false; if (ary[index] != extra) return false; - if (ary.IndexOf(extra) == UINT32_MAX) + if (ary.IndexOf(extra) == ary.NoIndex) return false; - if (ary.LastIndexOf(extra) == UINT32_MAX) + if (ary.LastIndexOf(extra) == ary.NoIndex) return false; // ensure proper searching if (ary.IndexOf(extra) > ary.LastIndexOf(extra)) @@ -114,16 +115,16 @@ static bool test_basic_array(ElementType *data, } if (!ary.AppendElements(copy)) return false; - uint32_t cap = ary.Capacity(); + size_t cap = ary.Capacity(); ary.RemoveElementsAt(copy.Length(), copy.Length()); ary.Compact(); if (ary.Capacity() == cap) return false; ary.Clear(); - if (ary.IndexOf(extra) != UINT32_MAX) + if (ary.IndexOf(extra) != ary.NoIndex) return false; - if (ary.LastIndexOf(extra) != UINT32_MAX) + if (ary.LastIndexOf(extra) != ary.NoIndex) return false; ary.Clear(); @@ -225,7 +226,7 @@ class Object { static bool test_object_array() { nsTArray objArray; const char kdata[] = "hello world"; - uint32_t i; + size_t i; for (i = 0; i < ArrayLength(kdata); ++i) { char x[] = {kdata[i],'\0'}; if (!objArray.AppendElement(Object(x, i))) @@ -251,7 +252,7 @@ static bool test_object_array() { static bool test_autoptr_array() { nsTArray< nsAutoPtr > objArray; const char kdata[] = "hello world"; - for (uint32_t i = 0; i < ArrayLength(kdata); ++i) { + for (size_t i = 0; i < ArrayLength(kdata); ++i) { char x[] = {kdata[i],'\0'}; nsAutoPtr obj(new Object(x,i)); if (!objArray.AppendElement(obj)) // XXX does not call copy-constructor for nsAutoPtr!!! @@ -260,7 +261,7 @@ static bool test_autoptr_array() { return false; obj.forget(); // the array now owns the reference } - for (uint32_t i = 0; i < ArrayLength(kdata); ++i) { + for (size_t i = 0; i < ArrayLength(kdata); ++i) { if (objArray[i]->Str()[0] != kdata[i]) return false; if (objArray[i]->Num() != i) @@ -275,7 +276,7 @@ static bool test_autoptr_array() { static bool test_string_array() { nsTArray strArray; const char kdata[] = "hello world"; - uint32_t i; + size_t i; for (i = 0; i < ArrayLength(kdata); ++i) { nsCString str; str.Assign(kdata[i]); @@ -288,7 +289,7 @@ static bool test_string_array() { } const char kextra[] = "foo bar"; - uint32_t oldLen = strArray.Length(); + size_t oldLen = strArray.Length(); if (!strArray.AppendElement(kextra)) return false; strArray.RemoveElement(kextra); @@ -342,7 +343,7 @@ static bool test_comptr_array() { "foo.txt", "bar.html", "baz.gif" }; nsTArray fileArray; - uint32_t i; + size_t i; for (i = 0; i < ArrayLength(kNames); ++i) { FilePointer f; tmpDir->Clone(getter_AddRefs(f)); @@ -474,7 +475,7 @@ static bool test_autoarray() { return false; if (hdr == array2.DebugGetHeader()) return false; - uint32_t i; + size_t i; for (i = 0; i < ArrayLength(data); ++i) { if (array2[i] != data[i]) return false; @@ -519,8 +520,8 @@ static bool test_indexof() { //---- template -static bool is_heap(const Array& ary, uint32_t len) { - uint32_t index = 1; +static bool is_heap(const Array& ary, size_t len) { + size_t index = 1; while (index < len) { if (ary[index] > ary[(index - 1) >> 1]) return false; @@ -548,7 +549,7 @@ static bool test_heap() { return false; // make sure the heap looks like what we expect const int expected_data[] = {8,7,5,6,4,1,4,2,3}; - uint32_t index; + size_t index; for (index = 0; index < ArrayLength(data); index++) if (ary[index] != expected_data[index]) return false; @@ -595,16 +596,18 @@ static bool test_heap() { #define CHECK_EQ_INT(actual, expected) \ do { \ if ((actual) != (expected)) { \ - printf("%s:%d CHECK_EQ_INT(%s=%u, %s=%u) failed.\n", \ - __FILE__, __LINE__, #actual, (actual), #expected, (expected)); \ - return false; \ + std::cout << __FILE__ << ":" << __LINE__ << " CHECK_EQ_INT(" \ + << #actual << "=" << (actual) << ", " \ + << #expected << "=" << (expected) << ") failed." \ + << std::endl; \ + return false; \ } \ } while(0) #define CHECK_ARRAY(arr, data) \ do { \ - CHECK_EQ_INT((arr).Length(), (uint32_t)ArrayLength(data)); \ - for (uint32_t _i = 0; _i < ArrayLength(data); _i++) { \ + CHECK_EQ_INT((arr).Length(), (size_t)ArrayLength(data)); \ + for (size_t _i = 0; _i < ArrayLength(data); _i++) { \ CHECK_EQ_INT((arr)[_i], (data)[_i]); \ } \ } while(0) @@ -755,7 +758,7 @@ static bool test_swap() { b.AppendElements(data2, ArrayLength(data2)); CHECK_EQ_INT(a.Capacity(), 0); - uint32_t bCapacity = b.Capacity(); + size_t bCapacity = b.Capacity(); a.SwapElements(b); @@ -852,12 +855,12 @@ static bool test_fallible() // 36 * 128MB > 4GB, so we should definitely OOM by the 36th array. const unsigned numArrays = 36; FallibleTArray arrays[numArrays]; - for (uint32_t i = 0; i < numArrays; i++) { + for (size_t i = 0; i < numArrays; i++) { bool success = arrays[i].SetCapacity(128 * 1024 * 1024); if (!success) { // We got our OOM. Check that it didn't come too early. if (i < 8) { - printf("test_fallible: Got OOM on iteration %d. Too early!\n", i); + printf("test_fallible: Got OOM on iteration %d. Too early!\n", int(i)); return false; } return true;