shithub: mc

Download patch

ref: dbf04d054d0fc04385c766ced8e0f3b3edd120e8
parent: e65d5c4019e76430398e4ebc1cb734f1efea3b14
author: Ori Bernstein <ori@markovcorp.com>
date: Sat Mar 10 13:16:21 EST 2018

Clean up readinto.

--- a/lib/bio/bio.myr
+++ b/lib/bio/bio.myr
@@ -365,7 +365,7 @@
 		/* get at least delimiter count of characters */
 		match ensureread(f, 1)
 		| `std.Err `Eof:
-			ret = readinto(f, ret, f.rend - f.rstart)
+			readinto(f, &ret, f.rend - f.rstart)
 			if ret.len > 0
 				-> `std.Ok ret
 			else
@@ -378,7 +378,7 @@
 		for var i = f.rstart; i < f.rend; i++
 			c = (f.rbuf[i] : char)
 			if c == '\r' || c == '\n'
-				ret = readinto(f, ret, i - f.rstart)
+				readinto(f, &ret, i - f.rstart)
 				f.rstart++
 				/* if we have '\r', we can get '\r\n'. */
 				if c == '\r' && unwrapc(peekc(f), -1) == '\n'
@@ -388,7 +388,7 @@
 			;;
 :nextitergetln
 		;;
-		ret = readinto(f, ret, f.rend - f.rstart)
+		readinto(f, &ret, f.rend - f.rstart)
 	;;
 	std.die("unreachable")
 }
@@ -409,7 +409,7 @@
 		match ensureread(f, 1)
 		| `std.Err `Eof:
 			if !drop
-				ret = readinto(f, ret, f.rend - f.rstart)
+				readinto(f, &ret, f.rend - f.rstart)
 			else
 				f.rstart += f.rend - f.rstart
 			;;
@@ -429,7 +429,7 @@
 					;;
 				;;
 				if !drop
-					ret = readinto(f, ret, i - f.rstart)
+					readinto(f, &ret, i - f.rstart)
 				else
 					f.rstart += i - f.rstart
 				;;
@@ -439,7 +439,7 @@
 :nextiterread
 		;;
 		if !drop
-			ret = readinto(f, ret, f.rend - f.rstart)
+			readinto(f, &ret, f.rend - f.rstart)
 		else
 			f.rstart += f.rend - f.rstart
 		;;
@@ -476,13 +476,10 @@
 reads n bytes from the read buffer onto the heap-allocated slice
 provided.
 */
-const readinto = {f, buf, n
-	var ret
-
+const readinto = {f, bufp, n
 	std.assert(f.rstart + n <= f.rend, "Reading too much from buffer")
-	ret = std.sljoin(&buf, f.rbuf[f.rstart:f.rstart + n])
+	std.sljoin(bufp, f.rbuf[f.rstart:f.rstart + n])
 	f.rstart += n
-	-> ret
 }
 
 /* makes sure we can bufferedly write at least n bytes */