|
Last change
on this file since 1813 was 1813, checked in by bird, 16 years ago |
|
kmk: inline memchr everywhere but on linux.
|
-
Property svn:eol-style
set to
native
-
Property svn:keywords
set to
Id
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | #include <string.h>
|
|---|
| 2 | static __inline__ void *
|
|---|
| 3 | my_inline_memchr(const void *pv, int ch, register size_t cb)
|
|---|
| 4 | {
|
|---|
| 5 | register const unsigned int uch = (unsigned)ch;
|
|---|
| 6 | register const unsigned char *pb = (const unsigned char *)pv;
|
|---|
| 7 | #if 1
|
|---|
| 8 | while (cb >= 4)
|
|---|
| 9 | {
|
|---|
| 10 | if (*pb == uch)
|
|---|
| 11 | return (unsigned char *)pb;
|
|---|
| 12 | if (pb[1] == uch)
|
|---|
| 13 | return (unsigned char *)pb + 1;
|
|---|
| 14 | if (pb[2] == uch)
|
|---|
| 15 | return (unsigned char *)pb + 2;
|
|---|
| 16 | if (pb[3] == uch)
|
|---|
| 17 | return (unsigned char *)pb + 3;
|
|---|
| 18 | cb -= 4;
|
|---|
| 19 | pb += 4;
|
|---|
| 20 | }
|
|---|
| 21 | switch (cb & 3)
|
|---|
| 22 | {
|
|---|
| 23 | case 0:
|
|---|
| 24 | break;
|
|---|
| 25 | case 1:
|
|---|
| 26 | if (*pb == uch)
|
|---|
| 27 | return (unsigned char *)pb;
|
|---|
| 28 | break;
|
|---|
| 29 | case 2:
|
|---|
| 30 | if (*pb == uch)
|
|---|
| 31 | return (unsigned char *)pb;
|
|---|
| 32 | if (pb[1] == uch)
|
|---|
| 33 | return (unsigned char *)pb + 1;
|
|---|
| 34 | break;
|
|---|
| 35 | case 3:
|
|---|
| 36 | if (*pb == uch)
|
|---|
| 37 | return (unsigned char *)pb;
|
|---|
| 38 | if (pb[1] == uch)
|
|---|
| 39 | return (unsigned char *)pb + 1;
|
|---|
| 40 | if (pb[2] == uch)
|
|---|
| 41 | return (unsigned char *)pb + 2;
|
|---|
| 42 | break;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | #else
|
|---|
| 46 | while (cb > 0)
|
|---|
| 47 | {
|
|---|
| 48 | if (*pb == uch)
|
|---|
| 49 | return (void *)pb;
|
|---|
| 50 | cb--;
|
|---|
| 51 | pb++;
|
|---|
| 52 | }
|
|---|
| 53 | #endif
|
|---|
| 54 | return 0;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | #define memchr my_inline_memchr
|
|---|
| 58 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.