From a4c4165539c01a2ade5cd7f123295d77733f6624 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 17 Mar 2017 00:53:57 +0000 Subject: favor require_relative over require This makes it easier to avoid file name conflicts while also improving startup performance by attempting fewer paths. --- ext/sleepy_penguin/epoll.c | 6 ++++-- ext/sleepy_penguin/kqueue.c | 9 ++++----- lib/sleepy_penguin.rb | 2 ++ lib/sleepy_penguin/kqueue.rb | 1 + lib/sleepy_penguin/sp.rb | 2 +- test/test_constants.rb | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c index 50a3a6f..8155c4a 100644 --- a/ext/sleepy_penguin/epoll.c +++ b/ext/sleepy_penguin/epoll.c @@ -329,7 +329,9 @@ void sleepy_penguin_init_epoll(void) id_for_fd = rb_intern("for_fd"); - /* the high-level interface is implemented in Ruby: */ - rb_require("sleepy_penguin/epoll"); + /* + * the high-level interface is implemented in Ruby, + * see lib/sleepy_penguin/epoll.rb + */ } #endif /* HAVE_SYS_EPOLL_H */ diff --git a/ext/sleepy_penguin/kqueue.c b/ext/sleepy_penguin/kqueue.c index c368514..114e78a 100644 --- a/ext/sleepy_penguin/kqueue.c +++ b/ext/sleepy_penguin/kqueue.c @@ -657,10 +657,9 @@ void sleepy_penguin_init_kqueue(void) id_for_fd = rb_intern("for_fd"); - /* the high-level interface is implemented in Ruby: */ - rb_require("sleepy_penguin/kqueue"); - - /* Kevent helper struct */ - rb_require("sleepy_penguin/kevent"); + /* + * the high-level interface is implemented in Ruby + * see lib/sleepy_penguin/kevent.rb + */ } #endif /* HAVE_SYS_EVENT_H */ diff --git a/lib/sleepy_penguin.rb b/lib/sleepy_penguin.rb index 5722f2a..eff92e6 100644 --- a/lib/sleepy_penguin.rb +++ b/lib/sleepy_penguin.rb @@ -19,6 +19,8 @@ end module SleepyPenguin require_relative 'sleepy_penguin/splice' if respond_to?(:__splice) require_relative 'sleepy_penguin/cfr' if respond_to?(:__cfr) + require_relative 'sleepy_penguin/epoll' if const_defined?(:Epoll) + require_relative 'sleepy_penguin/kqueue' if const_defined?(:Kqueue) # Copies +len+ bytes from +src+ to +dst+, where +src+ refers to # an open, mmap(2)-able File and +dst+ refers to a Socket. diff --git a/lib/sleepy_penguin/kqueue.rb b/lib/sleepy_penguin/kqueue.rb index dd09c51..d460669 100644 --- a/lib/sleepy_penguin/kqueue.rb +++ b/lib/sleepy_penguin/kqueue.rb @@ -1,4 +1,5 @@ require 'thread' +require_relative 'kevent' # The high-level Kqueue interface. This provides fork-safety under Ruby 1.9 # and later (but not Ruby 1.8). diff --git a/lib/sleepy_penguin/sp.rb b/lib/sleepy_penguin/sp.rb index 6a32f25..4e2618d 100644 --- a/lib/sleepy_penguin/sp.rb +++ b/lib/sleepy_penguin/sp.rb @@ -1,4 +1,4 @@ # :stopdoc: -require "sleepy_penguin" +require_relative '../sleepy_penguin' Object.const_set(:SP, SleepyPenguin) # :startdoc: diff --git a/test/test_constants.rb b/test/test_constants.rb index a15ae5e..56caefb 100644 --- a/test/test_constants.rb +++ b/test/test_constants.rb @@ -1,5 +1,5 @@ -require_relative 'helper' require 'sleepy_penguin/sp' +require_relative 'helper' class TestConstants < Test::Unit::TestCase def test_constants -- cgit v1.2.3-24-ge0c7