2 ms·
Still, what's wrong with toupper(), besides not getting to show off that you know the archaic characteristics of ASCII? (Not that I'm free from that sin of brag
by ptaipale 12y ago
Still, what's wrong with toupper(), besides not getting to show off that you know the archaic characteristics of ASCII? (Not that I'm free from that sin of bragging myself, of course.)
Library functions provide idiomatic, readable ways to do things.
- gumby 12y agoOf course you should use toupper(). toupper is great and handles all sorts of corner cases. The person who would use a hack like this and case already used toupper here. But toupper is slower AND that slowness is unnecessary in some cases. These are the kind of optimizations you use after you have revisited your algorithms, after you have profiled your code, and when you know you have a code path that is heavily used, where saving a few cycles really does have big gains. If I were writing the parser front end for GMAIL's SMTP server, for example, a micro optimization like this could pay off. Or (more likely in my case) when I have an embedded device with only 4K of program memory that nevertheless needs to talk to a syslog or time server and still perform its normal function. This is not a "party trick" optimization a la HAKMEM. And that's not an "archaic characteristic of ASCII" it shows thoughtful design from an age of specific resource constraints. We don't have those constraints now, but we have others and this is a good example of how they can manifest themselves, and be designed for. And for that matter it shows why, for all that I hate it, ASCII itself is not archaic.