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

Unified Diff: Source/wtf/PartitionAlloc.cpp

Issue 180293003: Simplify partitionReallocGeneric() implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: restore TODOs + extended test Created 6 years, 10 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 | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | Source/wtf/PartitionAllocTest.cpp » ('J')
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 9a18bd4ab0fdce43efa1bc6563fe59f1dc8c3fbd..e62a9a66235e23719cd2c5eb30ae29ed76cfdc52 100644
--- a/Source/wtf/PartitionAlloc.cpp
+++ b/Source/wtf/PartitionAlloc.cpp
@@ -775,26 +775,26 @@ void* partitionReallocGeneric(PartitionRootGeneric* root, void* ptr, size_t newS
return 0;
}
+ ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr)));
+
+ size_t actualNewSize = partitionAllocActualSize(root, newSize);
+ size_t actualOldSize = partitionAllocGetSize(ptr);
+
// TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the
// new size is a significant percentage smaller. We could do the same if we
// determine it is a win.
- void* realPtr = partitionCookieFreePointerAdjust(ptr);
- ASSERT(partitionPointerIsValid(realPtr));
- PartitionPage* oldPage = partitionPointerToPage(realPtr);
- PartitionBucket* oldBucket = oldPage->bucket;
-
- size_t allocSize = partitionCookieSizeAdjustAdd(newSize);
- PartitionBucket* newBucket = partitionGenericSizeToBucket(root, allocSize);
-
- // TODO: for a downsize on a direct mapped allocation, we really should
- // just de-commit the correct number of pages off the end.
- if (oldBucket == newBucket)
+ if (actualNewSize == actualOldSize) {
+ // Trying to allocate a block of size newSize would give us a block of
+ // the same size as the one we've already got, so no point in doing
+ // anything here.
+ // TODO: for an upsize or downsize on a direct mapped allocation, we
+ // should really try and resize it in-place.
return ptr;
+ }
// This realloc cannot be resized in-place. Sadness.
void* ret = partitionAllocGeneric(root, newSize);
- size_t copySize = oldPage->bucket->slotSize;
- copySize = partitionCookieSizeAdjustSubtract(copySize);
+ size_t copySize = actualOldSize;
if (newSize < copySize)
copySize = newSize;
« no previous file with comments | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | Source/wtf/PartitionAllocTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698