Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This looks wonky. Why are you writing a loop here?

    if (potentially_large_value >= 32) bit_pattern = 0;
    else bit_pattern = bit_pattern << potentially_large_value;
That does the same thing in constant time, and doesn't loop 2^27 times on bad input.


Simple, it preserves the algorithm. Just setting to 0 is conceptually a different thing.

I might also note that in the specific instance, potentially_large_value was the length of a string in memory.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: