@@ -169,17 +169,13 @@ void BlockDesc::Flush() {
169169 }
170170
171171 if (need_update_) {
172- auto &op_field = *this ->desc_ ->mutable_ops ();
173- this ->ClearPBOps ();
174- op_field.Reserve (static_cast <int >(ops_.size ()));
172+ this ->desc_ ->mutable_ops ()->Clear ();
175173 for (auto &op_desc : ops_) {
176- op_field. AddAllocated ( op_desc->Proto ());
174+ this -> desc_ -> mutable_ops ()-> Add ()-> CopyFrom (* op_desc->Proto ());
177175 }
178- auto &var_field = *this ->desc_ ->mutable_vars ();
179- this ->ClearPBVars ();
180- var_field.Reserve (static_cast <int >(vars_.size ()));
176+ this ->desc_ ->mutable_vars ()->Clear ();
181177 for (auto &var_desc : vars_) {
182- var_field. AddAllocated ( var_desc.second ->Proto ());
178+ this -> desc_ -> mutable_vars ()-> Add ()-> CopyFrom (* var_desc.second ->Proto ());
183179 }
184180 need_update_ = false ;
185181 }
@@ -217,22 +213,6 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
217213 }
218214}
219215
220- void BlockDesc::ClearPBOps () {
221- auto ops = this ->desc_ ->mutable_ops ();
222- while (!ops->empty ()) {
223- // we do not own the OpDesc, so release the ownership.
224- ops->ReleaseLast ();
225- }
226- }
227-
228- void BlockDesc::ClearPBVars () {
229- auto vars = this ->desc_ ->mutable_vars ();
230- while (!vars->empty ()) {
231- // we do not own the VarDesc, so release the ownership.
232- vars->ReleaseLast ();
233- }
234- }
235-
236216void BlockDesc::SetForwardBlockID (int32_t forward_block_id) {
237217 PADDLE_ENFORCE (!desc_->has_forward_block_idx (),
238218 " Parent block ID has been set to %d. Cannot set to %d" ,
0 commit comments