Skip to content

Commit f26851b

Browse files
committed
uiv_2buf: code quality improvements suggested in GH#22927
1 parent e7ae449 commit f26851b

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

sv.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,8 +2807,8 @@ Perl_uiv_2buf(char *const buf, const IV iv, UV uv, const int is_uv, char **const
28072807
{
28082808
char *ptr = buf + TYPE_CHARS(UV);
28092809
char * const ebuf = ptr;
2810-
int sign;
2811-
U16 *word_ptr, *word_table;
2810+
U16 *word_ptr;
2811+
U16 const *word_table;
28122812

28132813
PERL_ARGS_ASSERT_UIV_2BUF;
28142814

@@ -2817,16 +2817,17 @@ Perl_uiv_2buf(char *const buf, const IV iv, UV uv, const int is_uv, char **const
28172817
/* we are going to read/write two bytes at a time */
28182818
word_ptr = (U16*)ptr;
28192819
word_table = (U16*)int2str_table.arr;
2820-
2821-
if (UNLIKELY(is_uv))
2822-
sign = 0;
2823-
else if (iv >= 0) {
2824-
uv = iv;
2825-
sign = 0;
2826-
} else {
2827-
/* Using 0- here to silence bogus warning from MS VC */
2828-
uv = (UV) (0 - (UV) iv);
2829-
sign = 1;
2820+
bool sign = false;
2821+
if (LIKELY(!is_uv)) {
2822+
if (iv >= 0) {
2823+
uv = iv;
2824+
} else {
2825+
/* This is NEGATE_2UV(iv), which can be found in handy.h. */
2826+
/* sv_inline.h does not include handy.h because the latter
2827+
* would then get included twice into .c files. */
2828+
uv = (ASSUME((iv) < 0), (UV)-((iv) + 1) + 1U);
2829+
sign = 1;
2830+
}
28302831
}
28312832

28322833
while (uv > 99) {

0 commit comments

Comments
 (0)