Skip to content

Commit 573b8f7

Browse files
committed
S_uiv_2buf: code quality improvements suggested in GH#22927
1 parent 0678177 commit 573b8f7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Diff for: sv_inline.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ S_uiv_2buf(char *const buf, const IV iv, UV uv, const int is_uv, char **const pe
10441044
{
10451045
char *ptr = buf + TYPE_CHARS(UV);
10461046
char * const ebuf = ptr;
1047-
int sign;
10481047
U16 *word_ptr, *word_table;
10491048

10501049
PERL_ARGS_ASSERT_UIV_2BUF;
@@ -1055,15 +1054,17 @@ S_uiv_2buf(char *const buf, const IV iv, UV uv, const int is_uv, char **const pe
10551054
word_ptr = (U16*)ptr;
10561055
word_table = (U16*)Perl_int2str_table.arr;
10571056

1058-
if (UNLIKELY(is_uv))
1059-
sign = 0;
1060-
else if (iv >= 0) {
1061-
uv = iv;
1062-
sign = 0;
1063-
} else {
1064-
/* Using 0- here to silence bogus warning from MS VC */
1065-
uv = (UV) (0 - (UV) iv);
1066-
sign = 1;
1057+
bool sign = false;
1058+
if (LIKELY(!is_uv)) {
1059+
if (iv >= 0) {
1060+
uv = iv;
1061+
} else {
1062+
/* This is NEGATE_2UV(iv), which can be found in handy.h. */
1063+
/* sv_inline.h does not include handy.h because the latter
1064+
* would then get included twice into .c files. */
1065+
uv = (ASSUME((iv) < 0), (UV)-((iv) + 1) + 1U);
1066+
sign = 1;
1067+
}
10671068
}
10681069

10691070
while (uv > 99) {

0 commit comments

Comments
 (0)