diff --git a/netwerk/protocol/http/Http2Push.cpp b/netwerk/protocol/http/Http2Push.cpp index 78bd8f59c198..133bd59b067c 100644 --- a/netwerk/protocol/http/Http2Push.cpp +++ b/netwerk/protocol/http/Http2Push.cpp @@ -233,10 +233,8 @@ Http2PushTransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer, uint32_t count, uint32_t *countWritten) { if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) { - Http2Session::EnsureBuffer(mBufferedHTTP1, - mBufferedHTTP1Size + kDefaultBufferSize, - mBufferedHTTP1Used, - mBufferedHTTP1Size); + EnsureBuffer(mBufferedHTTP1,mBufferedHTTP1Size + kDefaultBufferSize, + mBufferedHTTP1Used, mBufferedHTTP1Size); } count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used); diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp index bc3dadcd4920..5d447d6ac5d5 100644 --- a/netwerk/protocol/http/Http2Session.cpp +++ b/netwerk/protocol/http/Http2Session.cpp @@ -562,34 +562,6 @@ Http2Session::ResetDownstreamState() mInputFrameDataStream = nullptr; } -template void -Http2Session::EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, - uint32_t preserve, uint32_t &objSize) -{ - if (objSize >= newSize) - return; - - // Leave a little slop on the new allocation - add 2KB to - // what we need and then round the result up to a 4KB (page) - // boundary. - - objSize = (newSize + 2048 + 4095) & ~4095; - - static_assert(sizeof(T) == 1, "sizeof(T) must be 1"); - nsAutoArrayPtr tmp(new T[objSize]); - memcpy(tmp, buf, preserve); - buf = tmp; -} - -// Instantiate supported templates explicitly. -template void -Http2Session::EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, - uint32_t preserve, uint32_t &objSize); - -template void -Http2Session::EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, - uint32_t preserve, uint32_t &objSize); - // call with data length (i.e. 0 for 0 data bytes - ignore 8 byte header) // dest must have 8 bytes of allocated space template void diff --git a/netwerk/protocol/http/Http2Session.h b/netwerk/protocol/http/Http2Session.h index 6e6f0c25777b..85aa19a2414f 100644 --- a/netwerk/protocol/http/Http2Session.h +++ b/netwerk/protocol/http/Http2Session.h @@ -166,9 +166,6 @@ public: static nsresult RecvAltSvc(Http2Session *); static nsresult RecvBlocked(Http2Session *); - template - static void EnsureBuffer(nsAutoArrayPtr &, - uint32_t, uint32_t, uint32_t &); char *EnsureOutputBuffer(uint32_t needed); template diff --git a/netwerk/protocol/http/Http2Stream.cpp b/netwerk/protocol/http/Http2Stream.cpp index b46649438c7b..1f6c443ae5bf 100644 --- a/netwerk/protocol/http/Http2Stream.cpp +++ b/netwerk/protocol/http/Http2Stream.cpp @@ -421,10 +421,8 @@ Http2Stream::ParseHttpRequestHeaders(const char *buf, messageSize += 13; // frame header + priority overhead in HEADERS frame messageSize += (numFrames - 1) * 8; // frame header overhead in CONTINUATION frames - Http2Session::EnsureBuffer(mTxInlineFrame, - dataLength + messageSize, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, dataLength + messageSize, + mTxInlineFrameUsed, mTxInlineFrameSize); mTxInlineFrameUsed += messageSize; LOG3(("%p Generating %d bytes of HEADERS for stream 0x%X with priority weight %u frames %u\n", @@ -546,10 +544,8 @@ Http2Stream::AdjustInitialWindow() } uint8_t *packet = mTxInlineFrame.get() + mTxInlineFrameUsed; - Http2Session::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameUsed + 12, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 12, + mTxInlineFrameUsed, mTxInlineFrameSize); mTxInlineFrameUsed += 12; mSession->CreateFrameHeader(packet, 4, @@ -582,10 +578,8 @@ Http2Stream::AdjustPushedPriority() return; uint8_t *packet = mTxInlineFrame.get() + mTxInlineFrameUsed; - Http2Session::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameUsed + 13, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 13, + mTxInlineFrameUsed, mTxInlineFrameSize); mTxInlineFrameUsed += 13; mSession->CreateFrameHeader(packet, 5, diff --git a/netwerk/protocol/http/SpdyPush3.cpp b/netwerk/protocol/http/SpdyPush3.cpp index 61c0825a69a6..ac1d9304b367 100644 --- a/netwerk/protocol/http/SpdyPush3.cpp +++ b/netwerk/protocol/http/SpdyPush3.cpp @@ -257,10 +257,8 @@ SpdyPush3TransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer, uint32_t count, uint32_t *countWritten) { if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) { - SpdySession3::EnsureBuffer(mBufferedHTTP1, - mBufferedHTTP1Size + kDefaultBufferSize, - mBufferedHTTP1Used, - mBufferedHTTP1Size); + EnsureBuffer(mBufferedHTTP1, mBufferedHTTP1Size + kDefaultBufferSize, + mBufferedHTTP1Used, mBufferedHTTP1Size); } count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used); diff --git a/netwerk/protocol/http/SpdyPush31.cpp b/netwerk/protocol/http/SpdyPush31.cpp index cee1f23621b4..46e6b63edc59 100644 --- a/netwerk/protocol/http/SpdyPush31.cpp +++ b/netwerk/protocol/http/SpdyPush31.cpp @@ -255,10 +255,8 @@ SpdyPush31TransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer, uint32_t count, uint32_t *countWritten) { if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) { - SpdySession31::EnsureBuffer(mBufferedHTTP1, - mBufferedHTTP1Size + kDefaultBufferSize, - mBufferedHTTP1Used, - mBufferedHTTP1Size); + EnsureBuffer(mBufferedHTTP1, mBufferedHTTP1Size + kDefaultBufferSize, + mBufferedHTTP1Used, mBufferedHTTP1Size); } count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used); diff --git a/netwerk/protocol/http/SpdySession3.cpp b/netwerk/protocol/http/SpdySession3.cpp index 0cd835cdcefc..1333e108ec77 100644 --- a/netwerk/protocol/http/SpdySession3.cpp +++ b/netwerk/protocol/http/SpdySession3.cpp @@ -535,40 +535,6 @@ SpdySession3::ResetDownstreamState() mInputFrameDataStream = nullptr; } -template void -SpdySession3::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize) -{ - if (objSize >= newSize) - return; - - // Leave a little slop on the new allocation - add 2KB to - // what we need and then round the result up to a 4KB (page) - // boundary. - - objSize = (newSize + 2048 + 4095) & ~4095; - - static_assert(sizeof(T) == 1, "sizeof(T) must be 1"); - nsAutoArrayPtr tmp(new T[objSize]); - memcpy(tmp, buf, preserve); - buf = tmp; -} - -// Instantiate supported templates explicitly. -template void -SpdySession3::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize); - -template void -SpdySession3::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize); - void SpdySession3::DecrementConcurrent(SpdyStream3 *aStream) { diff --git a/netwerk/protocol/http/SpdySession3.h b/netwerk/protocol/http/SpdySession3.h index 430bc1b73ba8..284df2b368e5 100644 --- a/netwerk/protocol/http/SpdySession3.h +++ b/netwerk/protocol/http/SpdySession3.h @@ -158,10 +158,6 @@ public: static nsresult HandleWindowUpdate(SpdySession3 *); static nsresult HandleCredential(SpdySession3 *); - template - static void EnsureBuffer(nsAutoArrayPtr &, - uint32_t, uint32_t, uint32_t &); - // For writing the SPDY data stream to LOG4 static void LogIO(SpdySession3 *, SpdyStream3 *, const char *, const char *, uint32_t); diff --git a/netwerk/protocol/http/SpdySession31.cpp b/netwerk/protocol/http/SpdySession31.cpp index 57bca0d44b7e..cac97262dce1 100644 --- a/netwerk/protocol/http/SpdySession31.cpp +++ b/netwerk/protocol/http/SpdySession31.cpp @@ -540,40 +540,6 @@ SpdySession31::ResetDownstreamState() mInputFrameDataStream = nullptr; } -template void -SpdySession31::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize) -{ - if (objSize >= newSize) - return; - - // Leave a little slop on the new allocation - add 2KB to - // what we need and then round the result up to a 4KB (page) - // boundary. - - objSize = (newSize + 2048 + 4095) & ~4095; - - static_assert(sizeof(T) == 1, "sizeof(T) must be 1"); - nsAutoArrayPtr tmp(new T[objSize]); - memcpy(tmp, buf, preserve); - buf = tmp; -} - -// Instantiate supported templates explicitly. -template void -SpdySession31::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize); - -template void -SpdySession31::EnsureBuffer(nsAutoArrayPtr &buf, - uint32_t newSize, - uint32_t preserve, - uint32_t &objSize); - void SpdySession31::DecrementConcurrent(SpdyStream31 *aStream) { diff --git a/netwerk/protocol/http/SpdySession31.h b/netwerk/protocol/http/SpdySession31.h index 5710fd9204e7..27279919cd41 100644 --- a/netwerk/protocol/http/SpdySession31.h +++ b/netwerk/protocol/http/SpdySession31.h @@ -157,10 +157,6 @@ public: static nsresult HandleWindowUpdate(SpdySession31 *); static nsresult HandleCredential(SpdySession31 *); - template - static void EnsureBuffer(nsAutoArrayPtr &, - uint32_t, uint32_t, uint32_t &); - // For writing the SPDY data stream to LOG4 static void LogIO(SpdySession31 *, SpdyStream31 *, const char *, const char *, uint32_t); diff --git a/netwerk/protocol/http/SpdyStream3.cpp b/netwerk/protocol/http/SpdyStream3.cpp index db90ecc96172..dfdb01ba9365 100644 --- a/netwerk/protocol/http/SpdyStream3.cpp +++ b/netwerk/protocol/http/SpdyStream3.cpp @@ -569,10 +569,8 @@ SpdyStream3::AdjustInitialWindow() return; toack = PR_htonl(toack); - SpdySession3::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameUsed + 16, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 16, + mTxInlineFrameUsed, mTxInlineFrameSize); unsigned char *packet = mTxInlineFrame.get() + mTxInlineFrameUsed; mTxInlineFrameUsed += 16; @@ -1039,10 +1037,8 @@ SpdyStream3::Uncompress(z_stream *context, !context->avail_out && context->avail_in) { LOG3(("SpdyStream3::Uncompress %p Large Headers - so far %d", this, mDecompressBufferSize)); - SpdySession3::EnsureBuffer(mDecompressBuffer, - mDecompressBufferSize + 4096, - mDecompressBufferUsed, - mDecompressBufferSize); + EnsureBuffer(mDecompressBuffer, mDecompressBufferSize + 4096, + mDecompressBufferUsed, mDecompressBufferSize); } } while (context->avail_in); @@ -1263,10 +1259,8 @@ SpdyStream3::ExecuteCompress(uint32_t flushMode) { uint32_t avail = mTxInlineFrameSize - mTxInlineFrameUsed; if (avail < 1) { - SpdySession3::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameSize + 2000, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameSize + 2000, + mTxInlineFrameUsed, mTxInlineFrameSize); avail = mTxInlineFrameSize - mTxInlineFrameUsed; } diff --git a/netwerk/protocol/http/SpdyStream31.cpp b/netwerk/protocol/http/SpdyStream31.cpp index 51fa90d22b22..cf7bf8f42874 100644 --- a/netwerk/protocol/http/SpdyStream31.cpp +++ b/netwerk/protocol/http/SpdyStream31.cpp @@ -575,10 +575,8 @@ SpdyStream31::AdjustInitialWindow() return; toack = PR_htonl(toack); - SpdySession31::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameUsed + 16, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 16, + mTxInlineFrameUsed, mTxInlineFrameSize); unsigned char *packet = mTxInlineFrame.get() + mTxInlineFrameUsed; mTxInlineFrameUsed += 16; @@ -1055,10 +1053,8 @@ SpdyStream31::Uncompress(z_stream *context, !context->avail_out && context->avail_in) { LOG3(("SpdyStream31::Uncompress %p Large Headers - so far %d", this, mDecompressBufferSize)); - SpdySession31::EnsureBuffer(mDecompressBuffer, - mDecompressBufferSize + 4096, - mDecompressBufferUsed, - mDecompressBufferSize); + EnsureBuffer(mDecompressBuffer, mDecompressBufferSize + 4096, + mDecompressBufferUsed, mDecompressBufferSize); } } while (context->avail_in); @@ -1279,10 +1275,8 @@ SpdyStream31::ExecuteCompress(uint32_t flushMode) { uint32_t avail = mTxInlineFrameSize - mTxInlineFrameUsed; if (avail < 1) { - SpdySession31::EnsureBuffer(mTxInlineFrame, - mTxInlineFrameSize + 2000, - mTxInlineFrameUsed, - mTxInlineFrameSize); + EnsureBuffer(mTxInlineFrame, mTxInlineFrameSize + 2000, + mTxInlineFrameUsed, mTxInlineFrameSize); avail = mTxInlineFrameSize - mTxInlineFrameUsed; } diff --git a/netwerk/protocol/http/nsHttp.cpp b/netwerk/protocol/http/nsHttp.cpp index 390d79f4c27e..593f562e6a03 100644 --- a/netwerk/protocol/http/nsHttp.cpp +++ b/netwerk/protocol/http/nsHttp.cpp @@ -295,5 +295,39 @@ nsHttp::IsPermanentRedirect(uint32_t httpStatus) return httpStatus == 301 || httpStatus == 308; } + +template void +localEnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, + uint32_t preserve, uint32_t &objSize) +{ + if (objSize >= newSize) + return; + + // Leave a little slop on the new allocation - add 2KB to + // what we need and then round the result up to a 4KB (page) + // boundary. + + objSize = (newSize + 2048 + 4095) & ~4095; + + static_assert(sizeof(T) == 1, "sizeof(T) must be 1"); + nsAutoArrayPtr tmp(new T[objSize]); + if (preserve) { + memcpy(tmp, buf, preserve); + } + buf = tmp; +} + +void EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, + uint32_t preserve, uint32_t &objSize) +{ + localEnsureBuffer (buf, newSize, preserve, objSize); +} + +void EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, + uint32_t preserve, uint32_t &objSize) +{ + localEnsureBuffer (buf, newSize, preserve, objSize); +} + } // namespace mozilla::net } // namespace mozilla diff --git a/netwerk/protocol/http/nsHttp.h b/netwerk/protocol/http/nsHttp.h index d7d680303664..10d8ce5ac461 100644 --- a/netwerk/protocol/http/nsHttp.h +++ b/netwerk/protocol/http/nsHttp.h @@ -9,6 +9,7 @@ #include #include "prtime.h" +#include "nsAutoPtr.h" #include "nsString.h" #include "nsError.h" @@ -190,6 +191,11 @@ PRTimeToSeconds(PRTime t_usec) #define HTTP_LWS " \t" #define HTTP_HEADER_VALUE_SEPS HTTP_LWS "," +void EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, + uint32_t preserve, uint32_t &objSize); +void EnsureBuffer(nsAutoArrayPtr &buf, uint32_t newSize, + uint32_t preserve, uint32_t &objSize); + } // namespace mozilla::net } // namespace mozilla