mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	tweak
This commit is contained in:
		| @@ -114,7 +114,7 @@ class LambdaFilter : public Filter { | ||||
| /** Optimized lambda filter for stateless lambdas (no capture). | ||||
|  * | ||||
|  * Uses function pointer instead of std::function to reduce memory overhead. | ||||
|  * Memory: 8 bytes (function pointer) vs 32 bytes (std::function). | ||||
|  * Memory: 4 bytes (function pointer on 32-bit) vs 32 bytes (std::function). | ||||
|  */ | ||||
| class StatelessLambdaFilter : public Filter { | ||||
|  public: | ||||
|   | ||||
| @@ -299,7 +299,7 @@ class LambdaFilter : public Filter { | ||||
| /** Optimized lambda filter for stateless lambdas (no capture). | ||||
|  * | ||||
|  * Uses function pointer instead of std::function to reduce memory overhead. | ||||
|  * Memory: 8 bytes (function pointer) vs 32 bytes (std::function). | ||||
|  * Memory: 4 bytes (function pointer on 32-bit) vs 32 bytes (std::function). | ||||
|  */ | ||||
| class StatelessLambdaFilter : public Filter { | ||||
|  public: | ||||
|   | ||||
| @@ -65,7 +65,7 @@ class LambdaFilter : public Filter { | ||||
| /** Optimized lambda filter for stateless lambdas (no capture). | ||||
|  * | ||||
|  * Uses function pointer instead of std::function to reduce memory overhead. | ||||
|  * Memory: 8 bytes (function pointer) vs 32 bytes (std::function). | ||||
|  * Memory: 4 bytes (function pointer on 32-bit) vs 32 bytes (std::function). | ||||
|  */ | ||||
| class StatelessLambdaFilter : public Filter { | ||||
|  public: | ||||
|   | ||||
| @@ -81,7 +81,7 @@ template<typename... Ts> class LambdaCondition : public Condition<Ts...> { | ||||
|  | ||||
| /// Optimized lambda condition for stateless lambdas (no capture). | ||||
| /// Uses function pointer instead of std::function to reduce memory overhead. | ||||
| /// Memory: 8 bytes (function pointer) vs 32 bytes (std::function). | ||||
| /// Memory: 4 bytes (function pointer on 32-bit) vs 32 bytes (std::function). | ||||
| template<typename... Ts> class StatelessLambdaCondition : public Condition<Ts...> { | ||||
|  public: | ||||
|   explicit StatelessLambdaCondition(bool (*f)(Ts...)) : f_(f) {} | ||||
| @@ -204,7 +204,7 @@ template<typename... Ts> class LambdaAction : public Action<Ts...> { | ||||
|  | ||||
| /// Optimized lambda action for stateless lambdas (no capture). | ||||
| /// Uses function pointer instead of std::function to reduce memory overhead. | ||||
| /// Memory: 8 bytes (function pointer) vs 32 bytes (std::function). | ||||
| /// Memory: 4 bytes (function pointer on 32-bit) vs 32 bytes (std::function). | ||||
| template<typename... Ts> class StatelessLambdaAction : public Action<Ts...> { | ||||
|  public: | ||||
|   explicit StatelessLambdaAction(void (*f)(Ts...)) : f_(f) {} | ||||
|   | ||||
| @@ -213,6 +213,23 @@ class TestLambdaExpression: | ||||
|             "+[](int32_t foo, float bar) -> float {\n  return foo + bar;\n}" | ||||
|         ) | ||||
|  | ||||
|     def test_str__with_capture_no_prefix(self): | ||||
|         """Test lambda with capture (not stateless) does NOT get + prefix""" | ||||
|         target = cg.LambdaExpression( | ||||
|             ("return captured_var + x;",), | ||||
|             ((int, "x"),), | ||||
|             "captured_var",  # Has capture (not stateless) | ||||
|             int, | ||||
|         ) | ||||
|  | ||||
|         actual = str(target) | ||||
|  | ||||
|         # Should NOT have + prefix | ||||
|         assert actual == ( | ||||
|             "[captured_var](int32_t x) -> int32_t {\n  return captured_var + x;\n}" | ||||
|         ) | ||||
|         assert not actual.startswith("+") | ||||
|  | ||||
|  | ||||
| class TestLiterals: | ||||
|     @pytest.mark.parametrize( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user