This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Suggestions for more built-ins.


I don't really know how to add these, but strchr() is a function I use
very often, and which is definitely amenable to optimization opportunities:

- strchr(p, '\0') == p + strlen(p)
(This is probably just a question of recognizing the '\0' and reproducing
whatever builtin strlen does)

- strchr(constant_string, c) is a nice short-hand for checking whether a
character belongs to a small charset... There are several possible
optimizations there. For small constant_string, it's probably easiest to
compare c to each character individually. For larger one, a switch-like
construct ? Or maybe, if the construct is frequent enough, going directly
to an isxxx-like array would be the solution ?

The first optimization would be of special interest to me, and probably
a few others: right now, gcc is better at optimizing p + strlen(p) than
strchr(p, '\0'), which would tend to make me change back a nice idiom to 
something which is somewhat less legible...
-- 
	Marc Espie		
|anime, sf, juggling, unicycle, acrobatics, comics...
|AmigaOS, OpenBSD, C++, perl, Icon, PostScript...
| `real programmers don't die, they just get out of beta'

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]