This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
refactor sv_add_backref
authorDaniel Dragan <bulk88@hotmail.com>
Wed, 23 Oct 2013 10:28:15 +0000 (11:28 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 23 Oct 2013 10:28:15 +0000 (11:28 +0100)
commit52379eb83d6750e5a25234194773cdad131ae34f
tree6a4d20ba6da3b2d37bca57a01a9af331a080f21b
parent3e7c2d43f6ca98041fe070aeb1caf1177867ca3c
refactor sv_add_backref

-don't assign NULL twice to var mg, seen in machine code
-use sv_magicext to get MAGIC * instead of a 2nd call to mg_find, less
 passes through the linked list is faster
-move the mg_flags MGf_REFCOUNTED statement to before av, to reduce scope
 of liveness for var mg, it is never used again in the function
-av can not be null since it was just created, use
 SvREFCNT_inc_simple_void_NN
-on a tsv, that is being upgraded to be an AV backref holder, call
 av_extend only once with the correct slice count based on whether tsv was
 a SV backref holder or not previously
-since on a newly AV backref tsv, the number of backrefs will only be 1 or
 2, and if we made an AV type backref holder, doing the SV type
 optimization is now impossible, so don't check av for NULL when we know
 it wont be if we just made the AV, and don't do the bounds check and 2nd
 av_extend either since the AV is new and under our control
-if tsv is already an AV type backref, the AV can have 1 to infinity
 elements so do the bounds check and av_extend as before

It is intentional that on the new AV type holder branch, that after
"av_extend(av, *svp ? 2 : 1);" there are no further function calls in the
execution path until the return.
sv.c