[PATCH 5/5] usp10: Use bsearch() to lookup the script range in get_char_script().
Aric Stewart
aric at codeweavers.com
Wed Mar 8 07:44:40 CST 2017
Signed-off-by: Aric Stewart <aric at codeweavers.com>
On 3/7/17 1:57 AM, Henri Verbeet wrote:
> Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
> ---
> dlls/usp10/usp10.c | 45 +++++++++++++++++++++++----------------------
> dlls/usp10/usp10_internal.h | 3 +++
> 2 files changed, 26 insertions(+), 22 deletions(-)
>
> diff --git a/dlls/usp10/usp10.c b/dlls/usp10/usp10.c
> index 6711347..8a8a62f 100644
> --- a/dlls/usp10/usp10.c
> +++ b/dlls/usp10/usp10.c
> @@ -43,7 +43,7 @@
>
> WINE_DEFAULT_DEBUG_CHANNEL(uniscribe);
>
> -static const struct
> +static const struct usp10_script_range
> {
> enum usp10_script script;
> DWORD rangeFirst;
> @@ -51,7 +51,7 @@ static const struct
> enum usp10_script numericScript;
> enum usp10_script punctScript;
> }
> -scriptRanges[] =
> +script_ranges[] =
> {
> /* Basic Latin: U+0000–U+007A */
> { Script_Latin, 0x00, 0x07a , Script_Numeric, Script_Punctuation},
> @@ -296,8 +296,6 @@ scriptRanges[] =
> { Script_Osmanya, 0x10480, 0x104AF, Script_Osmanya_Numeric, 0},
> /* Mathematical Alphanumeric Symbols: U+1D400–U+1D7FF */
> { Script_MathAlpha, 0x1D400, 0x1D7FF, 0, 0},
> - /* END */
> - { SCRIPT_UNDEFINED, 0, 0, 0}
> };
>
> /* this must be in order so that the index matches the Script value */
> @@ -888,13 +886,25 @@ static inline DWORD decode_surrogate_pair(LPCWSTR str, INT index, INT end)
> return 0;
> }
>
> +static int usp10_compare_script_range(const void *key, const void *value)
> +{
> + const struct usp10_script_range *range = value;
> + const DWORD *ch = key;
> +
> + if (*ch < range->rangeFirst)
> + return -1;
> + if (*ch > range->rangeLast)
> + return 1;
> + return 0;
> +}
> +
> static enum usp10_script get_char_script(const WCHAR *str, unsigned int index,
> unsigned int end, unsigned int *consumed)
> {
> static const WCHAR latin_punc[] = {'#','$','&','\'',',',';','<','>','?','@','\\','^','_','`','{','|','}','~', 0x00a0, 0};
> + struct usp10_script_range *range;
> WORD type = 0, type2 = 0;
> DWORD ch;
> - int i;
>
> *consumed = 1;
>
> @@ -936,24 +946,15 @@ static enum usp10_script get_char_script(const WCHAR *str, unsigned int index,
> else
> ch = str[index];
>
> - i = 0;
> - do
> - {
> - if (ch < scriptRanges[i].rangeFirst || scriptRanges[i].script == SCRIPT_UNDEFINED)
> - break;
> -
> - if (ch >= scriptRanges[i].rangeFirst && ch <= scriptRanges[i].rangeLast)
> - {
> - if (scriptRanges[i].numericScript && (type & C1_DIGIT || type2 == C2_ARABICNUMBER))
> - return scriptRanges[i].numericScript;
> - if (scriptRanges[i].punctScript && type & C1_PUNCT)
> - return scriptRanges[i].punctScript;
> - return scriptRanges[i].script;
> - }
> - i++;
> - } while (1);
> + if (!(range = bsearch(&ch, script_ranges, ARRAY_SIZE(script_ranges),
> + sizeof(*script_ranges), usp10_compare_script_range)))
> + return Script_Undefined;
>
> - return SCRIPT_UNDEFINED;
> + if (range->numericScript && (type & C1_DIGIT || type2 == C2_ARABICNUMBER))
> + return range->numericScript;
> + if (range->punctScript && type & C1_PUNCT)
> + return range->punctScript;
> + return range->script;
> }
>
> static int compare_FindGlyph(const void *a, const void* b)
> diff --git a/dlls/usp10/usp10_internal.h b/dlls/usp10/usp10_internal.h
> index dd1b9fa..989620d 100644
> --- a/dlls/usp10/usp10_internal.h
> +++ b/dlls/usp10/usp10_internal.h
> @@ -24,6 +24,9 @@
> ( (ULONG)_x2 << 8 ) | \
> (ULONG)_x1 )
>
> +#ifndef ARRAY_SIZE
> +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
> +#endif
>
> enum usp10_script
> {
>
More information about the wine-patches
mailing list