Projectkk2glider/flash savings (#4199)
* Flash savings: getFileExtension() de-templated, saves 160 bytes * Flash savings: several variables moved to rodata, RGB macro optimization (speed and can now be used to initialize rodata) Result for Horus: text data bss dec 1261182 808603 42020 2111805 before 1267149 803335 42124 2112608 after (data size also counts .sram section) 5kB saved in .data section (RAM and FLASH) * Removed compiler warnings * RGB() and ARGB() gtests added * ARGB() optimized
This commit is contained in:
committed by
Bertrand Songis
parent
3b58ee8d3c
commit
82dce3ee60
+29
-3
@@ -114,7 +114,7 @@ bool isFilePatternAvailable(const char * path, const char * file, const char * p
|
||||
char * getFileIndex(char * filename, unsigned int & value)
|
||||
{
|
||||
value = 0;
|
||||
char * pos = getFileExtension(filename);
|
||||
char * pos = (char *)getFileExtension(filename);
|
||||
if (!pos || pos == filename)
|
||||
return NULL;
|
||||
int multiplier = 1;
|
||||
@@ -148,7 +148,7 @@ int findNextFileIndex(char * filename, uint8_t size, const char * directory)
|
||||
uint8_t extlen;
|
||||
char * indexPos = getFileIndex(filename, index);
|
||||
char extension[LEN_FILE_EXTENSION_MAX+1] = "\0";
|
||||
char *p = getFileExtension(filename, 0, 0, NULL, &extlen);
|
||||
char * p = (char *)getFileExtension(filename, 0, 0, NULL, &extlen);
|
||||
if (p) strncat(extension, p, sizeof(extension)-1);
|
||||
while (1) {
|
||||
index++;
|
||||
@@ -163,6 +163,32 @@ int findNextFileIndex(char * filename, uint8_t size, const char * directory)
|
||||
}
|
||||
}
|
||||
|
||||
const char * getFileExtension(const char * filename, uint8_t size, uint8_t extMaxLen, uint8_t *fnlen, uint8_t *extlen)
|
||||
{
|
||||
int len = size;
|
||||
if (!size) {
|
||||
len = strlen(filename);
|
||||
}
|
||||
if (!extMaxLen) {
|
||||
extMaxLen = LEN_FILE_EXTENSION_MAX;
|
||||
}
|
||||
if (fnlen != NULL) {
|
||||
*fnlen = (uint8_t)len;
|
||||
}
|
||||
for (int i=len-1; i >= 0 && len-i <= extMaxLen; --i) {
|
||||
if (filename[i] == '.') {
|
||||
if (extlen) {
|
||||
*extlen = len-i;
|
||||
}
|
||||
return &filename[i];
|
||||
}
|
||||
}
|
||||
if (extlen != NULL) {
|
||||
*extlen = 0;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
Check if given extension exists in a list of extensions.
|
||||
@param extension The extension to search for, including leading period.
|
||||
@@ -198,7 +224,7 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
||||
static uint16_t lastpopupMenuOffset = 0;
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
char *fnExt;
|
||||
const char * fnExt;
|
||||
uint8_t fnLen, extLen;
|
||||
char tmpExt[LEN_FILE_EXTENSION_MAX+1] = "\0";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user