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

Unified Diff: Source/wtf/PartitionAlloc.cpp

Issue 21666003: Enhancements to PartitionAlloc to support threading and arbitrary allocation sizes. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review comments. Created 7 years, 4 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
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/PartitionAlloc.cpp
diff --git a/Source/wtf/PartitionAlloc.cpp b/Source/wtf/PartitionAlloc.cpp
index f53b03a79ed2a7c4e740265c8bba758750a66ab1..9b9af0d6821f220f985029b9133e6d5e3f24920f 100644
--- a/Source/wtf/PartitionAlloc.cpp
+++ b/Source/wtf/PartitionAlloc.cpp
@@ -46,6 +46,7 @@ void partitionAllocInit(PartitionRoot* root)
{
ASSERT(!root->initialized);
root->initialized = true;
+ root->lock = 0;
size_t i;
for (i = 0; i < kNumBuckets; ++i) {
PartitionBucket* bucket = &root->buckets[i];
@@ -323,6 +324,36 @@ void partitionFreeSlowPath(PartitionPageHeader* page)
}
}
+void* partitionReallocGeneric(PartitionRoot* root, void* ptr, size_t oldSize, size_t newSize)
+{
+#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ return realloc(ptr, newSize);
+#else
+ size_t oldIndex = oldSize >> kBucketShift;
+ if (oldIndex > kNumBuckets)
+ oldIndex = kNumBuckets;
+ size_t newIndex = newSize >> kBucketShift;
+ if (newIndex > kNumBuckets)
+ newIndex = kNumBuckets;
+
+ if (oldIndex == newIndex) {
+ // Same bucket. But kNumBuckets indicates the fastMalloc "bucket" so in
+ // that case we're not done; we have to forward to fastRealloc.
+ if (oldIndex == kNumBuckets)
+ return WTF::fastRealloc(ptr, newSize);
+ return ptr;
+ }
+ // This realloc cannot be resized in-place. Sadness.
+ void* ret = partitionAllocGeneric(root, newSize);
+ size_t copySize = oldSize;
+ if (newSize < oldSize)
+ copySize = newSize;
+ memcpy(ret, ptr, copySize);
+ partitionFreeGeneric(ptr, oldSize);
+ return ret;
+#endif
+}
+
#ifndef NDEBUG
void partitionDumpStats(const PartitionRoot& root)
« no previous file with comments | « Source/wtf/PartitionAlloc.h ('k') | Source/wtf/PartitionAllocTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698