On Wednesday 07 February 2007 16:13, Steve wrote:
> Turns out I had to create an assignment to get it function as I wanted.
>
> s[y] = ~s[y];
Yes, that would seem more correct.
[snip]
> inline void flip(std::string& s){
> int y = 0;
> while(y++ < s.length()){
> s[y] = ~s[y];
> }
> }
Try this optimization:
inline void flip(std::string& s) {
int len = s.length(); // compute the string length only once
for (int y = 0; y < len; y++) {
s[y] = ~s[y];
}
}
Depending on how std::string.length() is implemented, the compiler may already
have been able to do this optimization for you. You can test by comparing
both sets of code with optimizations turned off.
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/