Bug 414186 - slow loop code in nsICODecoder? r=stuart. a1.9=schrep
authordolske@mozilla.com
Tue, 19 Feb 2008 15:40:04 -0800
changeset 11889 3fa4dd0551610348de13ba5fd203bf6da68c5ce0
parent 11888 f273cd19c3b2b9f817fded63ec810b47510b24f1
child 11890 966bb0d78337b52120266c5dc427b54af759a904
push idunknown
push userunknown
push dateunknown
reviewersstuart
bugs414186
milestone1.9b4pre
Bug 414186 - slow loop code in nsICODecoder? r=stuart. a1.9=schrep
modules/libpr0n/decoders/bmp/nsICODecoder.cpp
--- a/modules/libpr0n/decoders/bmp/nsICODecoder.cpp
+++ b/modules/libpr0n/decoders/bmp/nsICODecoder.cpp
@@ -218,18 +218,25 @@ nsresult nsICODecoder::ProcessData(const
           return NS_ERROR_FAILURE;
 
         colorDepth = e.mBitCount;
         memcpy(&mDirEntry, &e, sizeof(IconDirEntry));
       }
     }
   }
 
-  while (aCount && mPos < mImageOffset) { // Skip to our offset
-    mPos++; aBuffer++; aCount--;
+  if (mPos < mImageOffset) {
+    // Skip to (or at least towards) the desired image offset
+    PRUint32 toSkip = mImageOffset - mPos;
+    if (toSkip > aCount)
+      toSkip = aCount;
+
+    mPos    += toSkip;
+    aBuffer += toSkip;
+    aCount  -= toSkip;
   }
 
   if (mCurrIcon == mNumIcons && mPos >= mImageOffset && mPos < mImageOffset + BITMAPINFOSIZE) {
     // We've found the icon.
     PRUint32 toCopy = sizeof(mBIHraw) - (mPos - mImageOffset);
     if (toCopy > aCount)
       toCopy = aCount;