mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	[core] Optimize automation actions memory usage with std::initializer_list
This commit is contained in:
		| @@ -14,13 +14,13 @@ template<typename... Ts> class SendAction : public Action<Ts...>, public Parente | ||||
|   TEMPLATABLE_VALUE(std::vector<uint8_t>, data); | ||||
|  | ||||
|  public: | ||||
|   void add_on_sent(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_on_sent(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     this->sent_.add_actions(actions); | ||||
|     if (this->flags_.wait_for_sent) { | ||||
|       this->sent_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next_(x...); })); | ||||
|     } | ||||
|   } | ||||
|   void add_on_error(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_on_error(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     this->error_.add_actions(actions); | ||||
|     if (this->flags_.wait_for_sent) { | ||||
|       this->error_.add_action(new LambdaAction<Ts...>([this](Ts... x) { | ||||
|   | ||||
| @@ -243,7 +243,7 @@ template<typename... Ts> class ActionList { | ||||
|     } | ||||
|     this->actions_end_ = action; | ||||
|   } | ||||
|   void add_actions(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_actions(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     for (auto *action : actions) { | ||||
|       this->add_action(action); | ||||
|     } | ||||
| @@ -286,7 +286,7 @@ template<typename... Ts> class Automation { | ||||
|   explicit Automation(Trigger<Ts...> *trigger) : trigger_(trigger) { this->trigger_->set_automation_parent(this); } | ||||
|  | ||||
|   void add_action(Action<Ts...> *action) { this->actions_.add_action(action); } | ||||
|   void add_actions(const std::vector<Action<Ts...> *> &actions) { this->actions_.add_actions(actions); } | ||||
|   void add_actions(const std::initializer_list<Action<Ts...> *> &actions) { this->actions_.add_actions(actions); } | ||||
|  | ||||
|   void stop() { this->actions_.stop(); } | ||||
|  | ||||
|   | ||||
| @@ -194,12 +194,12 @@ template<typename... Ts> class IfAction : public Action<Ts...> { | ||||
|  public: | ||||
|   explicit IfAction(Condition<Ts...> *condition) : condition_(condition) {} | ||||
|  | ||||
|   void add_then(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_then(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     this->then_.add_actions(actions); | ||||
|     this->then_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next_(x...); })); | ||||
|   } | ||||
|  | ||||
|   void add_else(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_else(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     this->else_.add_actions(actions); | ||||
|     this->else_.add_action(new LambdaAction<Ts...>([this](Ts... x) { this->play_next_(x...); })); | ||||
|   } | ||||
| @@ -240,7 +240,7 @@ template<typename... Ts> class WhileAction : public Action<Ts...> { | ||||
|  public: | ||||
|   WhileAction(Condition<Ts...> *condition) : condition_(condition) {} | ||||
|  | ||||
|   void add_then(const std::vector<Action<Ts...> *> &actions) { | ||||
|   void add_then(const std::initializer_list<Action<Ts...> *> &actions) { | ||||
|     this->then_.add_actions(actions); | ||||
|     this->then_.add_action(new LambdaAction<Ts...>([this](Ts... x) { | ||||
|       if (this->num_running_ > 0 && this->condition_->check_tuple(this->var_)) { | ||||
| @@ -287,7 +287,7 @@ template<typename... Ts> class RepeatAction : public Action<Ts...> { | ||||
|  public: | ||||
|   TEMPLATABLE_VALUE(uint32_t, count) | ||||
|  | ||||
|   void add_then(const std::vector<Action<uint32_t, Ts...> *> &actions) { | ||||
|   void add_then(const std::initializer_list<Action<uint32_t, Ts...> *> &actions) { | ||||
|     this->then_.add_actions(actions); | ||||
|     this->then_.add_action(new LambdaAction<uint32_t, Ts...>([this](uint32_t iteration, Ts... x) { | ||||
|       iteration++; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user