Index: Source/wtf/WTF.h |
diff --git a/Source/wtf/WTF.h b/Source/wtf/WTF.h |
index 27c8a2e8bea893859a4a694e7759cd17c23ba041..402b60416afbd4193abe1490ea944024ff858337 100644 |
--- a/Source/wtf/WTF.h |
+++ b/Source/wtf/WTF.h |
@@ -34,6 +34,7 @@ |
#include "wtf/Compiler.h" |
#include "wtf/CurrentTime.h" |
#include "wtf/PartitionAlloc.h" |
+#include <limits.h> |
namespace WTF { |
@@ -52,6 +53,33 @@ private: |
}; |
+class QuantizedAllocation { |
abarth-chromium
2013/09/07 05:08:24
Why is this in WTF.h? Please put it in its own he
|
+public: |
+ static const size_t kMaxAllocation = 32768; |
+ static const size_t kMaxRounding = 4096; |
+ static const size_t kMinRounding = 16; |
+ static const size_t kMinRoundingLimit = 256; |
+ static const size_t kTableSize = kMaxAllocation / kMinRoundingLimit; |
abarth-chromium
2013/09/07 05:08:24
Can you add some comments explaining where these n
|
+ |
+ // Using "unsigned" is not a limitation because Chromium's max malloc() is 2GB even on 64-bit. |
+ static const size_t kMaxUnquantizedAllocation = UINT_MAX - kMaxRounding; |
+ |
+ static void init(); |
+ |
+ static size_t quantizedSize(size_t size) |
+ { |
+ size_t roundToLessOne; |
+ if (UNLIKELY(size >= kMaxAllocation)) |
+ roundToLessOne = kMaxRounding - 1; |
+ else |
+ roundToLessOne = table[size / kMinRoundingLimit]; |
+ return (size + roundToLessOne) & ~roundToLessOne; |
+ } |
+ |
+private: |
+ static unsigned short table[kTableSize]; |
+}; |
+ |
} // namespace WTF |
#endif // WTF_h |