PRUint32 newBufferLength = (aCount + mLeftOverCount); if (newBufferLength > mBufferSize) { PRUint32 newBufferSize = newBufferLength * 2; rv = mBuffer->Grow(newBufferSize);
while (aCount > 0) { PRUint32 readCount, totalCount = (aCount + mLeftOverCount); if (totalCount >= mBufferSize) { #if GROWABLE_BUFFER PRUint32 newBufferSize = mBufferSize * 2; while (totalCount >= newBufferSize) newBufferSize *= 2; char* newBuffer = new char[newBufferSize]; if (!newBuffer) return NS_ERROR_OUT_OF_MEMORY; memcpy(newBuffer, mBuffer, mLeftOverCount); delete[] mBuffer; mBuffer = newBuffer; mBufferSize = newBufferSize; #else readCount = mBufferSize - mLeftOverCount - 1; #endif } else { readCount = aCount; }  char* buffer = mBuffer; rv = aInputStream->Read(buffer + mLeftOverCount, readCount, &readCount);
NS_IMETHODIMP TokenStreamListener::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, nsIInputStream *aInputStream, PRUint32 aOffset, PRUint32 aCount){    nsresult rv;    PRUint32 newBufferLength = (aCount + mLeftOverCount);    if (newBufferLength > mBufferSize) {        PRUint32 newBufferSize = newBufferLength * 2;        rv = mBuffer->Grow(newBufferSize);        if (NS_FAILED(rv))            return rv;        mBufferSize = newBufferSize;    }        char* buffer = mBuffer->GetBuffer();    rv = aInputStream->Read(buffer + mLeftOverCount, aCount, &aCount);    /* consume the tokens up to the last legal token delimiter in the buffer. */    newBufferLength = (aCount + mLeftOverCount);    buffer[newBufferLength] = '\0';    char* last_delimiter = NULL;    char* scan = buffer + newBufferLength;    while (scan > buffer) {        if (strchr(kBayesianFilterTokenDelimiters, *--scan)) {            last_delimiter = scan;            break;        }    }        if (last_delimiter) {        *last_delimiter = '\0';        mTokenizer.tokenize(buffer);        PRUint32 consumedCount = 1 + (last_delimiter - buffer);        mLeftOverCount = newBufferLength - consumedCount;        if (mLeftOverCount)            memmove(buffer, buffer + consumedCount, mLeftOverCount);    }    return rv;}