1 /* Copyright (C) 1994, 1999 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 * My personal strstr() implementation that beats most other algorithms.
20 * Until someone tells me otherwise, I assume that this is the
21 * fastest implementation of strstr() in C.
22 * I deliberately chose not to comment it. You should have at least
23 * as much fun trying to understand it, as I had to write it :-).
25 * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
32 #include <sys/types.h>
34 typedef unsigned chartype
;
37 strstr (const char *phaystack
, const char *pneedle
)
39 register const unsigned char *haystack
, *needle
;
40 register chartype b
, c
;
42 haystack
= (const unsigned char *) phaystack
;
43 needle
= (const unsigned char *) pneedle
;
48 haystack
--; /* possible ANSI violation */
66 register const unsigned char *rhaystack
, *rneedle
;
88 rhaystack
= haystack
-- + 1;
106 while (*rhaystack
== a
);
108 needle
= rneedle
; /* took the register-poor aproach */
115 return (char*) haystack
;