bool ParseString(const nsACString& aSource, char aDelimiter, nsTArray<nsCString>& aArray) { int32_t start = 0; int32_t end = aSource.Length(); uint32_t oldLength = aArray.Length(); for (;;) { int32_t delimiter = aSource.FindChar(aDelimiter, start); if (delimiter < 0) { delimiter = end; } if (delimiter != start) { if (!aArray.AppendElement(Substring(aSource, start, delimiter - start))) { aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength); return false; } } if (delimiter == end) break; start = ++delimiter; if (start == end) break; } return true; }
bool ParseString(const nsACString& aSource, char aDelimiter, nsTArray<nsCString>& aArray) { nsACString::const_iterator start, end; aSource.BeginReading(start); aSource.EndReading(end); uint32_t oldLength = aArray.Length(); for (;;) { nsACString::const_iterator delimiter = start; FindCharInReadable(aDelimiter, delimiter, end); if (delimiter != start) { if (!aArray.AppendElement(Substring(start, delimiter))) { aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength); return false; } } if (delimiter == end) break; start = ++delimiter; if (start == end) break; } return true; }
PRBool ParseString(const nsACString& aSource, char aDelimiter, nsTArray<nsCString>& aArray) { PRInt32 start = 0; PRInt32 end = aSource.Length(); PRUint32 oldLength = aArray.Length(); for (;;) { PRInt32 delimiter = aSource.FindChar(aDelimiter, start); if (delimiter < 0) { delimiter = end; } if (delimiter != start) { if (!aArray.AppendElement(Substring(aSource, start, delimiter - start))) { aArray.RemoveElementsAt(oldLength, aArray.Length() - oldLength); return PR_FALSE; } } if (delimiter == end) break; start = ++delimiter; if (start == end) break; } return PR_TRUE; }
void AudioNodeStream::UpMixDownMixChunk(const AudioChunk* aChunk, uint32_t aOutputChannelCount, nsTArray<const void*>& aOutputChannels, nsTArray<float>& aDownmixBuffer) { static const float silenceChannel[WEBAUDIO_BLOCK_SIZE] = {0.f}; aOutputChannels.AppendElements(aChunk->mChannelData); if (aOutputChannels.Length() < aOutputChannelCount) { if (mChannelInterpretation == ChannelInterpretation::Speakers) { AudioChannelsUpMix(&aOutputChannels, aOutputChannelCount, nullptr); NS_ASSERTION(aOutputChannelCount == aOutputChannels.Length(), "We called GetAudioChannelsSuperset to avoid this"); } else { // Fill up the remaining aOutputChannels by zeros for (uint32_t j = aOutputChannels.Length(); j < aOutputChannelCount; ++j) { aOutputChannels.AppendElement(silenceChannel); } } } else if (aOutputChannels.Length() > aOutputChannelCount) { if (mChannelInterpretation == ChannelInterpretation::Speakers) { nsAutoTArray<float*,GUESS_AUDIO_CHANNELS> outputChannels; outputChannels.SetLength(aOutputChannelCount); aDownmixBuffer.SetLength(aOutputChannelCount * WEBAUDIO_BLOCK_SIZE); for (uint32_t j = 0; j < aOutputChannelCount; ++j) { outputChannels[j] = &aDownmixBuffer[j * WEBAUDIO_BLOCK_SIZE]; } AudioChannelsDownMix(aOutputChannels, outputChannels.Elements(), aOutputChannelCount, WEBAUDIO_BLOCK_SIZE); aOutputChannels.SetLength(aOutputChannelCount); for (uint32_t j = 0; j < aOutputChannels.Length(); ++j) { aOutputChannels[j] = outputChannels[j]; } } else { // Drop the remaining aOutputChannels aOutputChannels.RemoveElementsAt(aOutputChannelCount, aOutputChannels.Length() - aOutputChannelCount); } } }
// This method is a hack to prioritize newly inserted messages, // without changing the size of the queue. It is required since // we cannot sort ranges in nsTArray. nsresult nsAutoSyncState::SortSubQueueBasedOnStrategy(nsTArray<nsMsgKey> &aQueue, uint32_t aStartingOffset) { NS_ASSERTION(aStartingOffset < aQueue.Length(), "*** Starting offset is out of range"); // Copy already downloaded messages into a temporary queue, // we want to exclude them from the sort. nsTArray<nsMsgKey> tmpQ; tmpQ.AppendElements(aQueue.Elements(), aStartingOffset); // Remove already downloaded messages and sort the resulting queue aQueue.RemoveElementsAt(0, aStartingOffset); nsresult rv = SortQueueBasedOnStrategy(aQueue); // copy excluded messages back aQueue.InsertElementsAt(0, tmpQ); return rv; }