Sahil Malik said:
Or simply this -- (char)((int)letter + 1) ;
Rule - always avoid calling a method for performance reasons. Calling a
method means push/pop of all local stack variables - very painful for the
CPU.
This rule is **very** debatable. I would propose instead:
Rule 1: Always introduce a method when you have identified a piece of code
that could be reused instead of duplicating the code everywhere, especially
if the method body is a bit obscure (like the double cast that you have to
do to get the next letter).
Rule 2: If you identify a performance bottleneck with a profiler, try to
inline the method and see if it makes a difference (if it does not, keep the
method, the problem is elsewhere).
Also, calling a method does not "push/pop all local stack variables" (which
leads to think that all the variables are copied in the process), it pushes
and pops a "stack frame", which is a very simple and very fast operation.
Inlining code often leads to less efficient code, simply because the code
gets bigger and you start to get trashing in the CPU cache.
Bruno.