@@ -169,17 +169,13 @@ void BlockDesc::Flush() {
169
169
}
170
170
171
171
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 ();
175
173
for (auto &op_desc : ops_) {
176
- op_field. AddAllocated ( op_desc->Proto ());
174
+ this -> desc_ -> mutable_ops ()-> Add ()-> CopyFrom (* op_desc->Proto ());
177
175
}
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 ();
181
177
for (auto &var_desc : vars_) {
182
- var_field. AddAllocated ( var_desc.second ->Proto ());
178
+ this -> desc_ -> mutable_vars ()-> Add ()-> CopyFrom (* var_desc.second ->Proto ());
183
179
}
184
180
need_update_ = false ;
185
181
}
@@ -217,22 +213,6 @@ BlockDesc::BlockDesc(const BlockDesc &other, proto::BlockDesc *desc,
217
213
}
218
214
}
219
215
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
-
236
216
void BlockDesc::SetForwardBlockID (int32_t forward_block_id) {
237
217
PADDLE_ENFORCE (!desc_->has_forward_block_idx (),
238
218
" Parent block ID has been set to %d. Cannot set to %d" ,
0 commit comments