mirror of
https://github.com/esphome/esphome.git
synced 2026-09-20 11:38:48 +00:00
[core] Specialize TemplatableValue for non-string types as function pointer
Specialize TemplatableValue so non-string types use function-pointer-only storage (4 bytes on 32-bit) instead of the tagged union with std::function support (8 bytes). The std::string specialization retains full support for VALUE, STATIC_STRING, FLASH_STRING, and stateful lambdas. Codegen now wraps non-string constants in stateless lambdas automatically, so the generated C++ always assigns a function pointer.
This commit is contained in:
@@ -669,11 +669,10 @@ async def test_templatable__int_with_std_string() -> None:
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_templatable__string_with_non_string_output_type() -> None:
|
||||
"""Static string with non-std::string output_type returns raw string."""
|
||||
"""Static string with non-std::string output_type returns stateless lambda."""
|
||||
result = await cg.templatable("hello", [], ct.bool_)
|
||||
|
||||
assert isinstance(result, str)
|
||||
assert result == "hello"
|
||||
assert isinstance(result, cg.LambdaExpression)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user