ruby-changes:53842
From: normal <ko1@a...>
Date: Wed, 28 Nov 2018 10:10:45 +0900 (JST)
Subject: [ruby-changes:53842] normal:r66060 (trunk): io.c (rb_update_max_fd): use F_GETFL if possible
normal 2018-11-28 10:10:40 +0900 (Wed, 28 Nov 2018) New Revision: 66060 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66060 Log: io.c (rb_update_max_fd): use F_GETFL if possible On 64-bit Linux, fstat() needs to fill out a 144 byte struct while F_GETFL only needs to return 8 bytes. Fwiw, F_GETFD requires an additional rcu_read_lock and bitmap check; so it's obviously more expensive than F_GETFL on Linux. Reduce stack usage of rb_update_max_fd from 184 to 24 bytes. Modified files: trunk/io.c Index: io.c =================================================================== --- io.c (revision 66059) +++ io.c (revision 66060) @@ -193,14 +193,22 @@ static rb_atomic_t max_file_descriptor = https://github.com/ruby/ruby/blob/trunk/io.c#L193 void rb_update_max_fd(int fd) { - struct stat buf; rb_atomic_t afd = (rb_atomic_t)fd; rb_atomic_t max_fd = max_file_descriptor; + int err; if (afd <= max_fd) return; - if (fstat(fd, &buf) != 0 && errno == EBADF) { +#if defined(HAVE_FCNTL) && defined(F_GETFL) + err = fcntl(fd, F_GETFL) == -1; +#else + { + struct stat buf; + err = fstat(fd, &buf) != 0; + } +#endif + if (err && errno == EBADF) { rb_bug("rb_update_max_fd: invalid fd (%d) given.", fd); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/