Skip to content

Commit

Permalink
When saving ints, if the value is small enough save it with the type.
Browse files Browse the repository at this point in the history
This uses a new type, SAVEt_INT_SMALL.
  • Loading branch information
nwc10 committed May 5, 2010
1 parent 89abef2 commit 994d373
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion scope.c
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions scope.h
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions sv.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 994d373

Please sign in to comment.