summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-02-20 19:39:37 +0000
committerNicholas Clark <nick@ccl4.org>2010-05-05 13:44:49 +0100
commit994d373a075399b04d509cb2732e0a956c88e014 (patch)
treef63c576e17112f54901861f1272a0d0946d5ddbc
parent89abef211f482f5f37aeb9b02c71c4452feb5c34 (diff)
downloadperl-994d373a075399b04d509cb2732e0a956c88e014.tar.gz
When saving ints, if the value is small enough save it with the type.
This uses a new type, SAVEt_INT_SMALL.
-rw-r--r--scope.c12
-rw-r--r--scope.h1
-rw-r--r--sv.c1
3 files changed, 13 insertions, 1 deletions
diff --git a/scope.c b/scope.c
index 15081c7cd2..92e952360d 100644
--- a/scope.c
+++ b/scope.c
@@ -392,10 +392,16 @@ void
Perl_save_int(pTHX_ int *intp)
{
dVAR;
+ const UV shifted = (UV)*intp << SAVE_TIGHT_SHIFT;
PERL_ARGS_ASSERT_SAVE_INT;
- save_pushi32ptr(*intp, intp, SAVEt_INT);
+ if ((int)(shifted >> SAVE_TIGHT_SHIFT) == *intp) {
+ SSCHECK(2);
+ SSPUSHPTR(intp);
+ SSPUSHUV(SAVEt_INT_SMALL | shifted);
+ } else
+ save_pushi32ptr(*intp, intp, SAVEt_INT);
}
void
@@ -802,6 +808,10 @@ Perl_leave_scope(pTHX_ I32 base)
PL_localizing = 0;
}
break;
+ case SAVEt_INT_SMALL:
+ ptr = SSPOPPTR;
+ *(int*)ptr = (int)(uv >> SAVE_TIGHT_SHIFT);
+ break;
case SAVEt_INT: /* int reference */
ptr = SSPOPPTR;
*(int*)ptr = (int)SSPOPINT;
diff --git a/scope.h b/scope.h
index 9b337e713b..7df44b6471 100644
--- a/scope.h
+++ b/scope.h
@@ -56,6 +56,7 @@
#define SAVEt_PARSER 45
#define SAVEt_ADELETE 46
#define SAVEt_I32_SMALL 47
+#define SAVEt_INT_SMALL 48
#define SAVEf_SETMAGIC 1
#define SAVEf_KEEPOLDELEM 2
diff --git a/sv.c b/sv.c
index 80f7ea2a3d..ae9f9d0a81 100644
--- a/sv.c
+++ b/sv.c
@@ -11583,6 +11583,7 @@ Perl_ss_dup(pTHX_ PerlInterpreter *proto_perl, CLONE_PARAMS* param)
ptr = POPPTR(ss,ix);
TOPPTR(nss,ix) = any_dup(ptr, proto_perl);
/* Fall through */
+ case SAVEt_INT_SMALL:
case SAVEt_I32_SMALL:
case SAVEt_I16: /* I16 reference */
case SAVEt_I8: /* I8 reference */