Skip to content

Commit 4edac50

Browse files
committed
utf8_to_uv_msgs: Avoid extra deref pointer writes
This function is passed an address of where to write some values. Instead of updating the derefernced pointer each time, do it once after all the information is accumulated. This allows for the values to be updated without updating the pointed to variable.
1 parent 6e88530 commit 4edac50

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

utf8.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
19911991
bool disallowed = FALSE;
19921992
const U32 orig_problems = possible_problems;
19931993
U32 error_flags_return = 0;
1994+
AV * msgs_return = NULL;
19941995

19951996
/* The following macro returns 0 if no message needs to be generated
19961997
* for this problem even if everything else says to. Otherwise returns
@@ -2471,17 +2472,17 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
24712472

24722473
} /* End of switch() on the possible problems */
24732474

2474-
/* Display the message (if any) for the problem being handled in
2475-
* this iteration of the loop */
2475+
/* Display or save the message (if any) for the problem being
2476+
* handled in this iteration of the loop */
24762477
if (message) {
24772478
if (msgs) {
2478-
if (*msgs == NULL) {
2479-
*msgs = newAV();
2479+
if (msgs_return == NULL) {
2480+
msgs_return = newAV();
24802481
}
24812482

2482-
av_push(*msgs, newRV_noinc((SV*) new_msg_hv(message,
2483-
pack_warn,
2484-
this_flag_bit)));
2483+
av_push(msgs_return,
2484+
newRV_noinc((SV*) new_msg_hv(message, pack_warn,
2485+
this_flag_bit)));
24852486
}
24862487
else if (PL_op)
24872488
Perl_warner(aTHX_ pack_warn, "%s in %s", message,
@@ -2498,6 +2499,10 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
24982499
*advance_p = curlen;
24992500
}
25002501

2502+
if (msgs_return) {
2503+
*msgs = msgs_return;
2504+
}
2505+
25012506
if (errors) {
25022507
*errors = error_flags_return;
25032508
}

0 commit comments

Comments
 (0)