From 56f4184622ebb39e21fe704cef486d64ea242fa0 Mon Sep 17 00:00:00 2001 From: Erwin Janssen Date: Mon, 9 Jan 2017 13:11:52 +0100 Subject: [PATCH] Assume default memchr and memcpy are fast enough `features/sfio` contains some test that check if the default memchr and memcpy are "fast enough". These days we can safely assume that this is the case, also because this define is always enabled when running the tests. --- lib/sfio/features/sfio | 81 ------------------------------------------ lib/sfio/sfgetr.c | 6 ---- lib/sfio/sfputr.c | 6 ---- 3 files changed, 93 deletions(-) diff --git a/lib/sfio/features/sfio b/lib/sfio/features/sfio index 20fd54053..0ac0ca14f 100644 --- a/lib/sfio/features/sfio +++ b/lib/sfio/features/sfio @@ -33,87 +33,6 @@ exit cleanup note{ stuck with standard _cleanup }end execute{ main() { printf("cleanup\n"); exit(1); } }end -lib memchr note{ see if memchr is fast }end execute{ - #include - #include - #include - - main() - { struct tms stm1, etm1, stm2, etm2; - register int i, p; - register char *s, *ends; - long t1, t2; - char buf[128]; - - for(p = 0; p < 100; ++p) - buf[p] = '0' + (p%10); - buf[p++] = '\n'; - buf[p] = 0; - - times(&stm1); - for(i = 0; i < 100000; ++i) - s = memchr(buf,'\n',p); - times(&etm1); - - times(&stm2); - for(i = 0; i < 100000; ++i) - { ends = (s = buf) + p; - while(*s != '\n') - if((s += 1) == ends) - break; - } - times(&etm2); - - t1 = (etm1.tms_utime - stm1.tms_utime) + - (etm1.tms_stime - stm1.tms_stime); - t2 = (etm2.tms_utime - stm2.tms_utime) + - (etm2.tms_stime - stm2.tms_stime); - - return t1 < t2 ? 0 : 1; - } -}end - -lib memccpy note{ see if memccpy is fast }end execute{ - #include - #include - #include - - main() - { struct tms stm1, etm1, stm2, etm2; - register int i, p; - register char *s1, *s2; - long t1, t2; - char buf1[128], buf2[128]; - - for(i = 0; i < 100; ++i) - buf1[i] = '0' + (i%10); - buf1[i++] = '\n'; - buf1[i] = 0; - - times(&stm1); - for(i = 0; i < 100000; ++i) - { p = 128; - memccpy(buf2,buf1,'\n',p); - } - times(&etm1); - - times(&stm2); - for(i = 0; i < 100000; ++i) - { s1 = buf1; s2 = buf2; p = 128; - while((*s2++ = *s1++) != '\n' && --p > 0) - ; - } - times(&etm2); - - t1 = (etm1.tms_utime - stm1.tms_utime) + - (etm1.tms_stime - stm1.tms_stime); - t2 = (etm2.tms_utime - stm2.tms_utime) + - (etm2.tms_stime - stm2.tms_stime); - - return t1 < t2 ? 0 : 1; - } -}end - sys stat note{ stat() in default lib(s) }end link{ #if _STD_ #include diff --git a/lib/sfio/sfgetr.c b/lib/sfio/sfgetr.c index 30fbcbce9..7b3ff11a3 100644 --- a/lib/sfio/sfgetr.c +++ b/lib/sfio/sfgetr.c @@ -72,14 +72,8 @@ char *sfgetr(reg Sfio_t * f, reg int rc, int type) } } } -#if _lib_memchr if (!(s = (uchar *) memchr((char *) s, rc, n))) s = ends; -#else - while (*s != rc) - if ((s += 1) == ends) - break; -#endif do_copy: if (s < ends) { s += 1; /* include the separator */ diff --git a/lib/sfio/sfputr.c b/lib/sfio/sfputr.c index ecde41431..43dd16844 100644 --- a/lib/sfio/sfputr.c +++ b/lib/sfio/sfputr.c @@ -76,17 +76,11 @@ ssize_t sfputr(reg Sfio_t * f, const char *s, reg int rc) w += 1; break; } -#if _lib_memccpy if ((ps = (uchar *) memccpy(ps, s, '\0', p)) != NIL(uchar *)) ps -= 1; else ps = f->next + p; s += ps - f->next; -#else - for (; p > 0; --p, ++ps, ++s) - if ((*ps = *s) == 0) - break; -#endif w += ps - f->next; f->next = ps; } -- 2.40.0