bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speeding up `wc -m`


From: Pádraig Brady
Subject: Re: speeding up `wc -m`
Date: Sun, 24 Jun 2018 11:41:49 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 24/06/18 07:24, Bruno Haible wrote:
> Pádraig Brady wrote:
>> I'm going to apply my whar-single module to gnulib to tweak
>> it so the main bottleneck of calling locale_charset repeatedly
>> is removed from wcwidth() and mbrtowc(), in a simple manner,
>> without the need for another API.
> 
> This patch has two problems:
> 
> 1) It introduces a test suite failure: A gnulib testdir
>    ./gnulib-tool --create-testdir --dir=... --single-configure mbrtowc 
> wcwidth wchar-single
>    fails the test-wcwidth test (test-wcwidth.c:59) on Mac OS X.
> 
> 2) It introduces a multithread-safety bug: You added 'static' variables
>    also to the normal (non-singlethreaded) code path. Now, when you have
>    two threads which operate in different locales (via uselocale()) and
>      1. thread1 does encoding = locale_charset ();
>      2. thread2 does encoding = locale_charset ();
>      3. thread1 does utf8_charset = STREQ_OPT (encoding, ...);
>    you've got a bug.
>    To eliminate such kinds of bugs, it is better to structure the code as 
> follows:
>      - A function that returns that value that can be cached.
>      - A function that does the caching AND NOTHING ELSE. So that it can be 
> #ifdefed
>        out easily.
>      - Code that uses the caching function. Do not add complexity here!

Excellent. Thanks for pushing those fixes!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]