Re: [dev] [PATCH][RFC] Add a basic version of tr

From: sin <sin_AT_2f30.org>
Date: Wed, 15 Jan 2014 11:27:23 +0000

On Tue, Jan 14, 2014 at 09:35:11AM +0100, Silvan Jegen wrote:
> 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.

How slow is it currently? Can you provide your benchmark measurements?
Most tools in sbase are really not what I'd call blazingly fast and
that is not the point. I like to keep things simple and reliable
as much as possible. If we can optimize it without sacrificing simplicity
then go for it.

I do not think inlining makes sense here at all.

bye,
sin
Received on Wed Jan 15 2014 - 12:27:23 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 15 2014 - 12:36:13 CET