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