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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/wtf/PartitionAllocTest.cpp » ('j') | Source/wtf/PartitionAllocTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) 768 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
769 return realloc(ptr, newSize); 769 return realloc(ptr, newSize);
770 #else 770 #else
771 if (UNLIKELY(!ptr)) 771 if (UNLIKELY(!ptr))
772 return partitionAllocGeneric(root, newSize); 772 return partitionAllocGeneric(root, newSize);
773 if (UNLIKELY(!newSize)) { 773 if (UNLIKELY(!newSize)) {
774 partitionFreeGeneric(root, ptr); 774 partitionFreeGeneric(root, ptr);
775 return 0; 775 return 0;
776 } 776 }
777 777
778 ASSERT(partitionPointerIsValid(partitionCookieFreePointerAdjust(ptr)));
779
780 size_t actualNewSize = partitionAllocActualSize(root, newSize);
781 size_t actualOldSize = partitionAllocGetSize(ptr);
782
778 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the 783 // TODO: note that tcmalloc will "ignore" a downsizing realloc() unless the
779 // new size is a significant percentage smaller. We could do the same if we 784 // new size is a significant percentage smaller. We could do the same if we
780 // determine it is a win. 785 // determine it is a win.
781 void* realPtr = partitionCookieFreePointerAdjust(ptr); 786 if (actualNewSize == actualOldSize) {
782 ASSERT(partitionPointerIsValid(realPtr)); 787 // Trying to allocate a block of size newSize would give us a block of
783 PartitionPage* oldPage = partitionPointerToPage(realPtr); 788 // the same size as the one we've already got, so no point in doing
784 PartitionBucket* oldBucket = oldPage->bucket; 789 // anything here.
785 790 // TODO: for an upsize or downsize on a direct mapped allocation, we
786 size_t allocSize = partitionCookieSizeAdjustAdd(newSize); 791 // should really try and resize it in-place.
787 PartitionBucket* newBucket = partitionGenericSizeToBucket(root, allocSize);
788
789 // TODO: for a downsize on a direct mapped allocation, we really should
790 // just de-commit the correct number of pages off the end.
791 if (oldBucket == newBucket)
792 return ptr; 792 return ptr;
793 }
793 794
794 // This realloc cannot be resized in-place. Sadness. 795 // This realloc cannot be resized in-place. Sadness.
795 void* ret = partitionAllocGeneric(root, newSize); 796 void* ret = partitionAllocGeneric(root, newSize);
796 size_t copySize = oldPage->bucket->slotSize; 797 size_t copySize = actualOldSize;
797 copySize = partitionCookieSizeAdjustSubtract(copySize);
798 if (newSize < copySize) 798 if (newSize < copySize)
799 copySize = newSize; 799 copySize = newSize;
800 800
801 memcpy(ret, ptr, copySize); 801 memcpy(ret, ptr, copySize);
802 partitionFreeGeneric(root, ptr); 802 partitionFreeGeneric(root, ptr);
803 return ret; 803 return ret;
804 #endif 804 #endif
805 } 805 }
806 806
807 #ifndef NDEBUG 807 #ifndef NDEBUG
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 printf("total live: %zu bytes\n", totalLive); 855 printf("total live: %zu bytes\n", totalLive);
856 printf("total resident: %zu bytes\n", totalResident); 856 printf("total resident: %zu bytes\n", totalResident);
857 printf("total freeable: %zu bytes\n", totalFreeable); 857 printf("total freeable: %zu bytes\n", totalFreeable);
858 fflush(stdout); 858 fflush(stdout);
859 } 859 }
860 860
861 #endif // !NDEBUG 861 #endif // !NDEBUG
862 862
863 } // namespace WTF 863 } // namespace WTF
864 864
OLDNEW
« 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