io_splice RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: ruby-io-splice@bogomips.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] favor comparisons against zero instead of -1
Date: Sat, 10 Jan 2015 03:44:47 +0000	[thread overview]
Message-ID: <1420861487-5332-1-git-send-email-e@80x24.org> (raw)

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


                 reply	other threads:[~2015-01-10  3:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/ruby_io_splice/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420861487-5332-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=ruby-io-splice@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/ruby_io_splice.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).