dir.c: reduce syscalls

* dir.c (glob_helper): utilize d_type even if no recursive
  pattern, to reduce stat/lstat syscalls in subsequent
  glob_helper.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-08-03 04:13:12 +00:00
parent 2a5c20acaf
commit 76857f8ee8

10
dir.c
View File

@ -1940,7 +1940,7 @@ glob_helper(
pathtype = path_noent; pathtype = path_noent;
} }
} }
if (match_dir && pathtype == path_unknown) { if (match_dir && (pathtype == path_unknown || pathtype == path_symlink)) {
if (do_stat(fd, base, &st, flags, enc) == 0) { if (do_stat(fd, base, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode); pathtype = IFTODT(st.st_mode);
} }
@ -2042,14 +2042,12 @@ glob_helper(
break; break;
} }
name = buf + pathlen + (dirsep != 0); name = buf + pathlen + (dirsep != 0);
if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) { if (dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) &&
#ifdef DT_UNKNOWN #ifdef DT_UNKNOWN
if ((new_pathtype = dp->d_type) != (rb_pathtype_t)DT_UNKNOWN) ((new_pathtype = dp->d_type) == (rb_pathtype_t)DT_UNKNOWN) &&
/* Got it. We need nothing more. */
;
else
/* fall back to call lstat(2) */ /* fall back to call lstat(2) */
#endif #endif
recursive) {
/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */ /* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
if (do_lstat(fd, buf, &st, flags, enc) == 0) if (do_lstat(fd, buf, &st, flags, enc) == 0)
new_pathtype = IFTODT(st.st_mode); new_pathtype = IFTODT(st.st_mode);