Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Consider using look-up tables to increase execution speed (at the cost of some 200 bytes .rodata use). For example this: static const char specifiers[] = "diouxaefgcspAEFGX"; could be replaced wit...
Answer
#1: Initial revision
Consider using look-up tables to increase execution speed (at the cost of some 200 bytes .rodata use). For example this: static const char specifiers[] = "diouxaefgcspAEFGX"; could be replaced with static const bool specifiers[UCHAR_MAX] = { ['d'] = true, ['i'] = true, ... }; C guarantees that any specifier not mentioned in the above array initialization will get set to `false`. Then instead of the repeated slow `strchr` calls, you could simply do unsigned char ch = (unsigned char)*fmt; if(specifiers[ch]) The conversion to unsigned is defensive programming in case of signed `char` and 8 bit non-ASCII characters or a mangled `EOF` made it inside the string.