Skip to content

Commit

Permalink
utf8.c: Make new static fcn more flexible
Browse files Browse the repository at this point in the history
This commit allows this function to be called with NULL parameters when
the result of these is not needed.
  • Loading branch information
khwilliamson committed Aug 16, 2021
1 parent a0446ed commit 0726078
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions embed.fnc
Expand Up @@ -2500,8 +2500,8 @@ S |void |warn_on_first_deprecated_use \
|const unsigned line
#endif
S |UV |to_case_cp_list|const UV original \
|NN const U32 ** const remaining_list \
|NN Size_t * remaining_count \
|NULLOK const U32 ** const remaining_list \
|NULLOK Size_t * remaining_count \
|NN SV *invlist \
|NN const I32 * const invmap \
|NULLOK const U32 * const * const aux_tables \
Expand Down
2 changes: 1 addition & 1 deletion proto.h
Expand Up @@ -6670,7 +6670,7 @@ STATIC HV * S_new_msg_hv(pTHX_ const char * const message, U32 categories, U32 f

STATIC UV S_to_case_cp_list(pTHX_ const UV original, const U32 ** const remaining_list, Size_t * remaining_count, SV *invlist, const I32 * const invmap, const U32 * const * const aux_tables, const U8 * const aux_table_lengths, const char * const normal);
#define PERL_ARGS_ASSERT_TO_CASE_CP_LIST \
assert(remaining_list); assert(remaining_count); assert(invlist); assert(invmap); assert(normal)
assert(invlist); assert(invmap); assert(normal)
STATIC U8 S_to_lower_latin1(const U8 c, U8 *p, STRLEN *lenp, const char dummy)
__attribute__warn_unused_result__;
#define PERL_ARGS_ASSERT_TO_LOWER_LATIN1
Expand Down
28 changes: 22 additions & 6 deletions utf8.c
Expand Up @@ -3178,10 +3178,16 @@ S_to_case_cp_list(pTHX_ const UV original,
I32 base;

/* Return the changed case of code point 'original'. The first code point of
* the changed case is returned; *remaining_count will be set to how many
* other code points are in the changed case. If it is non-zero,
* *remaining_list will point to a non-modifiable array containing them;
* if zero, *remaining_list is undefined.
* the changed case is returned.
*
* If 'remaining_count' is not NULL, *remaining_count will be set to how
* many other code points are in the changed case. If non-zero and
* 'remaining_list' is also not NULL, *remaining_list will be set to point
* to a non-modifiable array containing the second and potentially third
* code points in the changed case. (Unicode guarantees a maximum of 3.)
* Note that this means that *remaining_list is undefined unless there are
* multiple code points, and the caller has chosen to find out how many by
* making 'remaining_count' not NULL.
*
* 'normal' is a string to use to name the new case in any generated
* messages, as a fallback if the operation being used is not available.
Expand All @@ -3197,6 +3203,11 @@ S_to_case_cp_list(pTHX_ const UV original,
index = _invlist_search(invlist, original);
base = invmap[index];

/* Most likely, the case change will contain just a single code point */
if (remaining_count) {
*remaining_count = 0;
}

if (LIKELY(base == 0)) { /* 0 => original was unchanged by casing */

/* At this bottom level routine is where we warn about illegal code
Expand Down Expand Up @@ -3243,8 +3254,13 @@ S_to_case_cp_list(pTHX_ const UV original,
* the first entry in the *remaining returns, as it is returned by the
* function. */
base = -base;
*remaining_list = aux_tables[base] + 1;
*remaining_count = (Size_t) (aux_table_lengths[base] - 1);
if (remaining_count) {
*remaining_count = (Size_t) (aux_table_lengths[base] - 1);

if (remaining_list) {
*remaining_list = aux_tables[base] + 1;
}
}

return (UV) aux_tables[base][0];
}
Expand Down

0 comments on commit 0726078

Please sign in to comment.