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.
This commit is contained in:
parent
45e15b6cc6
commit
8b1931072a
|
@ -19,9 +19,6 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "Page.hxx"
|
||||
#include "util/Alloc.hxx"
|
||||
|
||||
#include <new>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
@ -30,9 +27,7 @@
|
|||
Page *
|
||||
Page::Create(size_t size)
|
||||
{
|
||||
void *p = xalloc(sizeof(Page) + size -
|
||||
sizeof(Page::data));
|
||||
return ::new(p) Page(size);
|
||||
return new Page(size);
|
||||
}
|
||||
|
||||
Page *
|
||||
|
@ -41,7 +36,7 @@ Page::Copy(const void *data, size_t size)
|
|||
assert(data != nullptr);
|
||||
|
||||
Page *page = Create(size);
|
||||
memcpy(page->data, data, size);
|
||||
memcpy(&page->buffer.front(), data, size);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
@ -50,10 +45,8 @@ Page::Unref()
|
|||
{
|
||||
bool unused = ref.Decrement();
|
||||
|
||||
if (unused) {
|
||||
this->Page::~Page();
|
||||
free(this);
|
||||
}
|
||||
if (unused)
|
||||
delete this;
|
||||
|
||||
return unused;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#define MPD_PAGE_HXX
|
||||
|
||||
#include "util/RefCount.hxx"
|
||||
#include "util/AllocatedArray.hxx"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
@ -44,18 +45,13 @@ class Page {
|
|||
*/
|
||||
RefCount ref;
|
||||
|
||||
/**
|
||||
* The size of this buffer in bytes.
|
||||
*/
|
||||
const size_t size;
|
||||
|
||||
/**
|
||||
* Dynamic array containing the buffer data.
|
||||
*/
|
||||
uint8_t data[sizeof(long)];
|
||||
AllocatedArray<uint8_t> buffer;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -91,11 +87,11 @@ public:
|
|||
bool Unref();
|
||||
|
||||
size_t GetSize() const {
|
||||
return size;
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
const uint8_t *GetData() const {
|
||||
return data;
|
||||
return &buffer.front();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue