Proposal for Optimized Character Type Function
enh
enh@google.com
Sat Mar 1 19:34:25 GMT 2025
you should benchmark this --- on modern cpus, the opposite is true.
indeed, Android moved in the opposite direction (though we do still
leave the legacy table visible for app compat reasons).
On Sat, Mar 1, 2025 at 2:28 PM The Cuthour <cuthour@gmail.com> wrote:
>
> Hi,
>
> I am writing to propose an enhancement to the character type functions
> such as isalpha(), isupper(), and islower() through the use of optimized
> lookup tables. By using a single lookup table with bitwise operations,
> we can achieve efficient and concise implementations for these
> functions. Below is a brief overview of the proposed implementation:
>
> unsigned char type_table[256] = {
> // ... initialization
> };
>
> const bool my_islower(const unsigned char ch) {
> return type_table[ch] & 0x01;
> }
>
> const bool my_isupper(const unsigned char ch) {
> return type_table[ch] & 0x02;
> }
>
> const bool my_isalpha(const unsigned char ch) {
> return type_table[ch] & 0x03;
> }
>
> This approach leverages a lookup table with predefined values, enabling
> fast and straightforward character type determination using bitwise
> operations. This method is not only efficient but also simplifies the
> code and enhances readability.
More information about the Libc-alpha
mailing list