Skip to content

Commit 7425e7c

Browse files
committed
utf8.h: Add UNICODE_IS_NONCHAR_GIVEN_NOT_SUPER
If we already know the input is a Unicode code point, we can save a conditional in checking if it is a Unicode non-character code point.
1 parent b71c4dd commit 7425e7c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

regexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11658,7 +11658,7 @@ Perl_is_grapheme(pTHX_ const U8 * strbeg, const U8 * s, const U8 * strend, const
1165811658
PERL_ARGS_ASSERT_IS_GRAPHEME;
1165911659

1166011660
if ( UNLIKELY(UNICODE_IS_SUPER(cp))
11661-
|| UNLIKELY(UNICODE_IS_NONCHAR(cp)))
11661+
|| UNLIKELY(UNICODE_IS_NONCHAR_GIVEN_NOT_SUPER(cp)))
1166211662
{
1166311663
/* These are considered graphemes */
1166411664
return true;

utf8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
19521952
possible_problems |= UTF8_GOT_SUPER;
19531953
}
19541954
}
1955-
else if (UNLIKELY(UNICODE_IS_NONCHAR(uv))) {
1955+
else if (UNLIKELY(UNICODE_IS_NONCHAR_GIVEN_NOT_SUPER(uv))) {
19561956
if (flags & (UTF8_DISALLOW_NONCHAR|UTF8_WARN_NONCHAR)) {
19571957
possible_problems |= UTF8_GOT_NONCHAR;
19581958
}

utf8.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,11 +1112,13 @@ non-character code points
11121112
* the Unicode legal max */
11131113
#define UNICODE_IS_END_PLANE_NONCHAR_GIVEN_NOT_SUPER(uv) \
11141114
UNLIKELY(((UV) (uv) & 0xFFFE) == 0xFFFE)
1115+
#define UNICODE_IS_NONCHAR_GIVEN_NOT_SUPER(uv) \
1116+
( UNLIKELY(UNICODE_IS_32_CONTIGUOUS_NONCHARS(uv)) \
1117+
|| UNLIKELY(UNICODE_IS_END_PLANE_NONCHAR_GIVEN_NOT_SUPER(uv)))
11151118

11161119
#define UNICODE_IS_NONCHAR(uv) \
1117-
( UNLIKELY(UNICODE_IS_32_CONTIGUOUS_NONCHARS(uv)) \
1118-
|| ( UNLIKELY(UNICODE_IS_END_PLANE_NONCHAR_GIVEN_NOT_SUPER(uv)) \
1119-
&& LIKELY(! UNICODE_IS_SUPER(uv))))
1120+
( LIKELY(! UNICODE_IS_SUPER(uv)) \
1121+
&& UNLIKELY(UNICODE_IS_NONCHAR_GIVEN_NOT_SUPER(uv)))
11201122

11211123
/*
11221124
=for apidoc Am|bool|UTF8_IS_NONCHAR|const U8 *s|const U8 *e

0 commit comments

Comments
 (0)