summaryrefslogtreecommitdiff
path: root/handy.h
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2004-07-16 11:04:37 +0000
committerNicholas Clark <nick@ccl4.org>2004-07-16 11:04:37 +0000
commite90e236463307bd7f53439b91573fe42e9cb8901 (patch)
tree89bf49d9ec83486ed0205849ff8ae782b1c2947e /handy.h
parentb0bc38e63ed7e7e448fb07e45ee093d3b3d54be8 (diff)
downloadperl-e90e236463307bd7f53439b91573fe42e9cb8901.tar.gz
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) p4raw-id: //depot/perl@23126
Diffstat (limited to 'handy.h')
-rw-r--r--handy.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/handy.h b/handy.h
index 19a593408e..e5c7c45c93 100644
--- a/handy.h
+++ b/handy.h
@@ -559,16 +559,30 @@ The XSUB-writer's interface to the C C<memmove> 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. 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.
@@ -605,6 +619,15 @@ hopefully catches attempts to access uninitialized memory.
#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
@@ -627,6 +650,14 @@ hopefully catches attempts to access uninitialized memory.
#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
@@ -640,6 +671,9 @@ hopefully catches attempts to access uninitialized memory.
#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)