mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-14 09:25:30 -04:00
Faster app_settings save (#1145)
* No-allocation settings save * remove fixed TODO --------- Co-authored-by: kallanreed <kallanreed@outlook.com>
This commit is contained in:
parent
8bd3d6249d
commit
fff78ce00f
3 changed files with 30 additions and 2 deletions
|
@ -21,6 +21,10 @@
|
|||
|
||||
#include "string_format.hpp"
|
||||
|
||||
/* This takes a pointer to the end of a buffer
|
||||
* and fills it backwards towards the front.
|
||||
* The return value 'q' is a pointer to the start.
|
||||
* TODO: use std::array for all this. */
|
||||
static char* to_string_dec_uint_internal(
|
||||
char* p,
|
||||
uint32_t n) {
|
||||
|
@ -44,6 +48,9 @@ static char* to_string_dec_uint_pad_internal(
|
|||
const char fill) {
|
||||
auto q = to_string_dec_uint_internal(term, n);
|
||||
|
||||
// Fill with padding if needed.
|
||||
// TODO: use std::array instead. There's no
|
||||
// bounds checks on any of this!
|
||||
if (fill) {
|
||||
while ((term - q) < l) {
|
||||
*(--q) = fill;
|
||||
|
@ -53,6 +60,13 @@ static char* to_string_dec_uint_pad_internal(
|
|||
return q;
|
||||
}
|
||||
|
||||
char* to_string_dec_uint(const uint32_t n, StringFormatBuffer& buffer, size_t& length) {
|
||||
auto end = &buffer.back();
|
||||
auto start = to_string_dec_uint_internal(end, n);
|
||||
length = end - start;
|
||||
return start;
|
||||
}
|
||||
|
||||
std::string to_string_bin(
|
||||
const uint32_t n,
|
||||
const uint8_t l) {
|
||||
|
@ -75,6 +89,7 @@ std::string to_string_dec_uint(
|
|||
auto term = p + sizeof(p) - 1;
|
||||
auto q = to_string_dec_uint_pad_internal(term, n, l, fill);
|
||||
|
||||
// TODO: is this needed, seems like pad already does this.
|
||||
// Right justify.
|
||||
while ((term - q) < l) {
|
||||
*(--q) = ' ';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue