Commit 8b193107 authored by Max Kellermann's avatar Max Kellermann

output/httpd/Page: no variable size, use AllocatedArray

Using variable-size objects is not worth the trouble here. Let's drop this and use existing and simpler code.
parent 45e15b6c
...@@ -19,9 +19,6 @@ ...@@ -19,9 +19,6 @@
#include "config.h" #include "config.h"
#include "Page.hxx" #include "Page.hxx"
#include "util/Alloc.hxx"
#include <new>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
...@@ -30,9 +27,7 @@ ...@@ -30,9 +27,7 @@
Page * Page *
Page::Create(size_t size) Page::Create(size_t size)
{ {
void *p = xalloc(sizeof(Page) + size - return new Page(size);
sizeof(Page::data));
return ::new(p) Page(size);
} }
Page * Page *
...@@ -41,7 +36,7 @@ Page::Copy(const void *data, size_t size) ...@@ -41,7 +36,7 @@ Page::Copy(const void *data, size_t size)
assert(data != nullptr); assert(data != nullptr);
Page *page = Create(size); Page *page = Create(size);
memcpy(page->data, data, size); memcpy(&page->buffer.front(), data, size);
return page; return page;
} }
...@@ -50,10 +45,8 @@ Page::Unref() ...@@ -50,10 +45,8 @@ Page::Unref()
{ {
bool unused = ref.Decrement(); bool unused = ref.Decrement();
if (unused) { if (unused)
this->Page::~Page(); delete this;
free(this);
}
return unused; return unused;
} }
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#define MPD_PAGE_HXX #define MPD_PAGE_HXX
#include "util/RefCount.hxx" #include "util/RefCount.hxx"
#include "util/AllocatedArray.hxx"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
...@@ -44,18 +45,13 @@ class Page { ...@@ -44,18 +45,13 @@ class Page {
*/ */
RefCount ref; RefCount ref;
/** AllocatedArray<uint8_t> buffer;
* The size of this buffer in bytes.
*/
const size_t size;
/**
* Dynamic array containing the buffer data.
*/
uint8_t data[sizeof(long)];
protected: protected:
Page(size_t _size):size(_size) {} explicit Page(size_t _size):buffer(_size) {}
explicit Page(AllocatedArray<uint8_t> &&_buffer)
:buffer(std::move(_buffer)) {}
~Page() = default; ~Page() = default;
/** /**
...@@ -91,11 +87,11 @@ public: ...@@ -91,11 +87,11 @@ public:
bool Unref(); bool Unref();
size_t GetSize() const { size_t GetSize() const {
return size; return buffer.size();
} }
const uint8_t *GetData() const { const uint8_t *GetData() const {
return data; return &buffer.front();
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment