sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy-penguin@bogomips.org
Cc: Eric Wong <normalperson@yhbt.net>
Subject: [PATCH] epoll: allow :CLOEXEC instead of the long constant
Date: Fri,  5 Jun 2015 09:26:16 +0000	[thread overview]
Message-ID: <1433496376-3003-1-git-send-email-normalperson@yhbt.net> (raw)

The long constant name conveys no additional info.  Since
epoll_create1 is rarely called, and a cache lookup for cold
code is wasfeful
---
 ext/sleepy_penguin/epoll.c | 2 +-
 test/test_epoll.rb         | 7 +++++++
 test/test_epoll_io.rb      | 2 +-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c
index 423ed69..120af0c 100644
--- a/ext/sleepy_penguin/epoll.c
+++ b/ext/sleepy_penguin/epoll.c
@@ -82,7 +82,7 @@ static struct ep_per_thread *ept_get(VALUE self, int maxevents)
 static VALUE s_new(VALUE klass, VALUE _flags)
 {
 	int default_flags = RB_SP_CLOEXEC(EPOLL_CLOEXEC);
-	int flags = rb_sp_get_flags(klass, _flags, default_flags);
+	int flags = rb_sp_get_flags(cEpoll, _flags, default_flags);
 	int fd = epoll_create1(flags);
 	VALUE rv;
 
diff --git a/test/test_epoll.rb b/test/test_epoll.rb
index 61b6e8c..48dd0ad 100644
--- a/test/test_epoll.rb
+++ b/test/test_epoll.rb
@@ -343,6 +343,13 @@ class TestEpoll < Testcase
     @ep.close
     io = Epoll.new(Epoll::CLOEXEC).to_io
     assert((io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC) == Fcntl::FD_CLOEXEC)
+    io.close
+
+    # prettier, slower, but more memory efficient due to lack of caching
+    # due to the constant cache:
+    io = Epoll.new(:CLOEXEC).to_io
+
+    assert((io.fcntl(Fcntl::F_GETFD) & Fcntl::FD_CLOEXEC) == Fcntl::FD_CLOEXEC)
   end
 
   def test_new
diff --git a/test/test_epoll_io.rb b/test/test_epoll_io.rb
index 56a3808..5452de1 100644
--- a/test/test_epoll_io.rb
+++ b/test/test_epoll_io.rb
@@ -23,7 +23,7 @@ class TestEpollIO < Testcase
 
   class EpSub < Epoll::IO
     def self.new
-      super(SleepyPenguin::Epoll::CLOEXEC)
+      super(:CLOEXEC)
     end
   end
 
-- 
EW


                 reply	other threads:[~2015-06-05  9:26 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/sleepy_penguin/

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

  git send-email \
    --in-reply-to=1433496376-3003-1-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy-penguin@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/sleepy_penguin.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).