Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1601)

Unified Diff: Source/wtf/WTF.h

Issue 23604048: Get rid of fastMallocGoodSize() and replace it with something generic. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix compile error. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« Source/wtf/Vector.h ('K') | « Source/wtf/Vector.h ('k') | Source/wtf/WTF.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698