1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-03 18:42:23 +01:00

[logger] Optimize log formatting performance (33-67% faster)

This commit is contained in:
J. Nick Koston
2025-10-01 01:36:35 +02:00
parent 502cd2b54d
commit 9bffa2faa6

View File

@@ -315,13 +315,11 @@ class Logger : public Component {
} }
#endif #endif
// Helper: copy fixed-length data to buffer and advance position
static inline void copy_and_advance(char *buffer, uint16_t &pos, const char *data, uint8_t len) { static inline void copy_and_advance(char *buffer, uint16_t &pos, const char *data, uint8_t len) {
memcpy(buffer + pos, data, len); memcpy(buffer + pos, data, len);
pos += len; pos += len;
} }
// Helper: copy string to buffer and advance position (calculates length with strlen)
static inline void copy_string(char *buffer, uint16_t &pos, const char *str) { static inline void copy_string(char *buffer, uint16_t &pos, const char *str) {
copy_and_advance(buffer, pos, str, strlen(str)); copy_and_advance(buffer, pos, str, strlen(str));
} }