mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-13 23:58:11 -07:00
Coalesce some allocations (#3747)
* View: Coalesce view model allocations * SceneManager: Coalesce AppScene allocations * BufferStream: Coalesce Buffer allocations * ProtocolDict: Coalesce dict allocations * DigitalSignal: Coalesce buffer allocations Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -12,8 +12,8 @@ struct BufferStream {
|
||||
FuriStreamBuffer* stream;
|
||||
|
||||
size_t index;
|
||||
Buffer* buffers;
|
||||
size_t max_buffers_count;
|
||||
Buffer buffers[];
|
||||
};
|
||||
|
||||
bool buffer_write(Buffer* buffer, const uint8_t* data, size_t size) {
|
||||
@@ -44,9 +44,8 @@ void buffer_reset(Buffer* buffer) {
|
||||
BufferStream* buffer_stream_alloc(size_t buffer_size, size_t buffers_count) {
|
||||
furi_assert(buffer_size > 0);
|
||||
furi_assert(buffers_count > 0);
|
||||
BufferStream* buffer_stream = malloc(sizeof(BufferStream));
|
||||
BufferStream* buffer_stream = malloc(sizeof(BufferStream) + (sizeof(Buffer) * buffers_count));
|
||||
buffer_stream->max_buffers_count = buffers_count;
|
||||
buffer_stream->buffers = malloc(sizeof(Buffer) * buffer_stream->max_buffers_count);
|
||||
for(size_t i = 0; i < buffer_stream->max_buffers_count; i++) {
|
||||
buffer_stream->buffers[i].occupied = false;
|
||||
buffer_stream->buffers[i].size = 0;
|
||||
@@ -66,7 +65,6 @@ void buffer_stream_free(BufferStream* buffer_stream) {
|
||||
free(buffer_stream->buffers[i].data);
|
||||
}
|
||||
furi_stream_buffer_free(buffer_stream->stream);
|
||||
free(buffer_stream->buffers);
|
||||
free(buffer_stream);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,16 +4,15 @@
|
||||
struct ProtocolDict {
|
||||
const ProtocolBase** base;
|
||||
size_t count;
|
||||
void** data;
|
||||
void* data[];
|
||||
};
|
||||
|
||||
ProtocolDict* protocol_dict_alloc(const ProtocolBase** protocols, size_t count) {
|
||||
furi_check(protocols);
|
||||
|
||||
ProtocolDict* dict = malloc(sizeof(ProtocolDict));
|
||||
ProtocolDict* dict = malloc(sizeof(ProtocolDict) + (sizeof(void*) * count));
|
||||
dict->base = protocols;
|
||||
dict->count = count;
|
||||
dict->data = malloc(sizeof(void*) * dict->count);
|
||||
|
||||
for(size_t i = 0; i < dict->count; i++) {
|
||||
dict->data[i] = dict->base[i]->alloc();
|
||||
@@ -29,7 +28,6 @@ void protocol_dict_free(ProtocolDict* dict) {
|
||||
dict->base[i]->free(dict->data[i]);
|
||||
}
|
||||
|
||||
free(dict->data);
|
||||
free(dict);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user