mirror of
https://github.com/esphome/esphome.git
synced 2026-09-04 03:56:04 +00:00
[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:
+15
-15
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user