Change 23306 by nicholas@no-spam on 2004/09/10 06:39:03
Integrate:
[ 23126]
Encourage compilers to tail call optimise in sv_savepv, sv_savepvn
and sv_savesharedpv. Need to create non-void returning versions of
Copy and Zero, as the existing macros deliberately cast to (void)
[ 23135]
Turn 2 strcpy()s into memcpy() because we know the length.
Affected files ...
... //depot/maint-5.8/perl/handy.h#16 integrate
... //depot/maint-5.8/perl/malloc.c#8 integrate
... //depot/maint-5.8/perl/perl.c#83 integrate
... //depot/maint-5.8/perl/pod/perlapi.pod#34 integrate
... //depot/maint-5.8/perl/sv.c#109 integrate
... //depot/maint-5.8/perl/toke.c#48 integrate
... //depot/maint-5.8/perl/util.c#43 integrate
Differences ...
==== //depot/maint-5.8/perl/handy.h#16 (text) ====
Index: perl/handy.h
--- perl/handy.h#15~22784~ Wed May 5 14:43:32 2004
+++ perl/handy.h Thu Sep 9 23:39:03 2004
@@no-spam -559,16 +559,30 @@no-spam
source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
the type. Can do overlapping moves. See also C<Copy>.
+=for apidoc Am|void *|MoveD|void* src|void* dest|int nitems|type
+Like C<Move> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
=for apidoc Am|void|Copy|void* src|void* dest|int nitems|type
The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
the type. May fail on overlapping copies. See also C<Move>.
+=for apidoc Am|void *|CopyD|void* src|void* dest|int nitems|type
+
+Like C<Copy> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
=for apidoc Am|void|Zero|void* dest|int nitems|type
The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
destination, C<nitems> is the number of items, and C<type> is the type.
+=for apidoc Am|void *|ZeroD|void* dest|int nitems|type
+
+Like C<Zero> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
=for apidoc Am|void|StructCopy|type src|type dest|type
This is an architecture-independent macro to copy one structure to another.
@@no-spam -605,6 +619,15 @@no-spam
#define Copy(s,d,n,t) (MEM_WRAP_CHECK(n,t), (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
#define Zero(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memzero((char*)(d), (n) * sizeof(t)))
+#define MoveD(s,d,n,t) (MEM_WRAP_CHECK(n,t), memmove((char*)(d),(char*)(s), (n) * sizeof(t)))
+#define CopyD(s,d,n,t) (MEM_WRAP_CHECK(n,t), memcpy((char*)(d),(char*)(s), (n) * sizeof(t)))
+#ifdef HAS_MEMSET
+#define ZeroD(d,n,t) (MEM_WRAP_CHECK(n,t), memzero((char*)(d), (n) * sizeof(t)))
+#else
+/* Using bzero(), which returns void. */
+#define ZeroD(d,n,t) (MEM_WRAP_CHECK(n,t), memzero((char*)(d), (n) * sizeof(t)),d)
+#endif
+
#define Poison(d,n,t) (MEM_WRAP_CHECK(n,t), (void)memset((char*)(d), 0xAB, (n) * sizeof(t)))
#else
@@no-spam -627,6 +650,14 @@no-spam
#define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
#define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
+#define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t))
+#define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
+#ifdef HAS_MEMSET
+#define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t))
+#else
+#define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)),d)
+#endif
+
#define Poison(d,n,t) (void)memset((char*)(d), 0xAB, (n) * sizeof(t))
#endif
@@no-spam -640,6 +671,9 @@no-spam
#define Move(s,d,n,t)
#define Copy(s,d,n,t)
#define Zero(d,n,t)
+#define MoveD(s,d,n,t) d
+#define CopyD(s,d,n,t) d
+#define ZeroD(d,n,t) d
#define Poison(d,n,t)
#define Safefree(d) (d) = (d)
==== //depot/maint-5.8/perl/malloc.c#8 (text) ====
Index: perl/malloc.c
--- perl/malloc.c#7~20212~ Thu Jul 24 07:32:57 2003
+++ perl/malloc.c Thu Sep 9 23:39:03 2004
@@no-spam -357,6 +357,7 @@no-spam
# define Free_t void
# endif
# define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
+# define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
# define PerlEnv_getenv getenv
# define PerlIO_printf fprintf
# define PerlIO_stderr() stderr
@@no-spam -2311,8 +2312,7 @@no-spam
MEM_SIZE l = strlen(s);
char *s1 = (char *)Perl_malloc(l+1);
- Copy(s, s1, (MEM_SIZE)(l+1), char);
- return s1;
+ return CopyD(s, s1, (MEM_SIZE)(l+1), char);
}
#ifdef PERL_CORE
==== //depot/maint-5.8/perl/perl.c#83 (text) ====
Index: perl/perl.c
--- perl/perl.c#82~23302~ Thu Sep 9 14:45:33 2004
+++ perl/perl.c Thu Sep 9 23:39:03 2004
@@no-spam -201,8 +201,7 @@no-spam
my_perl = (PerlInterpreter*)PerlMem_malloc(sizeof(PerlInterpreter));
INIT_TLS_AND_INTERP;
- Zero(my_perl, 1, PerlInterpreter);
- return my_perl;
+ return ZeroD(my_perl, 1, PerlInterpreter);
}
#endif /* PERL_IMPLICIT_SYS */
==== //depot/maint-5.8/perl/pod/perlapi.pod#34 (text+w) ====
Index: perl/pod/perlapi.pod
--- perl/pod/perlapi.pod#33~22983~ Wed Jun 23 06:41:45 2004
+++ perl/pod/perlapi.pod Thu Sep 9 23:39:03 2004
@@no-spam -1544,6 +1544,16 @@no-spam
=for hackers
Found in file handy.h
+=item CopyD
+
+Like C<Copy> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
+ void * CopyD(void* src, void* dest, int nitems, type)
+
+=for hackers
+Found in file handy.h
+
=item Move
The XSUB-writer's interface to the C C<memmove> function. The C<src> is the
@@no-spam -1555,6 +1565,16 @@no-spam
=for hackers
Found in file handy.h
+=item MoveD
+
+Like C<Move> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
+ void * MoveD(void* src, void* dest, int nitems, type)
+
+=for hackers
+Found in file handy.h
+
=item New
The XSUB-writer's interface to the C C<malloc> function.
@@no-spam -1671,6 +1691,16 @@no-spam
destination, C<nitems> is the number of items, and C<type> is the type.
void Zero(void* dest, int nitems, type)
+
+=for hackers
+Found in file handy.h
+
+=item ZeroD
+
+Like C<Zero> but returns dest. Useful for encouraging compilers to tail-call
+optimise.
+
+ void * ZeroD(void* dest, int nitems, type)
=for hackers
Found in file handy.h
==== //depot/maint-5.8/perl/sv.c#109 (text) ====
Index: perl/sv.c
--- perl/sv.c#108~23087~ Mon Jul 12 14:36:51 2004
+++ perl/sv.c Thu Sep 9 23:39:03 2004
@@no-spam -3252,9 +3252,8 @@no-spam
*lp = len;
s = SvGROW(sv, len + 1);
SvCUR_set(sv, len);
- (void)strcpy(s, t);
SvPOKp_on(sv);
- return s;
+ return strcpy(s, t);
}
}
==== //depot/maint-5.8/perl/toke.c#48 (text) ====
Index: perl/toke.c
--- perl/toke.c#47~23294~ Thu Sep 9 04:12:47 2004
+++ perl/toke.c Thu Sep 9 23:39:03 2004
@@no-spam -6629,7 +6629,7 @@no-spam
sv_setpvn(tmpstr,d+1,s-d);
s += len - 1;
sv_catpvn(herewas,s,bufend-s);
- (void)strcpy(bufptr,SvPVX(herewas));
+ Copy(SvPVX(herewas),bufptr,SvCUR(herewas) + 1,char);
s = olds;
goto retval;
@@no-spam -6799,7 +6799,7 @@no-spam
/* turn <> into <ARGV> */
if (!len)
- (void)strcpy(d,"ARGV");
+ Copy("ARGV",d,5,char);
/* Check whether readline() is overriden */
if (((gv_readline = gv_fetchpv("readline", FALSE, SVt_PVCV))
==== //depot/maint-5.8/perl/util.c#43 (text) ====
Index: perl/util.c
--- perl/util.c#42~23304~ Thu Sep 9 23:04:43 2004
+++ perl/util.c Thu Sep 9 23:39:03 2004
@@no-spam -751,12 +751,12 @@no-spam
char *
Perl_savepv(pTHX_ const char *pv)
{
- register char *newaddr = Nullch;
- if (pv) {
- New(902,newaddr,strlen(pv)+1,char);
- (void)strcpy(newaddr,pv);
- }
- return newaddr;
+ register char *newaddr;
+ if (!pv)
+ return Nullch;
+
+ New(902,newaddr,strlen(pv)+1,char);
+ return strcpy(newaddr,pv);
}
/* same thing but with a known length */
@@no-spam -780,13 +780,13 @@no-spam
New(903,newaddr,len+1,char);
/* Give a meaning to NULL pointer mainly for the use in sv_magic() */
if (pv) {
- Copy(pv,newaddr,len,char); /* might not be null terminated */
- newaddr[len] = '\0'; /* is now */
+ /* might not be null terminated */
+ newaddr[len] = '\0';
+ return CopyD(pv,newaddr,len,char);
}
else {
- Zero(newaddr,len+1,char);
+ return ZeroD(newaddr,len+1,char);
}
- return newaddr;
}
/*
@@no-spam -800,17 +800,17 @@no-spam
char *
Perl_savesharedpv(pTHX_ const char *pv)
{
- register char *newaddr = Nullch;
- if (pv) {
- newaddr = (char*)PerlMemShared_malloc(strlen(pv)+1);
- if (!newaddr) {
- PerlLIO_write(PerlIO_fileno(Perl_error_log),
- PL_no_mem, strlen(PL_no_mem));
- my_exit(1);
- }
- (void)strcpy(newaddr,pv);
+ register char *newaddr;
+ if (!pv)
+ return Nullch;
+
+ newaddr = (char*)PerlMemShared_malloc(strlen(pv)+1);
+ if (!newaddr) {
+ PerlLIO_write(PerlIO_fileno(Perl_error_log),
+ PL_no_mem, strlen(PL_no_mem));
+ my_exit(1);
}
- return newaddr;
+ return strcpy(newaddr,pv);
}
End of Patch.