io_splice RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] favor comparisons against zero instead of -1
@ 2015-01-10  3:44 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-01-10  3:44 UTC (permalink / raw)
  To: ruby-io-splice; +Cc: Eric Wong

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-01-10  3:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-10  3:44 [PATCH] favor comparisons against zero instead of -1 Eric Wong

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).