This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Inline av_top_index()
authorKarl Williamson <public@khwilliamson.com>
Thu, 7 Feb 2013 19:06:43 +0000 (12:06 -0700)
committerKarl Williamson <public@khwilliamson.com>
Fri, 8 Feb 2013 21:44:24 +0000 (14:44 -0700)
This function is just an assert and a macro call.  Avoid the function
call overhead by making it inline.

av.c
embed.fnc
embed.h
inline.h
proto.h

diff --git a/av.c b/av.c
index 18fa3c3..a24bda0 100644 (file)
--- a/av.c
+++ b/av.c
@@ -778,24 +778,9 @@ meaning from what the similarly named L</sv_len> returns.
 I32
 Perl_av_len(pTHX_ AV *av)
 {
-    /* If change this, must change identical Perl_av_top_index() just below */
-
     PERL_ARGS_ASSERT_AV_LEN;
-    assert(SvTYPE(av) == SVt_PVAV);
-
-    return AvFILL(av);
-}
-
-I32
-Perl_av_top_index(pTHX_ AV *av)
-{
-    /* So short, that it is just a duplicate of Perl_av_len().  Must keep them
-     * in sync */
-
-    PERL_ARGS_ASSERT_AV_TOP_INDEX;
-    assert(SvTYPE(av) == SVt_PVAV);
 
-    return AvFILL(av);
+    return av_top_index(av);
 }
 
 /*
index 756dd94..2689e4e 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -219,7 +219,7 @@ Apd |void   |av_push        |NN AV *av|NN SV *val
 EXp    |void   |av_reify       |NN AV *av
 ApdR   |SV*    |av_shift       |NN AV *av
 Apd    |SV**   |av_store       |NN AV *av|I32 key|NULLOK SV *val
-ApdR   |I32    |av_top_index   |NN AV *av
+AidR   |I32    |av_top_index   |NN AV *av
 Apd    |void   |av_undef       |NN AV *av
 ApdoxM |SV**   |av_create_and_unshift_one|NN AV **const avp|NN SV *const val
 Apd    |void   |av_unshift     |NN AV *av|I32 num
diff --git a/embed.h b/embed.h
index 28de51b..c66eba9 100644 (file)
--- a/embed.h
+++ b/embed.h
@@ -56,7 +56,7 @@
 #define av_push(a,b)           Perl_av_push(aTHX_ a,b)
 #define av_shift(a)            Perl_av_shift(aTHX_ a)
 #define av_store(a,b,c)                Perl_av_store(aTHX_ a,b,c)
-#define av_top_index(a)                Perl_av_top_index(aTHX_ a)
+#define av_top_index(a)                S_av_top_index(aTHX_ a)
 #define av_undef(a)            Perl_av_undef(aTHX_ a)
 #define av_unshift(a,b)                Perl_av_unshift(aTHX_ a,b)
 #define block_gimme()          Perl_block_gimme(aTHX)
index 85bdc74..6b5f93c 100644 (file)
--- a/inline.h
+++ b/inline.h
  * Each section names the header file that the functions "belong" to.
  */
 
+/* ------------------------------- av.h ------------------------------- */
+
+PERL_STATIC_INLINE I32
+S_av_top_index(pTHX_ AV *av)
+{
+    PERL_ARGS_ASSERT_AV_TOP_INDEX;
+    assert(SvTYPE(av) == SVt_PVAV);
+
+    return AvFILL(av);
+}
+
 /* ------------------------------- cv.h ------------------------------- */
 
 PERL_STATIC_INLINE I32 *
diff --git a/proto.h b/proto.h
index e22277f..e1575c7 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -227,7 +227,7 @@ PERL_CALLCONV SV**  Perl_av_store(pTHX_ AV *av, I32 key, SV *val)
 #define PERL_ARGS_ASSERT_AV_STORE      \
        assert(av)
 
-PERL_CALLCONV I32      Perl_av_top_index(pTHX_ AV *av)
+PERL_STATIC_INLINE I32 S_av_top_index(pTHX_ AV *av)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_AV_TOP_INDEX  \