mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 08:41:59 +00:00
reduce
This commit is contained in:
@@ -19,7 +19,6 @@ from esphome.cpp_generator import ( # noqa: F401
|
||||
RawExpression,
|
||||
RawStatement,
|
||||
Statement,
|
||||
StringRefLiteral,
|
||||
StructInitializer,
|
||||
TemplateArguments,
|
||||
add,
|
||||
|
||||
@@ -243,23 +243,6 @@ class LogStringLiteral(Literal):
|
||||
return f"LOG_STR({cpp_string_escape(self.string)})"
|
||||
|
||||
|
||||
class StringRefLiteral(Literal):
|
||||
"""A StringRef literal using from_lit() for compile-time string references.
|
||||
|
||||
Uses StringRef::from_lit() which stores pointer + length (8 bytes) instead of
|
||||
std::string (24-32 bytes + heap allocation). The string data stays in flash.
|
||||
"""
|
||||
|
||||
__slots__ = ("string",)
|
||||
|
||||
def __init__(self, string: str) -> None:
|
||||
super().__init__()
|
||||
self.string = string
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"StringRef::from_lit({cpp_string_escape(self.string)})"
|
||||
|
||||
|
||||
class IntLiteral(Literal):
|
||||
__slots__ = ("i",)
|
||||
|
||||
|
||||
@@ -248,12 +248,6 @@ class TestLiterals:
|
||||
(cg.FloatLiteral(4.2), "4.2f"),
|
||||
(cg.FloatLiteral(1.23456789), "1.23456789f"),
|
||||
(cg.FloatLiteral(math.nan), "NAN"),
|
||||
(cg.StringRefLiteral("foo"), 'StringRef::from_lit("foo")'),
|
||||
(cg.StringRefLiteral(""), 'StringRef::from_lit("")'),
|
||||
(
|
||||
cg.StringRefLiteral('with "quotes"'),
|
||||
'StringRef::from_lit("with \\042quotes\\042")',
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_str__simple(self, target: cg.Literal, expected: str):
|
||||
|
||||
Reference in New Issue
Block a user