[log] Skip esp_log_vprintf_ indirection on non-flash platforms

On platforms without USE_STORE_LOG_STR_IN_FLASH (ESP32, RP2040,
LibreTiny), there is only one esp_log_printf_ overload, so the
separate esp_log_vprintf_ function just adds an unnecessary call
frame. Inline the logger dispatch directly into esp_log_printf_
for these platforms.

The const char* esp_log_vprintf_ is still provided unconditionally
for direct callers (e.g. midea component).

On ESP8266 (USE_STORE_LOG_STR_IN_FLASH), the two esp_log_printf_
overloads continue to share esp_log_vprintf_ as before.

Measured: 32 bytes flash saved on ESP32, no change on ESP8266.
This commit is contained in:
J. Nick Koston
2026-03-05 21:22:14 -10:00
parent a2c0d70c2c
commit a4919f2504
2 changed files with 15 additions and 18 deletions
+15 -15
View File
@@ -8,18 +8,31 @@
namespace esphome {
// Call log_vprintf_ directly to avoid extra indirection through esp_log_vprintf_
void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return;
va_list arg;
va_start(arg, format);
esp_log_vprintf_(level, tag, line, format, arg);
log->log_vprintf_(static_cast<uint8_t>(level), tag, line, format, arg);
va_end(arg);
#endif
}
#ifdef USE_STORE_LOG_STR_IN_FLASH
void HOT esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...) {
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return;
va_list arg;
va_start(arg, format);
esp_log_vprintf_(level, tag, line, format, arg);
log->log_vprintf_(static_cast<uint8_t>(level), tag, line, format, arg);
va_end(arg);
#endif
}
#endif
@@ -33,19 +46,6 @@ void HOT esp_log_vprintf_(int level, const char *tag, int line, const char *form
#endif
}
#ifdef USE_STORE_LOG_STR_IN_FLASH
void HOT esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format,
va_list args) { // NOLINT
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return;
log->log_vprintf_(static_cast<uint8_t>(level), tag, line, format, args);
#endif
}
#endif
#ifdef USE_ESP32
int HOT esp_idf_log_vprintf_(const char *format, va_list args) { // NOLINT
#ifdef USE_LOGGER
-3
View File
@@ -60,9 +60,6 @@ void esp_log_printf_(int level, const char *tag, int line, const char *format, .
void esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...);
#endif
void esp_log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT
#ifdef USE_STORE_LOG_STR_IN_FLASH
void esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format, va_list args);
#endif
#if defined(USE_ESP32)
int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#endif