Skip to content

Commit 94cda30

Browse files
authored
Rearrange Comments::set (#1278)
* slightly optimize Comments::set Avoid allocation if the set is going to be rejected anyway. Prototype suggestion from #1277 review thread
1 parent 1ee39a6 commit 94cda30

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/lib_json/json_value.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,13 +1398,11 @@ String Value::Comments::get(CommentPlacement slot) const {
13981398
}
13991399

14001400
void Value::Comments::set(CommentPlacement slot, String comment) {
1401-
if (!ptr_) {
1401+
if (slot >= CommentPlacement::numberOfCommentPlacement)
1402+
return;
1403+
if (!ptr_)
14021404
ptr_ = std::unique_ptr<Array>(new Array());
1403-
}
1404-
// check comments array boundry.
1405-
if (slot < CommentPlacement::numberOfCommentPlacement) {
1406-
(*ptr_)[slot] = std::move(comment);
1407-
}
1405+
(*ptr_)[slot] = std::move(comment);
14081406
}
14091407

14101408
void Value::setComment(String comment, CommentPlacement placement) {

0 commit comments

Comments
 (0)