speeded up a bit
authorceriel <none@none>
Wed, 22 Feb 1989 16:16:11 +0000 (16:16 +0000)
committerceriel <none@none>
Wed, 22 Feb 1989 16:16:11 +0000 (16:16 +0000)
lang/cem/libcc/gen/strcat.c
lang/cem/libcc/gen/strcmp.c
lang/cem/libcc/gen/strlen.c
lang/cem/libcc/gen/strncat.c
lang/cem/libcc/gen/strncmp.c

index f3aa4e5..5856d6a 100644 (file)
@@ -7,8 +7,9 @@ register char *s1, *s2;
   char *original = s1;
 
   /* Find the end of s1. */
-  while (*s1 != 0) s1++;
+  while (*s1++ != 0) ;
 
+  s1--;
   /* Now copy s2 to the end of s1. */
   while (*s1++ = *s2++) /* nothing */ ;
   return(original);
index 4f2c50f..7baa6f9 100644 (file)
@@ -1,16 +1,10 @@
 /* $Header$ */
-int strcmp(s1, s2)
-register char *s1, *s2;
+int
+strcmp(s, t)
+       register char *s, *t;
 {
-/* Compare 2 strings. */
-
-  for(;;) {
-       if (*s1 != *s2) {
-               if (!*s1) return -1;
-               if (!*s2) return 1;
-               return(*s1 - *s2);
-       }
-       if (*s1++ == 0) return(0);
-       s2++;
-  }
+       while (*s == *t++)
+               if (*s++ == '\0')
+                       return 0;
+       return *s - *--t;
 }
index 6232d6c..a22a054 100644 (file)
@@ -1,11 +1,11 @@
 /* $Header$ */
-int strlen(s)
-char *s;
+int
+strlen(s)
+       char *s;
 {
-/* Return length of s. */
+       register char *b = s;
 
-  char *original = s;
-
-  while (*s != 0) s++;
-  return(s - original);
+       while (*b++)
+               ;
+       return b - s - 1;
 }
index 96009bb..1ab7965 100644 (file)
@@ -10,7 +10,9 @@ int n;
   if (n <= 0) return(s1);
 
   /* Find the end of s1. */
-  while (*s1 != 0) s1++;
+  while (*s1++ != 0) ;
+
+  s1--;
 
   /* Now copy s2 to the end of s1. */
   while (*s1++ = *s2++) {
index 24e8d6e..c0dbc48 100644 (file)
@@ -1,19 +1,16 @@
 /* $Header$ */
 int
-strncmp(s1, s2, n)
-       register char *s1, *s2;
-       int n;
+strncmp(s, t, n)
+       register char *s, *t;
+       register int n;
 {
-/* Compare two strings, but at most n characters. */
-
-  while (n-- > 0) {
-       if (*s1 != *s2) {
-               if (!*s1) return -1;
-               if (!*s2) return 1;
-               return(*s1 - *s2);
+       while (n-- > 0) {
+               if (*s == *t++) {
+                       if (*s++ == '\0')
+                               return 0;
+               }
+               else
+                       return *s - *--t;
        }
-       if (*s1++ == 0) break;
-       s2++;
-  }
-  return 0;
+       return 0;
 }