Bug 935789, part 1: Kill most uses of prbit.h, r=ehsan
authorJoshua Cranmer <Pidgeot18@gmail.com>
Tue, 12 Nov 2013 18:22:38 -0600
changeset 154658 6f28e77e0a200c723b7ec0545e3a73a147ebe3e9
parent 154657 cd0e2e0ef136b6bcfefaa695bd7909eb2504f9d3
child 154659 7c3792d389bc87d1bfb549cf7c44d45d3be2116e
push id36153
push userPidgeot18@gmail.com
push dateWed, 13 Nov 2013 00:58:42 +0000
treeherdermozilla-inbound@7c3792d389bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs935789
milestone28.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 935789, part 1: Kill most uses of prbit.h, r=ehsan
content/base/src/nsAttrAndChildArray.cpp
gfx/gl/GLContextProviderGLX.cpp
modules/libpref/src/nsPrefBranch.h
netwerk/cache/nsDiskCacheDevice.cpp
netwerk/cache/nsMemoryCacheDevice.cpp
netwerk/protocol/rtsp/controller/RtspController.cpp
rdf/base/src/nsRDFService.cpp
xpcom/ds/nsSupportsArray.cpp
xpcom/glue/nsVoidArray.cpp
xpcom/glue/pldhash.cpp
xpcom/io/nsStorageStream.cpp
--- a/content/base/src/nsAttrAndChildArray.cpp
+++ b/content/base/src/nsAttrAndChildArray.cpp
@@ -5,20 +5,20 @@
 
 /*
  * Storage of the children and attributes of a DOM node; storage for
  * the two is unified to minimize footprint.
  */
 
 #include "nsAttrAndChildArray.h"
 
+#include "mozilla/MathAlgorithms.h"
 #include "mozilla/MemoryReporting.h"
 
 #include "nsMappedAttributeElement.h"
-#include "prbit.h"
 #include "nsString.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsRuleWalker.h"
 #include "nsMappedAttributes.h"
 #include "nsUnicharUtils.h"
 #include "nsAutoPtr.h"
 #include "nsContentUtils.h" // nsAutoScriptBlocker
 
@@ -767,17 +767,17 @@ nsAttrAndChildArray::GrowBy(uint32_t aGr
   uint32_t minSize = size + aGrowSize;
 
   if (minSize <= ATTRCHILD_ARRAY_LINEAR_THRESHOLD) {
     do {
       size += ATTRCHILD_ARRAY_GROWSIZE;
     } while (size < minSize);
   }
   else {
-    size = 1u << PR_CeilingLog2(minSize);
+    size = 1u << mozilla::CeilingLog2(minSize);
   }
 
   bool needToInitialize = !mImpl;
   Impl* newImpl = static_cast<Impl*>(moz_realloc(mImpl, size * sizeof(void*)));
   NS_ENSURE_TRUE(newImpl, false);
 
   mImpl = newImpl;
 
--- a/gfx/gl/GLContextProviderGLX.cpp
+++ b/gfx/gl/GLContextProviderGLX.cpp
@@ -10,20 +10,20 @@
 #elif defined(MOZ_WIDGET_QT)
 #include <QWidget>
 #define GET_NATIVE_WINDOW(aWidget) static_cast<QWidget*>(aWidget->GetNativeData(NS_NATIVE_SHELLWIDGET))->winId()
 #endif
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 
+#include "mozilla/MathAlgorithms.h"
 #include "mozilla/X11Util.h"
 
 #include "prenv.h"
-#include "prbit.h" // for PR_FLOOR_LOG2
 #include "GLContextProvider.h"
 #include "GLLibraryLoader.h"
 #include "nsDebug.h"
 #include "nsIWidget.h"
 #include "GLXLibrary.h"
 #include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "gfxImageSurface.h"
@@ -294,18 +294,17 @@ GLXLibrary::CreatePixmap(gfxASurface* aS
     }
 
     gfxXlibSurface *xs = static_cast<gfxXlibSurface*>(aSurface);
     const XRenderPictFormat *format = xs->XRenderFormat();
     if (!format || format->type != PictTypeDirect) {
         return None;
     }
     const XRenderDirectFormat& direct = format->direct;
-    int alphaSize;
-    PR_FLOOR_LOG2(alphaSize, direct.alphaMask + 1);
+    int alphaSize = FloorLog2(direct.alphaMask + 1);
     NS_ASSERTION((1 << alphaSize) - 1 == direct.alphaMask,
                  "Unexpected render format with non-adjacent alpha bits");
 
     int attribs[] = { GLX_DOUBLEBUFFER, False,
                       GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
                       GLX_ALPHA_SIZE, alphaSize,
                       (alphaSize ? GLX_BIND_TO_TEXTURE_RGBA_EXT
                        : GLX_BIND_TO_TEXTURE_RGB_EXT), True,
--- a/modules/libpref/src/nsPrefBranch.h
+++ b/modules/libpref/src/nsPrefBranch.h
@@ -13,17 +13,16 @@
 #include "nsIRelativeFilePref.h"
 #include "nsIFile.h"
 #include "nsString.h"
 #include "nsVoidArray.h"
 #include "nsTArray.h"
 #include "nsWeakReference.h"
 #include "nsClassHashtable.h"
 #include "nsCRT.h"
-#include "prbit.h"
 #include "nsTraceRefcnt.h"
 #include "mozilla/HashFunctions.h"
 #include "mozilla/MemoryReporting.h"
 
 namespace mozilla {
 class PreferenceServiceReporter;
 } // namespace mozilla;
 
--- a/netwerk/cache/nsDiskCacheDevice.cpp
+++ b/netwerk/cache/nsDiskCacheDevice.cpp
@@ -19,17 +19,16 @@
 #elif defined(XP_OS2)
 #define INCL_DOSERRORS
 #include <os2.h>
 #else
 // XXX add necessary include file for ftruncate (or equivalent)
 #endif
 
 #include "prthread.h"
-#include "prbit.h"
 
 #include "private/pprio.h"
 
 #include "nsDiskCacheDevice.h"
 #include "nsDiskCacheEntry.h"
 #include "nsDiskCacheMap.h"
 #include "nsDiskCacheStreams.h"
 
--- a/netwerk/cache/nsMemoryCacheDevice.cpp
+++ b/netwerk/cache/nsMemoryCacheDevice.cpp
@@ -8,16 +8,17 @@
 #include "nsMemoryCacheDevice.h"
 #include "nsCacheService.h"
 #include "nsICacheService.h"
 #include "nsICacheVisitor.h"
 #include "nsIStorageStream.h"
 #include "nsIMemoryReporter.h"
 #include "nsCRT.h"
 #include "nsReadableUtils.h"
+#include "mozilla/MathAlgorithms.h"
 #include "mozilla/Telemetry.h"
 #include <algorithm>
 
 // The memory cache implements the "LRU-SP" caching algorithm
 // described in "LRU-SP: A Size-Adjusted and Popularity-Aware LRU Replacement
 // Algorithm for Web Caching" by Kai Cheng and Yahiko Kambayashi.
 
 // We keep kQueueCount LRU queues, which should be about ceil(log2(mHardLimit))
@@ -424,17 +425,17 @@ nsMemoryCacheDevice::EvictionList(nsCach
     if (entry->ExpirationTime() == nsICache::NO_EXPIRATION_TIME)
         return 0;
 
     // compute which eviction queue this entry should go into,
     // based on floor(log2(size/nref))
     int32_t  size       = deltaSize + (int32_t)entry->DataSize();
     int32_t  fetchCount = std::max(1, entry->FetchCount());
 
-    return std::min(PR_FloorLog2(size / fetchCount), kQueueCount - 1);
+    return std::min((int)mozilla::FloorLog2(size / fetchCount), kQueueCount - 1);
 }
 
 
 nsresult
 nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
 {
     nsMemoryCacheDeviceInfo * deviceInfo = new nsMemoryCacheDeviceInfo(this);
     nsCOMPtr<nsICacheDeviceInfo> deviceRef(deviceInfo);
--- a/netwerk/protocol/rtsp/controller/RtspController.cpp
+++ b/netwerk/protocol/rtsp/controller/RtspController.cpp
@@ -33,17 +33,16 @@
 #include "mozilla/Attributes.h"
 #include "TimeStamp.h"
 #include "mozilla/Telemetry.h"
 #include "prlog.h"
 
 #include "plbase64.h"
 #include "prmem.h"
 #include "prnetdb.h"
-#include "prbit.h"
 #include "zlib.h"
 #include <algorithm>
 #include "nsDebug.h"
 
 extern PRLogModuleInfo* gRtspLog;
 #undef LOG
 #define LOG(args) PR_LOG(gRtspLog, PR_LOG_DEBUG, args)
 
--- a/rdf/base/src/nsRDFService.cpp
+++ b/rdf/base/src/nsRDFService.cpp
@@ -50,17 +50,16 @@
 #include "plhash.h"
 #include "plstr.h"
 #include "prlog.h"
 #include "prprf.h"
 #include "prmem.h"
 #include "rdf.h"
 #include "nsCRT.h"
 #include "nsCRTGlue.h"
-#include "prbit.h"
 #include "mozilla/HashFunctions.h"
 
 using namespace mozilla;
 
 ////////////////////////////////////////////////////////////////////////
 
 static NS_DEFINE_CID(kRDFXMLDataSourceCID,    NS_RDFXMLDATASOURCE_CID);
 static NS_DEFINE_CID(kRDFDefaultResourceCID,  NS_RDFDEFAULTRESOURCE_CID);
--- a/xpcom/ds/nsSupportsArray.cpp
+++ b/xpcom/ds/nsSupportsArray.cpp
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <string.h>
-#include "prbit.h"
+#include "mozilla/MathAlgorithms.h"
 #include "nsSupportsArray.h"
 #include "nsSupportsArrayEnumerator.h"
 #include "nsIObjectInputStream.h"
 #include "nsIObjectOutputStream.h"
 
 #if DEBUG_SUPPORTSARRAY
 #define MAXSUPPORTS 20
 
@@ -124,17 +124,17 @@ void nsSupportsArray::GrowArrayBy(int32_
   uint32_t newSize = sizeof(mArray[0]) * newCount;
 
   if (newSize >= (uint32_t) kLinearThreshold)
   {
     // newCount includes enough space for at least kGrowArrayBy new slots.
     // Select the next power-of-two size in bytes above that if newSize is
     // not a power of two.
     if (newSize & (newSize - 1))
-      newSize = 1u << PR_CeilingLog2(newSize);
+      newSize = 1u << mozilla::CeilingLog2(newSize);
 
     newCount = newSize / sizeof(mArray[0]);
   }
   // XXX This would be far more efficient in many allocators if we used
   // XXX PR_Realloc(), etc
   nsISupports** oldArray = mArray;
 
   mArray = new nsISupports*[newCount];
--- a/xpcom/glue/nsVoidArray.cpp
+++ b/xpcom/glue/nsVoidArray.cpp
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; c-file-offsets: ((substatement-open . 0)) -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/MathAlgorithms.h"
 #include "mozilla/MemoryReporting.h"
 #include <stdlib.h>
 
 #include "nsVoidArray.h"
 #include "nsQuickSort.h"
-#include "prbit.h"
 #include "nsISupportsImpl.h" // for nsTraceRefcnt
 #include "nsAlgorithm.h"
 
 /**
  * Grow the array by at least this many elements at a time.
  */
 static const int32_t kMinGrowArrayBy = 8;
 static const int32_t kMaxGrowArrayBy = 1024;
@@ -234,17 +234,17 @@ bool nsVoidArray::GrowArrayBy(int32_t aG
     // Also, limit the increase in size to about a VM page or two.
     if (GetArraySize() >= kMaxGrowArrayBy)
     {
       newCapacity = GetArraySize() + XPCOM_MAX(kMaxGrowArrayBy,aGrowBy);
       newSize = SIZEOF_IMPL(newCapacity);
     }
     else
     {
-      PR_CEILING_LOG2(newSize, newSize);
+      newSize = mozilla::CeilingLog2(newSize);
       newCapacity = CAPACITYOF_IMPL(1u << newSize);
     }
   }
   // frees old mImpl IF this succeeds
   if (!SizeTo(newCapacity))
     return false;
 
   return true;
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -4,19 +4,19 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * Double hashing implementation.
  */
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include "prbit.h"
 #include "pldhash.h"
 #include "mozilla/HashFunctions.h"
+#include "mozilla/MathAlgorithms.h"
 #include "nsDebug.h"     /* for PR_ASSERT */
 #include "nsAlgorithm.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryReporting.h"
 
 #ifdef PL_DHASHMETER
 # define METER(x)       x
 #else
@@ -40,32 +40,32 @@
  */
 #define IMMUTABLE_RECURSION_LEVEL ((uint16_t)-1)
 
 #define RECURSION_LEVEL_SAFE_TO_FINISH(table_)                                \
     (table_->recursionLevel == 0 ||                                           \
      table_->recursionLevel == IMMUTABLE_RECURSION_LEVEL)
 
 #define INCREMENT_RECURSION_LEVEL(table_)                                     \
-    PR_BEGIN_MACRO                                                            \
+    do {                                                                      \
         if (table_->recursionLevel != IMMUTABLE_RECURSION_LEVEL)              \
             ++table_->recursionLevel;                                         \
-    PR_END_MACRO
+    } while(0)
 #define DECREMENT_RECURSION_LEVEL(table_)                                     \
-    PR_BEGIN_MACRO                                                            \
+    do {                                                                      \
         if (table->recursionLevel != IMMUTABLE_RECURSION_LEVEL) {             \
             MOZ_ASSERT(table->recursionLevel > 0);                            \
             --table->recursionLevel;                                          \
         }                                                                     \
-    PR_END_MACRO
+    } while(0)
 
 #else
 
-#define INCREMENT_RECURSION_LEVEL(table_)   PR_BEGIN_MACRO PR_END_MACRO
-#define DECREMENT_RECURSION_LEVEL(table_)   PR_BEGIN_MACRO PR_END_MACRO
+#define INCREMENT_RECURSION_LEVEL(table_)   do { } while(0)
+#define DECREMENT_RECURSION_LEVEL(table_)   do { } while(0)
 
 #endif /* defined(DEBUG) */
 
 using namespace mozilla;
 
 void *
 PL_DHashAllocTable(PLDHashTable *table, uint32_t nbytes)
 {
@@ -201,18 +201,17 @@ PL_DHashTableInit(PLDHashTable *table, c
     }
 #endif
 
     table->ops = ops;
     table->data = data;
     if (capacity < PL_DHASH_MIN_SIZE)
         capacity = PL_DHASH_MIN_SIZE;
 
-    int log2;
-    PR_CEILING_LOG2(log2, capacity);
+    int log2 = CeilingLog2(capacity);
 
     capacity = 1u << log2;
     if (capacity > PL_DHASH_MAX_SIZE)
         return false;
     table->hashShift = PL_DHASH_BITS - log2;
     table->entrySize = entrySize;
     table->entryCount = table->removedCount = 0;
     table->generation = 0;
@@ -656,18 +655,17 @@ PL_DHashTableEnumerate(PLDHashTable *tab
          (capacity > PL_DHASH_MIN_SIZE &&
           table->entryCount <= MinLoad(capacity)))) {
         METER(table->stats.enumShrinks++);
         capacity = table->entryCount;
         capacity += capacity >> 1;
         if (capacity < PL_DHASH_MIN_SIZE)
             capacity = PL_DHASH_MIN_SIZE;
 
-        uint32_t ceiling;
-        PR_CEILING_LOG2(ceiling, capacity);
+        uint32_t ceiling = CeilingLog2(capacity);
         ceiling -= PL_DHASH_BITS - table->hashShift;
 
         (void) ChangeTable(table, ceiling);
     }
 
     DECREMENT_RECURSION_LEVEL(table);
 
     return i;
--- a/xpcom/io/nsStorageStream.cpp
+++ b/xpcom/io/nsStorageStream.cpp
@@ -12,22 +12,22 @@
  * with the attendant performance loss and heap fragmentation.
  */
 
 #include "nsAlgorithm.h"
 #include "nsStorageStream.h"
 #include "nsSegmentedBuffer.h"
 #include "nsStreamUtils.h"
 #include "nsCOMPtr.h"
-#include "prbit.h"
 #include "nsIInputStream.h"
 #include "nsISeekableStream.h"
 #include "prlog.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Likely.h"
+#include "mozilla/MathAlgorithms.h"
 
 #if defined(PR_LOGGING)
 //
 // Log module for StorageStream logging...
 //
 // To enable logging (see prlog.h for full details):
 //
 //    set NSPR_LOG_MODULES=StorageStreamLog:5
@@ -67,17 +67,17 @@ NS_IMETHODIMP
 nsStorageStream::Init(uint32_t segmentSize, uint32_t maxSize,
                       nsIMemory *segmentAllocator)
 {
     mSegmentedBuffer = new nsSegmentedBuffer();
     if (!mSegmentedBuffer)
         return NS_ERROR_OUT_OF_MEMORY;
     
     mSegmentSize = segmentSize;
-    mSegmentSizeLog2 = PR_FloorLog2(segmentSize);
+    mSegmentSizeLog2 = mozilla::FloorLog2(segmentSize);
 
     // Segment size must be a power of two
     if (mSegmentSize != ((uint32_t)1 << mSegmentSizeLog2))
         return NS_ERROR_INVALID_ARG;
 
     return mSegmentedBuffer->Init(segmentSize, maxSize, segmentAllocator);
 }