[ai] Memory Optimizations

This commit is contained in:
2026-01-13 21:54:51 +01:00
parent 6ecb54e5ee
commit 7512e1d94b
3 changed files with 15 additions and 63 deletions

View File

@@ -405,11 +405,11 @@ DirectoryNode *DirectoryNode::advanceToMP3(const String &songName)
}
else
{
// Use static buffer for case conversion and comparison
// Use static buffer for comparison without allocation
buildFullPath(mp3Files[i], buffer, buffer_size);
String f = String(buffer);
f.toLowerCase();
if (f.endsWith(lowTarget))
size_t bufLen = strlen(buffer);
size_t targetLen = lowTarget.length();
if (bufLen >= targetLen && strcasecmp(buffer + bufLen - targetLen, lowTarget.c_str()) == 0)
{
setCurrentPlaying(mp3Files[i]);
return this;
@@ -450,9 +450,11 @@ DirectoryNode *DirectoryNode::advanceToMP3(const String &songName)
}
else
{
String f = subdir->mp3Files[i];
f.toLowerCase();
if (f.endsWith(lowTarget))
// Check suffix case-insensitively without creating new Strings
const String& fName = subdir->mp3Files[i];
size_t fLen = fName.length();
size_t targetLen = lowTarget.length();
if (fLen >= targetLen && strcasecmp(fName.c_str() + fLen - targetLen, lowTarget.c_str()) == 0)
{
subdir->setCurrentPlaying(subdir->mp3Files[i]);
return subdir;