Change WritableBuffer<uint8_t> to AllocatedArray<std::byte>
This commit is contained in:
parent
a134f692bf
commit
34f636ffc3
@ -23,16 +23,16 @@
|
|||||||
static constexpr size_t MOD_PREALLOC_BLOCK = 256 * 1024;
|
static constexpr size_t MOD_PREALLOC_BLOCK = 256 * 1024;
|
||||||
static constexpr offset_type MOD_FILE_LIMIT = 100 * 1024 * 1024;
|
static constexpr offset_type MOD_FILE_LIMIT = 100 * 1024 * 1024;
|
||||||
|
|
||||||
WritableBuffer<uint8_t>
|
AllocatedArray<std::byte>
|
||||||
mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is)
|
mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is)
|
||||||
{
|
{
|
||||||
//known/unknown size, preallocate array, lets read in chunks
|
//known/unknown size, preallocate array, lets read in chunks
|
||||||
|
|
||||||
const bool is_stream = !is.KnownSize();
|
const bool is_stream = !is.KnownSize();
|
||||||
|
size_t buffer_size;
|
||||||
|
|
||||||
WritableBuffer<uint8_t> buffer;
|
|
||||||
if (is_stream)
|
if (is_stream)
|
||||||
buffer.size = MOD_PREALLOC_BLOCK;
|
buffer_size = MOD_PREALLOC_BLOCK;
|
||||||
else {
|
else {
|
||||||
const auto size = is.GetSize();
|
const auto size = is.GetSize();
|
||||||
|
|
||||||
@ -46,13 +46,13 @@ mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.size = size;
|
buffer_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.data = new uint8_t[buffer.size];
|
auto buffer = AllocatedArray<std::byte>(buffer_size);
|
||||||
|
|
||||||
uint8_t *const end = buffer.end();
|
std::byte *const end = buffer.end();
|
||||||
uint8_t *p = buffer.begin();
|
std::byte *p = buffer.begin();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
size_t ret = decoder_read(client, is, p, end - p);
|
size_t ret = decoder_read(client, is, p, end - p);
|
||||||
@ -62,8 +62,6 @@ mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* I/O error - skip this song */
|
/* I/O error - skip this song */
|
||||||
delete[] buffer.data;
|
|
||||||
buffer.data = nullptr;
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,13 +71,11 @@ mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
LogWarning(*domain, "stream too large");
|
LogWarning(*domain, "stream too large");
|
||||||
delete[] buffer.data;
|
|
||||||
buffer.data = nullptr;
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.size = p - buffer.data;
|
buffer.SetSize(p - buffer.data());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
#include "../DecoderAPI.hxx"
|
#include "../DecoderAPI.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "util/WritableBuffer.hxx"
|
#include "util/AllocatedArray.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
|
|
||||||
WritableBuffer<uint8_t> mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is);
|
AllocatedArray<std::byte> mod_loadfile(const Domain *domain, DecoderClient *client, InputStream &is);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "../DecoderAPI.hxx"
|
#include "../DecoderAPI.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "tag/Handler.hxx"
|
#include "tag/Handler.hxx"
|
||||||
#include "util/WritableBuffer.hxx"
|
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/RuntimeError.hxx"
|
#include "util/RuntimeError.hxx"
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringView.hxx"
|
||||||
@ -79,8 +78,7 @@ LoadModPlugFile(DecoderClient *client, InputStream &is)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModPlugFile *f = ModPlug_Load(buffer.data, buffer.size);
|
ModPlugFile *f = ModPlug_Load(buffer.data(), buffer.size());
|
||||||
delete[] buffer.data;
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user