Re: [dev] [PATCH][RFC] Add a basic version of tr
On Tue, Jan 14, 2014 at 12:22 AM, <q_AT_c9x.me> wrote:
> On Mon, Jan 13, 2014 at 11:19:49AM -0800, Silvan Jegen wrote:
>> I have rewritten "tr" to use mmap and the wchar.h functions. It seems
>> to be quite slow but as far as I can tell it works reasonably well (at
>> least when using a UTF-8 locale). Comments/review and testing welcome
>> (I am relatively new to C so beware)!
>>
>> + void (*mapfunc) (const wchar_t*, char*);
>> +
>> + setlocale(LC_ALL, "");
>> +
>> + mappings = (wchar_t *) mmap(NULL, 0x110000 * sizeof(wchar_t), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
>> +
>> + if(argc >= 2) {
>> + parse_mapping(argv[0], argv[1], mappings);
>> + mapfunc = map_to_set;
>> + } else {
>> + parse_mapping(argv[0], NULL, mappings);
>> + mapfunc = map_to_null;
>> + }
>> +
>> + while(afgets(&buf, &size, stdin))
>> + mapfunc(mappings, buf);
>
> Hi,
>
> if you want it to be faster I would suggest dropping the function
> pointer so the compiler can inline instead of doing an indirect
> call.
I wasn't aware of the performance implications when using a function pointer.
I will try to implement the function in a way that allows for it to be
inlined by the compiler and maybe do some measurements.
Thanks for the suggestion!
Cheers,
Silvan
Received on Tue Jan 14 2014 - 09:35:11 CET
This archive was generated by hypermail 2.3.0
: Tue Jan 14 2014 - 09:48:03 CET