Skip to content

Commit 4d55d9a

Browse files
committed
Repeat newSViv optimization for newSVuv
Pretty much the same change as bd30fe8 was for newSViv.
1 parent d64e784 commit 4d55d9a

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sv.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9394,8 +9394,29 @@ Perl_newSVuv(pTHX_ const UV u)
93949394
{
93959395
SV *sv;
93969396

9397+
/* Inlining ONLY the small relevant subset of sv_setuv here
9398+
* for performance. Makes a significant difference. */
9399+
9400+
/* Using ivs is more efficient than using uvs - see sv_setuv */
9401+
if (u <= (UV)IV_MAX) {
9402+
return newSViv((IV)u);
9403+
}
9404+
93979405
new_SV(sv);
9398-
sv_setuv(sv,u);
9406+
9407+
/* We're starting from SVt_FIRST, so provided that's
9408+
* actual 0, we don't have to unset any SV type flags
9409+
* to promote to SVt_IV. */
9410+
assert(SVt_FIRST == 0);
9411+
9412+
SET_SVANY_FOR_BODYLESS_IV(sv);
9413+
SvFLAGS(sv) |= SVt_IV;
9414+
(void)SvIOK_on(sv);
9415+
(void)SvIsUV_on(sv);
9416+
9417+
SvUV_set(sv, u);
9418+
SvTAINT(sv);
9419+
93999420
return sv;
94009421
}
94019422

0 commit comments

Comments
 (0)