1 /* Copyright (C) 1994 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 */
28 #include <sys/types.h>
30 typedef unsigned chartype
;
33 strstr (const char *phaystack
, const char *pneedle
)
35 register const unsigned char *haystack
, *needle
;
36 register chartype b
, c
;
38 haystack
= (const unsigned char *) phaystack
;
39 needle
= (const unsigned char *) pneedle
;
44 haystack
--; /* possible ANSI violation */
62 register const unsigned char *rhaystack
, *rneedle
;
84 rhaystack
= haystack
-- + 1;
102 while (*rhaystack
== a
);
104 needle
= rneedle
; /* took the register-poor aproach */
111 return (char*) haystack
;