Skip to content

Commit 231a34d

Browse files
committed
opt(flow): 优化IfThenAction
1 parent 8771865 commit 231a34d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

modules/flow/actions/if_then_action.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,18 @@ void IfThenAction::toJson(Json &js) const {
5151

5252
auto &js_children = js["children"];
5353

54-
int index = 0;
54+
int prefix_num = 0;
5555
for (auto &item : if_then_actions_) {
5656
std::ostringstream oss;
57-
oss << std::setw(2) << std::setfill('0') << index << '.';
57+
oss << std::setw(2) << std::setfill('0') << prefix_num << '.';
5858
auto prefix = oss.str();
5959

6060
item.first->toJson(js_children[prefix + "if"]);
6161
item.second->toJson(js_children[prefix + "then"]);
62-
++index;
62+
++prefix_num;
6363
}
64+
65+
js["index"] = index_;
6466
}
6567

6668
int IfThenAction::addChildAs(Action *child, const std::string &role) {
@@ -130,7 +132,7 @@ void IfThenAction::onStart() {
130132
AssembleAction::onStart();
131133

132134
index_ = 0;
133-
tryNext();
135+
doStart();
134136
}
135137

136138
void IfThenAction::onStop() {
@@ -164,7 +166,7 @@ void IfThenAction::onReset() {
164166
}
165167
}
166168

167-
void IfThenAction::tryNext() {
169+
void IfThenAction::doStart() {
168170
if (index_ >= if_then_actions_.size()) {
169171
finish(false, Reason(ACTION_REASON_IF_THEN_SKIP, "IfThenSkip"));
170172
return;
@@ -183,7 +185,7 @@ void IfThenAction::onIfActionFinished(bool is_succ) {
183185
} else {
184186
//! 跳至下一个分支
185187
++index_;
186-
tryNext();
188+
doStart();
187189
}
188190
}
189191

modules/flow/actions/if_then_action.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class IfThenAction : public AssembleAction {
9191
virtual void onReset() override;
9292

9393
protected:
94-
void tryNext();
94+
void doStart();
9595
void onIfActionFinished(bool is_succ);
9696

9797
private:

0 commit comments

Comments
 (0)