mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-07 22:58:10 -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:
@@ -55,7 +55,6 @@ struct DigitalSequence {
|
||||
|
||||
uint32_t size;
|
||||
uint32_t max_size;
|
||||
uint8_t* data;
|
||||
|
||||
LL_DMA_InitTypeDef dma_config_gpio;
|
||||
LL_DMA_InitTypeDef dma_config_timer;
|
||||
@@ -64,19 +63,19 @@ struct DigitalSequence {
|
||||
DigitalSequenceRingBuffer timer_buf;
|
||||
DigitalSequenceSignalBank signals;
|
||||
DigitalSequenceState state;
|
||||
|
||||
uint8_t data[];
|
||||
};
|
||||
|
||||
DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) {
|
||||
furi_assert(size);
|
||||
furi_assert(gpio);
|
||||
|
||||
DigitalSequence* sequence = malloc(sizeof(DigitalSequence));
|
||||
DigitalSequence* sequence = malloc(sizeof(DigitalSequence) + size);
|
||||
|
||||
sequence->gpio = gpio;
|
||||
sequence->max_size = size;
|
||||
|
||||
sequence->data = malloc(sequence->max_size);
|
||||
|
||||
sequence->dma_config_gpio.PeriphOrM2MSrcAddress = (uint32_t)&gpio->port->BSRR;
|
||||
sequence->dma_config_gpio.MemoryOrM2MDstAddress = (uint32_t)sequence->gpio_buf;
|
||||
sequence->dma_config_gpio.Direction = LL_DMA_DIRECTION_MEMORY_TO_PERIPH;
|
||||
@@ -107,7 +106,6 @@ DigitalSequence* digital_sequence_alloc(uint32_t size, const GpioPin* gpio) {
|
||||
void digital_sequence_free(DigitalSequence* sequence) {
|
||||
furi_assert(sequence);
|
||||
|
||||
free(sequence->data);
|
||||
free(sequence);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,9 @@
|
||||
#define TAG "DigitalSignal"
|
||||
|
||||
DigitalSignal* digital_signal_alloc(uint32_t max_size) {
|
||||
DigitalSignal* signal = malloc(sizeof(DigitalSignal));
|
||||
DigitalSignal* signal = malloc(sizeof(DigitalSignal) + (max_size * sizeof(uint32_t)));
|
||||
|
||||
signal->max_size = max_size;
|
||||
signal->data = malloc(max_size * sizeof(uint32_t));
|
||||
|
||||
return signal;
|
||||
}
|
||||
@@ -17,7 +16,6 @@ DigitalSignal* digital_signal_alloc(uint32_t max_size) {
|
||||
void digital_signal_free(DigitalSignal* signal) {
|
||||
furi_check(signal);
|
||||
|
||||
free(signal->data);
|
||||
free(signal);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,6 @@ struct DigitalSignal {
|
||||
bool start_level; /**< The level to begin the signal with. */
|
||||
uint32_t size; /**< Current period count contained in the instance. */
|
||||
uint32_t max_size; /**< Maximum period count this instance can hold. */
|
||||
uint32_t* data; /**< Pointer to the array of time periods. */
|
||||
int32_t remainder; /**< Remainder left after converting all periods into timer ticks. */
|
||||
uint32_t data[]; /**< The array of time periods. */
|
||||
};
|
||||
|
||||
@@ -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