Title: [255586] trunk/Source/WebCore
- Revision
- 255586
- Author
- jer.no...@apple.com
- Date
- 2020-02-03 13:35:16 -0800 (Mon, 03 Feb 2020)
Log Message
Replace the custom allocator in AudioArray::allocate() with fastAlignedMalloc().
https://bugs.webkit.org/show_bug.cgi?id=206504
Reviewed by Filip Pizlo.
AudioArray wants to have its data aligned at 16-byte boundaries, as that's a requirement for
some of the accelerated math frameworks used by Web Audio. Now that we have fastAlignedMalloc(),
there's no need to use a custom aligned allocator.
Drive-by fixes: clean up the constructors a bit to use the modern initialization syntax.
* platform/audio/AudioArray.h:
(WebCore::AudioArray::AudioArray):
(WebCore::AudioArray::~AudioArray):
(WebCore::AudioArray::allocate):
(WebCore::AudioArray::data):
(WebCore::AudioArray::data const):
(WebCore::AudioArray::alignedAddress): Deleted.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (255585 => 255586)
--- trunk/Source/WebCore/ChangeLog 2020-02-03 21:33:06 UTC (rev 255585)
+++ trunk/Source/WebCore/ChangeLog 2020-02-03 21:35:16 UTC (rev 255586)
@@ -1,3 +1,24 @@
+2020-02-03 Jer Noble <jer.no...@apple.com>
+
+ Replace the custom allocator in AudioArray::allocate() with fastAlignedMalloc().
+ https://bugs.webkit.org/show_bug.cgi?id=206504
+
+ Reviewed by Filip Pizlo.
+
+ AudioArray wants to have its data aligned at 16-byte boundaries, as that's a requirement for
+ some of the accelerated math frameworks used by Web Audio. Now that we have fastAlignedMalloc(),
+ there's no need to use a custom aligned allocator.
+
+ Drive-by fixes: clean up the constructors a bit to use the modern initialization syntax.
+
+ * platform/audio/AudioArray.h:
+ (WebCore::AudioArray::AudioArray):
+ (WebCore::AudioArray::~AudioArray):
+ (WebCore::AudioArray::allocate):
+ (WebCore::AudioArray::data):
+ (WebCore::AudioArray::data const):
+ (WebCore::AudioArray::alignedAddress): Deleted.
+
2020-02-03 youenn fablet <you...@apple.com>
[ macOS wk2 ] http/tests/media/media-stream/get-display-media-prompt.html is flaky failure
Modified: trunk/Source/WebCore/platform/audio/AudioArray.h (255585 => 255586)
--- trunk/Source/WebCore/platform/audio/AudioArray.h 2020-02-03 21:33:06 UTC (rev 255585)
+++ trunk/Source/WebCore/platform/audio/AudioArray.h 2020-02-03 21:35:16 UTC (rev 255586)
@@ -39,8 +39,8 @@
class AudioArray {
WTF_MAKE_FAST_ALLOCATED;
public:
- AudioArray() : m_allocation(0), m_alignedData(0), m_size(0) { }
- explicit AudioArray(size_t n) : m_allocation(0), m_alignedData(0), m_size(0)
+ AudioArray() = default;
+ explicit AudioArray(size_t n)
{
allocate(n);
}
@@ -47,7 +47,7 @@
~AudioArray()
{
- fastFree(m_allocation);
+ fastAlignedFree(m_allocation);
}
// It's OK to call allocate() multiple times, but data will *not* be copied from an initial allocation
@@ -54,39 +54,20 @@
// if re-allocated. Allocations are zero-initialized.
void allocate(Checked<size_t> n)
{
- Checked<unsigned> initialSize = sizeof(T) * n;
+ Checked<size_t> initialSize = sizeof(T) * n;
const size_t alignment = 16;
- if (m_allocation)
- fastFree(m_allocation);
-
- bool isAllocationGood = false;
-
- while (!isAllocationGood) {
- // Initially we try to allocate the exact size, but if it's not aligned
- // then we'll have to reallocate and from then on allocate extra.
- static size_t extraAllocationBytes = 0;
+ fastAlignedFree(m_allocation);
- T* allocation = static_cast<T*>(fastMalloc((initialSize + extraAllocationBytes).unsafeGet()));
- if (!allocation)
- CRASH();
- T* alignedData = alignedAddress(allocation, alignment);
-
- if (alignedData == allocation || extraAllocationBytes == alignment) {
- m_allocation = allocation;
- m_alignedData = alignedData;
- m_size = n.unsafeGet();
- isAllocationGood = true;
- zero();
- } else {
- extraAllocationBytes = alignment; // always allocate extra after the first alignment failure.
- fastFree(allocation);
- }
- }
+ m_allocation = static_cast<T*>(fastAlignedMalloc(alignment, initialSize.unsafeGet()));
+ if (!m_allocation)
+ CRASH();
+ m_size = n.unsafeGet();
+ zero();
}
- T* data() { return m_alignedData; }
- const T* data() const { return m_alignedData; }
+ T* data() { return m_allocation; }
+ const T* data() const { return m_allocation; }
size_t size() const { return m_size; }
T& at(size_t i)
@@ -130,15 +111,8 @@
}
private:
- static T* alignedAddress(T* address, intptr_t alignment)
- {
- intptr_t value = reinterpret_cast<intptr_t>(address);
- return reinterpret_cast<T*>((value + alignment - 1) & ~(alignment - 1));
- }
-
- T* m_allocation;
- T* m_alignedData;
- size_t m_size;
+ T* m_allocation { nullptr };
+ size_t m_size { 0 };
};
typedef AudioArray<float> AudioFloatArray;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes