mirror of
https://github.com/esphome/esphome.git
synced 2026-09-17 18:18:43 +00:00
[logger] Inline ANSI reset sequence in LogBuffer::finalize_()
Replace write_() call with direct char stores for the 4-byte
ANSI reset sequence ("\033[0m"). This eliminates function call
overhead (entry/retw, bounds check, memcpy setup) on every log
message and avoids a rodata string reference that consumes RAM
on ESP8266.
This commit is contained in:
@@ -128,12 +128,21 @@ struct LogBuffer {
|
||||
}
|
||||
}
|
||||
void finalize_() {
|
||||
// Write color reset sequence
|
||||
static constexpr uint16_t RESET_COLOR_LEN = sizeof(ESPHOME_LOG_RESET_COLOR) - 1;
|
||||
this->write_(ESPHOME_LOG_RESET_COLOR, RESET_COLOR_LEN);
|
||||
this->write_ansi_reset_();
|
||||
// Null terminate
|
||||
this->data[this->full_() ? this->size - 1 : this->pos] = '\0';
|
||||
}
|
||||
// Write ANSI reset sequence inline (4 bytes: "\033[0m") - avoids write_() call overhead
|
||||
void write_ansi_reset_() {
|
||||
if (this->remaining_() >= 4) {
|
||||
char *p = this->current_();
|
||||
*p++ = '\033';
|
||||
*p++ = '[';
|
||||
*p++ = '0';
|
||||
*p++ = 'm';
|
||||
this->pos += 4;
|
||||
}
|
||||
}
|
||||
void strip_trailing_newlines_() {
|
||||
while (this->pos > 0 && this->data[this->pos - 1] == '\n')
|
||||
this->pos--;
|
||||
|
||||
Reference in New Issue
Block a user