From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: ruby-io-splice@bogomips.org Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 0258E1FA58; Sat, 10 Jan 2015 03:44:49 +0000 (UTC) From: Eric Wong To: ruby-io-splice@bogomips.org Cc: Eric Wong Subject: [PATCH] favor comparisons against zero instead of -1 Date: Sat, 10 Jan 2015 03:44:47 +0000 Message-Id: <1420861487-5332-1-git-send-email-e@80x24.org> X-Mailer: git-send-email 2.2.1.203.g624e5c2 List-Id: This should allow faster instructions to be used in some cases. Technically this may be less pedantically correct, but there is enough existing code out there which does the same thing to discourage kernel/libc developers from overloading negative return values. ...And glibc even favors comparison against zero, too. --- ext/io_splice/io_splice_ext.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c index 276f3a6..97f744c 100644 --- a/ext/io_splice/io_splice_ext.c +++ b/ext/io_splice/io_splice_ext.c @@ -167,7 +167,7 @@ static ssize_t do_splice(int argc, VALUE *argv, unsigned dflags) a.fd_in = check_fileno(io_in); a.fd_out = check_fileno(io_out); bytes = (ssize_t)io_run(nogvl_splice, &a); - if (bytes == -1) { + if (bytes < 0) { if (errno == EINTR) continue; if (waitall && errno == EAGAIN) { @@ -238,7 +238,7 @@ static VALUE my_splice(int argc, VALUE *argv, VALUE self) if (n == 0) rb_eof_error(); - if (n == -1) + if (n < 0) rb_sys_fail("splice"); return SSIZET2NUM(n); } @@ -264,7 +264,7 @@ static VALUE trysplice(int argc, VALUE *argv, VALUE self) if (n == 0) return Qnil; - if (n == -1) { + if (n < 0) { if (errno == EAGAIN) return sym_EAGAIN; rb_sys_fail("splice"); @@ -309,7 +309,7 @@ static ssize_t do_tee(int argc, VALUE *argv, unsigned dflags) a.fd_in = check_fileno(io_in); a.fd_out = check_fileno(io_out); bytes = (ssize_t)io_run(nogvl_tee, &a); - if (bytes == -1) { + if (bytes < 0) { if (errno == EINTR) continue; if (waitall && errno == EAGAIN) { @@ -366,7 +366,7 @@ static VALUE my_tee(int argc, VALUE *argv, VALUE self) if (n == 0) rb_eof_error(); - if (n == -1) + if (n < 0) rb_sys_fail("tee"); return SSIZET2NUM(n); @@ -391,7 +391,7 @@ static VALUE trytee(int argc, VALUE *argv, VALUE self) if (n == 0) return Qnil; - if (n == -1) { + if (n < 0) { if (errno == EAGAIN) return sym_EAGAIN; rb_sys_fail("tee"); @@ -520,7 +520,7 @@ static VALUE my_vmsplice(int argc, VALUE * argv, VALUE self) a.fd = check_fileno(io); n = (ssize_t)io_run(nogvl_vmsplice, &a); - if (n == -1) { + if (n < 0) { if (errno == EAGAIN) { if (a.flags & SPLICE_F_NONBLOCK) rb_sys_fail("vmsplice"); -- 2.2.1.203.g624e5c2