shithub: riscv

Download patch

ref: 761bf6c3477b2bef675c20aad954acae02b923ed
parent: 47cff2e833604ecf7e8f2742911efb444e2b912e
author: Amavect <amavect@gmail.com>
date: Sun May 22 18:38:11 EDT 2022

shorten strchr and runestrchr

--- a/sys/src/libc/port/runestrchr.c
+++ b/sys/src/libc/port/runestrchr.c
@@ -4,17 +4,14 @@
 Rune*
 runestrchr(Rune *s, Rune c)
 {
-	Rune c0 = c;
-	Rune c1;
+	Rune r;
 
-	if(c == 0) {
+	if(c == 0)
 		while(*s++)
 			;
-		return s-1;
-	}
-
-	while(c1 = *s++)
-		if(c1 == c0)
-			return s-1;
-	return 0;
+	else
+		while((r = *s++) != c)
+			if(r == 0)
+				return 0;
+	return s-1;
 }
--- a/sys/src/libc/port/strchr.c
+++ b/sys/src/libc/port/strchr.c
@@ -4,17 +4,14 @@
 char*
 strchr(char *s, int c)
 {
-	char c0 = c;
-	char c1;
+	char r;
 
-	if(c == 0) {
+	if(c == 0)
 		while(*s++)
 			;
-		return s-1;
-	}
-
-	while(c1 = *s++)
-		if(c1 == c0)
-			return s-1;
-	return 0;
+	else
+		while((r = *s++) != c)
+			if(r == 0)
+				return 0;
+	return s-1;
 }