[PATCH squash] Simplify test-terminal.perl

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The File::Copy module is included with perl (since version 5.002,
1995), so this simplification comes for free.  It does not make the
test noticeably faster or slower.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
Jonathan Nieder wrote:
> it is much slower than the C version.

I take that back.  The perl version takes roughly 3.7 s and the
C version 3.4 s here (both with hot cache).  Noticeable alone, but a
tiny blip in the context of a full test run.

Sorry to mislead.

 t/t7006/test-terminal.perl |   26 +++++++-------------------
 1 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/t/t7006/test-terminal.perl b/t/t7006/test-terminal.perl
index b51cfc6..73ff809 100755
--- a/t/t7006/test-terminal.perl
+++ b/t/t7006/test-terminal.perl
@@ -2,8 +2,9 @@
 use strict;
 use warnings;
 use IO::Pty;
+use File::Copy;
 
-# Fork and execute @$argv with stdout redirected to $out.
+# Run @$argv in the background with stdout redirected to $out.
 sub start_child {
 	my ($argv, $out) = @_;
 	my $pid = fork;
@@ -37,26 +38,13 @@ sub finish_child {
 sub xsendfile {
 	my ($out, $in) = @_;
 
-	my $buf;
-
 	# Note: the real sendfile() cannot read from a terminal.
-	for (;;) {
-		my $n = sysread $in, $buf, 4096;
 
-		# It is unspecified by POSIX whether reads
-		# from a disconnected terminal will return
-		# EIO (as in AIX 4.x, IRIX, and Linux) or
-		# end-of-file.  Either is fine.
-		if (!defined($n) && $!{EIO}) {
-			return;
-		} elsif (!defined($n)) {
-			die "cannot read from child: $!";
-		} elsif ($n == 0) {
-			return;
-		} else {
-			print $out $buf or die "write error: $!";
-		}
-	}
+	# It is unspecified by POSIX whether reads
+	# from a disconnected terminal will return
+	# EIO (as in AIX 4.x, IRIX, and Linux) or
+	# end-of-file.  Either is fine.
+	copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!";
 }
 
 if ($#ARGV < 1) {
-- 
1.7.0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]