bmalloc: allocate small and medium objects using the same bump pointer class
[WebKit-https.git] / Source / bmalloc / bmalloc / Allocator.h
index 2cd24ed8bfe984c172088228d6c518954faad5eb..65f149af8fb56b890332ef59a4f63eae82c76655 100644 (file)
 #ifndef Allocator_h
 #define Allocator_h
 
+#include "BumpAllocator.h"
 #include "FixedVector.h"
 #include "MediumAllocator.h"
 #include "Sizes.h"
-#include "SmallAllocator.h"
-#include "XSmallAllocator.h"
+#include "SmallLine.h"
 #include <array>
 
 namespace bmalloc {
@@ -51,67 +51,29 @@ public:
     void scavenge();
 
 private:
-    XSmallAllocator& xSmallAllocatorFor(size_t);
-    SmallAllocator& smallAllocatorFor(size_t);
-    
-    void* allocateFastCase(SmallAllocator&);
+    void* allocateFastCase(BumpAllocator&);
 
     void* allocateMedium(size_t);
     void* allocateLarge(size_t);
     void* allocateXLarge(size_t);
     
-    void log(XSmallAllocator&);
-    void log(SmallAllocator&);
-    void log(MediumAllocator&);
-
-    void processXSmallAllocatorLog();
-    void processSmallAllocatorLog();
-    void processMediumAllocatorLog();
-
     Deallocator& m_deallocator;
 
-    std::array<XSmallAllocator, xSmallMax / alignment> m_xSmallAllocators;
-    std::array<SmallAllocator, smallMax / alignment> m_smallAllocators;
-    MediumAllocator m_mediumAllocator;
-
-    FixedVector<std::pair<XSmallLine*, unsigned char>, xSmallAllocatorLogCapacity> m_xSmallAllocatorLog;
-    FixedVector<std::pair<SmallLine*, unsigned char>, smallAllocatorLogCapacity> m_smallAllocatorLog;
-    FixedVector<std::pair<MediumLine*, unsigned char>, mediumAllocatorLogCapacity> m_mediumAllocatorLog;
+    std::array<BumpAllocator, smallMax / alignment> m_smallAllocators;
+    std::array<BumpAllocator, mediumMax / alignment> m_mediumAllocators;
 };
 
-inline XSmallAllocator& Allocator::xSmallAllocatorFor(size_t size)
+inline bool Allocator::allocateFastCase(size_t size, void*& object)
 {
-    size_t index = mask((size - 1ul) / alignment, m_xSmallAllocators.size() - 1);
-    return m_xSmallAllocators[index];
-}
+    if (size > smallMax)
+        return false;
 
-inline SmallAllocator& Allocator::smallAllocatorFor(size_t size)
-{
-    size_t index = mask((size - 1ul) / alignment, m_smallAllocators.size() - 1);
-    return m_smallAllocators[index];
-}
+    BumpAllocator& allocator = m_smallAllocators[smallSizeClassFor(size)];
+    if (!allocator.canAllocate())
+        return false;
 
-inline bool Allocator::allocateFastCase(size_t size, void*& object)
-{
-    if (size <= xSmallMax) {
-        XSmallAllocator& allocator = xSmallAllocatorFor(size);
-        if (!allocator.canAllocate())
-            return false;
-        
-        object = allocator.allocate();
-        return true;
-    }
-    
-    if (size <= smallMax) {
-        SmallAllocator& allocator = smallAllocatorFor(size);
-        if (!allocator.canAllocate())
-            return false;
-
-        object = allocator.allocate();
-        return true;
-    }
-    
-    return false;
+    object = allocator.allocate();
+    return true;
 }
 
 inline void* Allocator::allocate(size_t size)