Efficient Substr implementation 10 May, 2010 Efficient Substr implementation

I came up with this implementation of substring method. Anyone got ideas to make it more terse and more efficient?

bool substring(const char* str, const char* substr){
    const char *currentString = str, *backTrackString = str, *currSubstr = substr;
    while( strlen(backTrackString) >= strlen(substr) ){
        while( *currSubstr && *currentString++ == *currSubstr++);
        if( !*currSubstr ) return true;
        currentString = backTrackString++;
        currSubstr = substr;
    return false;

In particular, can we do without atleast one of the local variables - while still being as efficient or better? A more basic question - so you think this is efficient?

Tags  ·   algorithm  ·   Show Comments ▾

Original design for Tumblr crafted by Prashanth Kamalakanthan.
Adapted for Tumblr & Jekyll by Sai Charan. Customized theme available on Github.

Sai Charan's blog by Sai Charan is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Creative Commons License