Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WTF_h | 31 #ifndef WTF_h |
| 32 #define WTF_h | 32 #define WTF_h |
| 33 | 33 |
| 34 #include "wtf/Compiler.h" | 34 #include "wtf/Compiler.h" |
| 35 #include "wtf/CurrentTime.h" | 35 #include "wtf/CurrentTime.h" |
| 36 #include "wtf/PartitionAlloc.h" | 36 #include "wtf/PartitionAlloc.h" |
| 37 #include <limits.h> | |
| 37 | 38 |
| 38 namespace WTF { | 39 namespace WTF { |
| 39 | 40 |
| 40 // This function must be called exactly once from the main thread before using a nything else in WTF. | 41 // This function must be called exactly once from the main thread before using a nything else in WTF. |
| 41 WTF_EXPORT void initialize(TimeFunction currentTimeFunction, TimeFunction monoto nicallyIncreasingTimeFunction); | 42 WTF_EXPORT void initialize(TimeFunction currentTimeFunction, TimeFunction monoto nicallyIncreasingTimeFunction); |
| 42 WTF_EXPORT void shutdown(); | 43 WTF_EXPORT void shutdown(); |
| 43 | 44 |
| 44 class Partitions { | 45 class Partitions { |
| 45 public: | 46 public: |
| 46 static void initialize(); | 47 static void initialize(); |
| 47 static void shutdown(); | 48 static void shutdown(); |
| 48 static ALWAYS_INLINE PartitionRoot* getBufferPartition() { return m_bufferAl locator.root(); } | 49 static ALWAYS_INLINE PartitionRoot* getBufferPartition() { return m_bufferAl locator.root(); } |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 static PartitionAllocator<4096> m_bufferAllocator; | 52 static PartitionAllocator<4096> m_bufferAllocator; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 | 55 |
| 56 class QuantizedAllocation { | |
|
abarth-chromium
2013/09/07 05:08:24
Why is this in WTF.h? Please put it in its own he
| |
| 57 public: | |
| 58 static const size_t kMaxAllocation = 32768; | |
| 59 static const size_t kMaxRounding = 4096; | |
| 60 static const size_t kMinRounding = 16; | |
| 61 static const size_t kMinRoundingLimit = 256; | |
| 62 static const size_t kTableSize = kMaxAllocation / kMinRoundingLimit; | |
|
abarth-chromium
2013/09/07 05:08:24
Can you add some comments explaining where these n
| |
| 63 | |
| 64 // Using "unsigned" is not a limitation because Chromium's max malloc() is 2 GB even on 64-bit. | |
| 65 static const size_t kMaxUnquantizedAllocation = UINT_MAX - kMaxRounding; | |
| 66 | |
| 67 static void init(); | |
| 68 | |
| 69 static size_t quantizedSize(size_t size) | |
| 70 { | |
| 71 size_t roundToLessOne; | |
| 72 if (UNLIKELY(size >= kMaxAllocation)) | |
| 73 roundToLessOne = kMaxRounding - 1; | |
| 74 else | |
| 75 roundToLessOne = table[size / kMinRoundingLimit]; | |
| 76 return (size + roundToLessOne) & ~roundToLessOne; | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 static unsigned short table[kTableSize]; | |
| 81 }; | |
| 82 | |
| 55 } // namespace WTF | 83 } // namespace WTF |
| 56 | 84 |
| 57 #endif // WTF_h | 85 #endif // WTF_h |
| OLD | NEW |