Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Thanks, looking back it's most probably too clever. Negative detection could simply be xneg = (x < 0); more readable and code generation would be same or better because it wouldn't confuse optimizers about the intent.
I love this solution. It is like a puzzle that needs to be solved. Clever.XD
You're welcome :D
But it's optimization theater, really. Most compilers optimize simple ?: expressions to branchless. I wrote it this way bc I was bored.
beutiful, thank you for gracing us with the prescense of such efficiency :D
In the last iteration you are writing out of bounds of
t
for oddlen
.Hmm. What happens if
folds
is 100 million?meh, tabs vs. spaces strike again..
Don't think so. Why would it?
Won't this access uninitalized memory if |len| is odd?
Just checked on Godbolt for GCC x86 and Clang Arm64, -O3 and they don't.
Even if they did, it still would be bad practice, there's no reason to add such cost in debug mode.
Besides, copy-pasting strlen(str) 3 times instead of putting it in one variable looks awful.
Pretty sure that modern compilers will optimise this away, as long as the length of the string isn't changed in the loop (or declaired as
volatile
).Call strlen for each iteration? How is this best practices??
It runs the same as n%2 because compilers turn it into a bit test, it only runs faster with optimizer turned off. I used it because once you're familiar with bit ops, it becomes a self-explanatory idiom.
clever use of bitshifting, probably runs very fast!
I accidentally left a printf; ignore this solution and look for my other one.
Loading more items...