Re: [dev] [PATCH][RFC] Add a basic version of tr
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.
-- qcar
Received on Tue Jan 14 2014 - 00:22:28 CET
This archive was generated by hypermail 2.3.0
: Tue Jan 14 2014 - 00:24:07 CET