Bug 827824 - Use uint8_t for mTxInlineFrame. r=mcmanus
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Thu, 17 Jan 2013 08:25:03 +0900
changeset 119087 b7743e1e31e475e8a14f82a59c572910f230b499
parent 119086 e270f015e0e1e6881119675bd5b1c9be0b4720f2
child 119088 2f28e36cd272a8d4fcf0fa28d9c6fca9f958bd3c
push id21454
push userVYV03354@nifty.ne.jp
push dateWed, 16 Jan 2013 23:26:30 +0000
treeherdermozilla-inbound@b7743e1e31e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs827824
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 827824 - Use uint8_t for mTxInlineFrame. r=mcmanus
netwerk/protocol/http/SpdySession3.cpp
netwerk/protocol/http/SpdySession3.h
netwerk/protocol/http/SpdyStream3.cpp
netwerk/protocol/http/SpdyStream3.h
--- a/netwerk/protocol/http/SpdySession3.cpp
+++ b/netwerk/protocol/http/SpdySession3.cpp
@@ -491,36 +491,50 @@ SpdySession3::ResetDownstreamState()
       --mConcurrent;
       ProcessPending();
     }
   }
   mInputFrameBufferUsed = 0;
   mInputFrameDataStream = nullptr;
 }
 
-void
-SpdySession3::EnsureBuffer(nsAutoArrayPtr<char> &buf,
+template<typename T> void
+SpdySession3::EnsureBuffer(nsAutoArrayPtr<T> &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;
-  
-  nsAutoArrayPtr<char> tmp(new char[objSize]);
+
+  MOZ_STATIC_ASSERT(sizeof(T) == 1, "sizeof(T) must be 1");
+  nsAutoArrayPtr<T> tmp(new T[objSize]);
   memcpy(tmp, buf, preserve);
   buf = tmp;
 }
 
+// Instantiate supported templates explicitly.
+template void
+SpdySession3::EnsureBuffer(nsAutoArrayPtr<char> &buf,
+                           uint32_t newSize,
+                           uint32_t preserve,
+                           uint32_t &objSize);
+
+template void
+SpdySession3::EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf,
+                           uint32_t newSize,
+                           uint32_t preserve,
+                           uint32_t &objSize);
+
 void
 SpdySession3::zlibInit()
 {
   mDownstreamZlib.zalloc = SpdyStream3::zlib_allocator;
   mDownstreamZlib.zfree = SpdyStream3::zlib_destructor;
   mDownstreamZlib.opaque = Z_NULL;
 
   inflateInit(&mDownstreamZlib);
--- a/netwerk/protocol/http/SpdySession3.h
+++ b/netwerk/protocol/http/SpdySession3.h
@@ -143,17 +143,18 @@ public:
   static nsresult HandleRstStream(SpdySession3 *);
   static nsresult HandleSettings(SpdySession3 *);
   static nsresult HandleNoop(SpdySession3 *);
   static nsresult HandlePing(SpdySession3 *);
   static nsresult HandleGoAway(SpdySession3 *);
   static nsresult HandleHeaders(SpdySession3 *);
   static nsresult HandleWindowUpdate(SpdySession3 *);
 
-  static void EnsureBuffer(nsAutoArrayPtr<char> &,
+  template<typename T>
+  static void EnsureBuffer(nsAutoArrayPtr<T> &,
                            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);
 
   // an overload of nsAHttpConnection
   void TransactionHasDataToWrite(nsAHttpTransaction *);
--- a/netwerk/protocol/http/SpdyStream3.cpp
+++ b/netwerk/protocol/http/SpdyStream3.cpp
@@ -61,17 +61,17 @@ SpdyStream3::SpdyStream3(nsAHttpTransact
     mTotalSent(0),
     mTotalRead(0)
 {
   NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread");
 
   LOG3(("SpdyStream3::SpdyStream3 %p", this));
 
   mRemoteWindow = spdySession->GetServerInitialWindow();
-  mTxInlineFrame = new char[mTxInlineFrameSize];
+  mTxInlineFrame = new uint8_t[mTxInlineFrameSize];
   mDecompressBuffer = new char[mDecompressBufferSize];
 }
 
 SpdyStream3::~SpdyStream3()
 {
   mStreamID = SpdySession3::kDeadStreamID;
 }
 
@@ -551,34 +551,36 @@ SpdyStream3::TransmitFrame(const char *b
   }
   if (NS_FAILED(rv))     // this will include WOULD_BLOCK
     return rv;
 
   // This function calls mSegmentReader->OnReadSegment to report the actual SPDY
   // bytes through to the SpdySession3 and then the HttpConnection which calls
   // the socket write function. It will accept all of the inline and stream
   // data because of the above 'commitment' even if it has to buffer
-  
-  rv = mSegmentReader->OnReadSegment(mTxInlineFrame, mTxInlineFrameUsed,
+
+  rv = mSegmentReader->OnReadSegment(reinterpret_cast<char*>(mTxInlineFrame.get()),
+                                     mTxInlineFrameUsed,
                                      &transmittedCount);
   LOG3(("SpdyStream3::TransmitFrame for inline session=%p "
         "stream=%p result %x len=%d",
         mSession, this, rv, transmittedCount));
 
   NS_ABORT_IF_FALSE(rv != NS_BASE_STREAM_WOULD_BLOCK,
                     "inconsistent inline commitment result");
 
   if (NS_FAILED(rv))
     return rv;
 
   NS_ABORT_IF_FALSE(transmittedCount == mTxInlineFrameUsed,
                     "inconsistent inline commitment count");
-    
+
   SpdySession3::LogIO(mSession, this, "Writing from Inline Buffer",
-                     mTxInlineFrame, transmittedCount);
+                      reinterpret_cast<char*>(mTxInlineFrame.get()),
+                      transmittedCount);
 
   if (mTxStreamFrameSize) {
     if (!buf) {
       // this cannot happen
       NS_ABORT_IF_FALSE(false, "Stream transmit with null buf argument to "
                         "TransmitFrame()");
       LOG(("Stream transmit with null buf argument to TransmitFrame()\n"));
       return NS_ERROR_UNEXPECTED;
@@ -1116,18 +1118,17 @@ SpdyStream3::ExecuteCompress(uint32_t fl
     if (avail < 1) {
       SpdySession3::EnsureBuffer(mTxInlineFrame,
                                 mTxInlineFrameSize + 2000,
                                 mTxInlineFrameUsed,
                                 mTxInlineFrameSize);
       avail = mTxInlineFrameSize - mTxInlineFrameUsed;
     }
 
-    mZlib->next_out = reinterpret_cast<unsigned char *> (mTxInlineFrame.get()) +
-      mTxInlineFrameUsed;
+    mZlib->next_out = mTxInlineFrame + mTxInlineFrameUsed;
     mZlib->avail_out = avail;
     deflate(mZlib, flushMode);
     mTxInlineFrameUsed += avail - mZlib->avail_out;
   } while (mZlib->avail_in > 0 || !mZlib->avail_out);
 }
 
 void
 SpdyStream3::CompressToFrame(uint32_t data)
@@ -1233,17 +1234,17 @@ SpdyStream3::OnReadSegment(const char *b
       mBlockedOnRwin = true;
       return NS_BASE_STREAM_WOULD_BLOCK;
     }
     mBlockedOnRwin = false;
 
     dataLength = std::min(count, mChunkSize);
 
     if (dataLength > mRemoteWindow)
-      dataLength = mRemoteWindow;
+      dataLength = static_cast<uint32_t>(mRemoteWindow);
 
     LOG3(("SpdyStream3 this=%p id 0x%X remote window is %d. Chunk is %d\n", 
           this, mStreamID, mRemoteWindow, dataLength));
     mRemoteWindow -= dataLength;
 
     LOG3(("SpdyStream3 %p id %x request len remaining %d, "
           "count avail %d, chunk used %d",
           this, mStreamID, mRequestBodyLenRemaining, count, dataLength));
--- a/netwerk/protocol/http/SpdyStream3.h
+++ b/netwerk/protocol/http/SpdyStream3.h
@@ -170,17 +170,17 @@ private:
   // which additional HEADERS data is invalid
   uint32_t                     mReceivedData         : 1;
 
   // Flag is set after TCP send autotuning has been disabled
   uint32_t                     mSetTCPSocketBuffer   : 1;
 
   // The InlineFrame and associated data is used for composing control
   // frames and data frame headers.
-  nsAutoArrayPtr<char>         mTxInlineFrame;
+  nsAutoArrayPtr<uint8_t>      mTxInlineFrame;
   uint32_t                     mTxInlineFrameSize;
   uint32_t                     mTxInlineFrameUsed;
 
   // mTxStreamFrameSize tracks the progress of
   // transmitting a request body data frame. The data frame itself
   // is never copied into the spdy layer.
   uint32_t                     mTxStreamFrameSize;