Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ncar!ico!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: strstr sources: a summary of responses Keywords: ANSI lib, strstr Message-ID: <17546@haddock.ima.isc.com> Date: 28 Aug 90 02:43:54 GMT References: <1158@umvlsi.ecs.umass.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 15 In article <1158@umvlsi.ecs.umass.edu> srivasta@umvlsi.ecs.umass.edu writes: >[From the comments introducing John Lacey's Boyer-Moore code:] > Some rough timings found this implementation about twice as fast as > the following straight string search. ... > while ( text[i] && pattern[j] ) { > i++; > j = ( text[i] == pattern[j] ) ? j + 1 : 0; > } I hope it's also more correct. As written, this won't even handle strstr("a", "a"); and even if you put the increment in a more likely place, there's no provision for doing less than a full reset of the search--so strstr("ababac", "abac") loses. Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint