File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -213,11 +213,19 @@ r_obj* fn_zap_srcref(r_obj* x) {
213213
214214 r_obj * out = KEEP (r_new_function (formals , body , env ));
215215
216- // Copy over attributes, but zap any `srcref` attribute.
217- // `r_attrib_poke()` will clone the attribute pairlist as required
218- // to avoid mutating the attributes of `x`.
219- r_poke_attrib (out , r_attrib (x ));
220- r_attrib_poke (out , r_syms .srcref , r_null );
216+ // Copy over attributes, but zap any `srcref` attribute
217+ if (r_attrib_get (x , r_syms .srcref ) == r_null ) {
218+ // Nothing to zap
219+ r_obj * attrib = r_attrib (x );
220+ r_poke_attrib (out , attrib );
221+ } else {
222+ // Clone so we can zap `srcref`
223+ r_obj * attrib = r_attrib (x );
224+ attrib = KEEP (r_clone (attrib ));
225+ r_poke_attrib (out , attrib );
226+ FREE (1 );
227+ r_attrib_poke (out , r_syms .srcref , r_null );
228+ }
221229
222230 FREE (2 );
223231 return out ;
You can’t perform that action at this time.
0 commit comments