Skip to content

Commit

Permalink
utf8.c: Extract out common statement
Browse files Browse the repository at this point in the history
Each case: in the switch has this statement which can be handled outside
it, once.
  • Loading branch information
khwilliamson committed Nov 21, 2024
1 parent a9374ce commit 41e43bc
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -1700,13 +1700,14 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
* it changes 'uv' looked at by the others */

U32 this_problem = 1U << lsbit_pos32(possible_problems);
possible_problems &= ~this_problem;

switch (this_problem) {
case UTF8_GOT_OVERFLOW:

/* Overflow means also got a super and are using Perl's
* extended UTF-8, but we handle all three cases here */
possible_problems
&= ~(UTF8_GOT_OVERFLOW|UTF8_GOT_SUPER|UTF8_GOT_PERL_EXTENDED);
possible_problems &= ~(UTF8_GOT_SUPER|UTF8_GOT_PERL_EXTENDED);
*errors |= UTF8_GOT_OVERFLOW;

/* But the API says we flag all errors found */
Expand Down Expand Up @@ -1757,7 +1758,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_EMPTY:
possible_problems &= ~UTF8_GOT_EMPTY;
*errors |= UTF8_GOT_EMPTY;

if (! (flags & UTF8_ALLOW_EMPTY)) {
Expand All @@ -1781,7 +1781,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_CONTINUATION:
possible_problems &= ~UTF8_GOT_CONTINUATION;
*errors |= UTF8_GOT_CONTINUATION;

if (! (flags & UTF8_ALLOW_CONTINUATION)) {
Expand All @@ -1802,7 +1801,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_SHORT:
possible_problems &= ~UTF8_GOT_SHORT;
*errors |= UTF8_GOT_SHORT;

if (! (flags & UTF8_ALLOW_SHORT)) {
Expand All @@ -1825,7 +1823,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_NON_CONTINUATION:
possible_problems &= ~UTF8_GOT_NON_CONTINUATION;
*errors |= UTF8_GOT_NON_CONTINUATION;

if (! (flags & UTF8_ALLOW_NON_CONTINUATION)) {
Expand Down Expand Up @@ -1853,7 +1850,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_SURROGATE:
possible_problems &= ~UTF8_GOT_SURROGATE;

if (flags & UTF8_WARN_SURROGATE) {
*errors |= UTF8_GOT_SURROGATE;
Expand Down Expand Up @@ -1886,7 +1882,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_SUPER:
possible_problems &= ~UTF8_GOT_SUPER;

if (flags & UTF8_WARN_SUPER) {
*errors |= UTF8_GOT_SUPER;
Expand Down Expand Up @@ -1963,7 +1958,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_NONCHAR:
possible_problems &= ~UTF8_GOT_NONCHAR;

if (flags & UTF8_WARN_NONCHAR) {
*errors |= UTF8_GOT_NONCHAR;
Expand All @@ -1990,7 +1984,6 @@ Perl__utf8n_to_uvchr_msgs_helper(const U8 *s,
break;

case UTF8_GOT_LONG:
possible_problems &= ~UTF8_GOT_LONG;
*errors |= UTF8_GOT_LONG;

if (flags & UTF8_ALLOW_LONG) {
Expand Down

0 comments on commit 41e43bc

Please sign in to comment.