mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-27 11:21:02 +08:00
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
This commit is contained in:
parent
1ee39a6752
commit
94cda30dbd
@ -1398,14 +1398,12 @@ String Value::Comments::get(CommentPlacement slot) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Value::Comments::set(CommentPlacement slot, String comment) {
|
void Value::Comments::set(CommentPlacement slot, String comment) {
|
||||||
if (!ptr_) {
|
if (slot >= CommentPlacement::numberOfCommentPlacement)
|
||||||
|
return;
|
||||||
|
if (!ptr_)
|
||||||
ptr_ = std::unique_ptr<Array>(new Array());
|
ptr_ = std::unique_ptr<Array>(new Array());
|
||||||
}
|
|
||||||
// check comments array boundry.
|
|
||||||
if (slot < CommentPlacement::numberOfCommentPlacement) {
|
|
||||||
(*ptr_)[slot] = std::move(comment);
|
(*ptr_)[slot] = std::move(comment);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Value::setComment(String comment, CommentPlacement placement) {
|
void Value::setComment(String comment, CommentPlacement placement) {
|
||||||
if (!comment.empty() && (comment.back() == '\n')) {
|
if (!comment.empty() && (comment.back() == '\n')) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user