Skip to content

Commit 0f17f26

Browse files
committed
Perl_utf8_to_uv_msgs_helper: Use bit pos in switch()
The previous commit #defined the bit position of various flag bits. This commit changes to use those as cases in a switch(), rather than the shifted values. This results in better generated code as the cases now reduce to: case 0: case 1: case 2: ... as opposed to previously: case 1<<0: case 1<<1: case 1<<2: ... clang and gcc were unable to see the pattern previously but now are.
1 parent 686c251 commit 0f17f26

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

utf8.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,8 +2209,9 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22092209
* depend on earlier actions. Also the ordering tries to cause any
22102210
* messages to be displayed in kind of decreasing severity order.
22112211
* */
2212-
U32 this_problem = 1U << lsbit_pos32(possible_problems);
22132212

2213+
U8 this_problem_bit = lsbit_pos32(possible_problems);
2214+
U32 this_problem = 1U << this_problem_bit;
22142215
U32 this_flag_bit = this_problem;
22152216

22162217
/* All cases set this */
@@ -2235,7 +2236,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22352236
* would be to handle the message.
22362237
*/
22372238

2238-
switch (this_problem) {
2239+
switch (this_problem_bit) {
22392240
default:
22402241
croak("panic: Unexpected case value in utf8_to_uv_msgs() %"
22412242
U32uf, this_problem);
@@ -2252,7 +2253,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22522253
continue; \
22532254
} \
22542255

2255-
case UTF8_GOT_EMPTY:
2256+
case UTF8_GOT_EMPTY_BIT_POS_:
22562257
COMMON_DEFAULT_REJECTS(,);
22572258

22582259
/* This so-called malformation is now treated as a bug in the
@@ -2263,7 +2264,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22632264
message = Perl_form(aTHX_ "%s: (empty string)", malformed_text);
22642265
break;
22652266

2266-
case UTF8_GOT_CONTINUATION:
2267+
case UTF8_GOT_CONTINUATION_BIT_POS_:
22672268
COMMON_DEFAULT_REJECTS(,);
22682269
message = form(
22692270
"%s: %s (unexpected continuation byte 0x%02x,"
@@ -2273,7 +2274,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22732274
*s0);
22742275
break;
22752276

2276-
case UTF8_GOT_SHORT:
2277+
case UTF8_GOT_SHORT_BIT_POS_:
22772278
COMMON_DEFAULT_REJECTS(,);
22782279
message = form(
22792280
"%s: %s (too short; %d byte%s available, need %d)",
@@ -2284,7 +2285,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22842285
(int)expectlen);
22852286
break;
22862287

2287-
case UTF8_GOT_NON_CONTINUATION:
2288+
case UTF8_GOT_NON_CONTINUATION_BIT_POS_:
22882289
{
22892290
COMMON_DEFAULT_REJECTS(,);
22902291

@@ -2302,8 +2303,8 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23022303
break;
23032304
}
23042305

2305-
case UTF8_GOT_LONG:
2306-
case UTF8_GOT_LONG_WITH_VALUE:
2306+
case UTF8_GOT_LONG_BIT_POS_:
2307+
case UTF8_GOT_LONG_WITH_VALUE_BIT_POS_:
23072308
COMMON_DEFAULT_REJECTS(,);
23082309

23092310
/* These error types cause 'input_uv' to be something that
@@ -2379,7 +2380,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23792380
continue; \
23802381
}
23812382

2382-
case UTF8_GOT_SURROGATE:
2383+
case UTF8_GOT_SURROGATE_BIT_POS_:
23832384
COMMON_DEFAULT_ACCEPTEDS(UTF8_WARN_SURROGATE,
23842385
WARN_SURROGATE,,);
23852386

@@ -2397,7 +2398,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
23972398

23982399
break;
23992400

2400-
case UTF8_GOT_NONCHAR:
2401+
case UTF8_GOT_NONCHAR_BIT_POS_:
24012402
COMMON_DEFAULT_ACCEPTEDS(UTF8_WARN_NONCHAR, WARN_NONCHAR,,);
24022403

24032404
/* The code above should have guaranteed that we don't get here
@@ -2429,21 +2430,21 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
24292430
bool overflows;
24302431
bool is_extended;
24312432

2432-
case UTF8_GOT_OVERFLOW:
2433+
case UTF8_GOT_OVERFLOW_BIT_POS_:
24332434
COMMON_DEFAULT_REJECTS(ckWARN_d, WARN_NON_UNICODE);
24342435
overflows = true;
24352436
is_extended = true;
24362437
goto super_common;
24372438

2438-
case UTF8_GOT_PERL_EXTENDED:
2439+
case UTF8_GOT_PERL_EXTENDED_BIT_POS_:
24392440
COMMON_DEFAULT_ACCEPTEDS(UTF8_WARN_PERL_EXTENDED,
24402441
WARN_NON_UNICODE, ckWARN_d,
24412442
WARN_PORTABLE);
24422443
overflows = orig_problems & UTF8_GOT_OVERFLOW;
24432444
is_extended = true;
24442445
goto super_common;
24452446

2446-
case UTF8_GOT_SUPER:
2447+
case UTF8_GOT_SUPER_BIT_POS_:
24472448
COMMON_DEFAULT_ACCEPTEDS(UTF8_WARN_SUPER, WARN_NON_UNICODE,,);
24482449
overflows = orig_problems & UTF8_GOT_OVERFLOW;
24492450
is_extended = UTF8_IS_PERL_EXTENDED(s0);

0 commit comments

Comments
 (0)