summaryrefslogtreecommitdiff
path: root/pad.h
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-11-28 14:35:40 -0800
committerFather Chrysostomos <sprout@cpan.org>2014-11-30 11:48:42 -0800
commit662308654967c8d237f3ee651bae9c27cd9feaa2 (patch)
tree9b54880a1f2ab9af8a41b57e4fd7b8f63b392a2d /pad.h
parent93fa278758aa71f9c91078585c82898a9c7b8eb6 (diff)
downloadperl-662308654967c8d237f3ee651bae9c27cd9feaa2.tar.gz
Minimise the size of padname + string buffer
If we define the struct a little differently, we can begin the string buffer two bytes into a pointer, rather than pointer-aligned. In case some platforms can compare pointer-aligned string faster, I added a #define to allow that. But on 64-bit darwin the speed is identical either way: $ time ./miniperl -e 'eval q|my$a;|x50000 . q|eval q<my $A>|' I ran this three times in each mode, and the average of the user times differed by less than 1%.
Diffstat (limited to 'pad.h')
-rw-r--r--pad.h44
1 files changed, 32 insertions, 12 deletions
diff --git a/pad.h b/pad.h
index e19c7a8e2a..7ee8a1ca38 100644
--- a/pad.h
+++ b/pad.h
@@ -45,26 +45,46 @@ struct padnamelist {
U32 xpadnl_refcnt;
};
+/* PERL_PADNAME_MINIMAL uses less memory, but on some platforms
+ PERL_PADNAME_ALIGNED may be faster, so platform-specific hints can
+ define one or the other. */
+#if defined(PERL_PADNAME_MINIMAL) && defined (PERL_PADNAME_ALIGNED)
+# error PERL_PADNAME_MINIMAL and PERL_PADNAME_ALIGNED are exclusive
+#endif
+
+#if !defined(PERL_PADNAME_MINIMAL) && !defined(PERL_PADNAME_ALIGNED)
+# define PERL_PADNAME_ALIGNED
+#endif
+
+#define _PADNAME_BASE \
+ char * xpadn_pv; \
+ HV * xpadn_ourstash; \
+ union { \
+ HV * xpadn_typestash; \
+ CV * xpadn_protocv; \
+ } xpadn_type_u; \
+ U32 xpadn_low; \
+ U32 xpadn_high; \
+ U32 xpadn_refcnt; \
+ int xpadn_gen; \
+ U8 xpadn_len; \
+ U8 xpadn_flags
+
struct padname {
- char * xpadn_pv;
- HV * xpadn_ourstash;
- union {
- HV * xpadn_typestash;
- CV * xpadn_protocv;
- } xpadn_type_u;
- U32 xpadn_low;
- U32 xpadn_high;
- U32 xpadn_refcnt;
- int xpadn_gen;
- U8 xpadn_len;
- U8 xpadn_flags;
+ _PADNAME_BASE;
};
struct padname_with_str {
+#ifdef PERL_PADNAME_MINIMAL
+ _PADNAME_BASE;
+#else
struct padname xpadn_padname;
+#endif
char xpadn_str[1];
};
+#undef _PADNAME_BASE
+
#define PADNAME_FROM_PV(s) \
((PADNAME *)((s) - STRUCT_OFFSET(struct padname_with_str, xpadn_str)))