mirror of
https://github.com/esphome/esphome.git
synced 2026-08-31 18:16:03 +00:00
[api] Make ProtoDecodableMessage::decode() non-virtual
decode() is never called polymorphically - all call sites in read_message_() use concrete types. The only indirect call site was decode_to_message(), which also always knows the concrete type. Convert decode_to_message() to a template so the concrete type is preserved, allowing decode() to be non-virtual. The two classes that override decode() (ExecuteServiceArgument, ExecuteServiceRequest) now hide the base method, which works since all calls use concrete types. This removes one vtable slot (4 bytes) from each decodable message class vtable, saving ~148 bytes of flash.
This commit is contained in:
@@ -2262,7 +2262,7 @@ def build_message_type(
|
||||
o += "}\n"
|
||||
cpp += o
|
||||
# Generate the decode() declaration in header (public method)
|
||||
prot = "void decode(const uint8_t *buffer, size_t length) override;"
|
||||
prot = "void decode(const uint8_t *buffer, size_t length);"
|
||||
public_content.append(prot)
|
||||
|
||||
# Only generate encode method if this message needs encoding and has fields
|
||||
|
||||
Reference in New Issue
Block a user