[前][次][番号順一覧][スレッド一覧]

ruby-changes:47365

From: nobu <ko1@a...>
Date: Thu, 3 Aug 2017 13:13:18 +0900 (JST)
Subject: [ruby-changes:47365] nobu:r59481 (trunk): dir.c: reduce syscalls

nobu	2017-08-03 13:13:12 +0900 (Thu, 03 Aug 2017)

  New Revision: 59481

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59481

  Log:
    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.

  Modified files:
    trunk/dir.c
Index: dir.c
===================================================================
--- dir.c	(revision 59480)
+++ dir.c	(revision 59481)
@@ -1940,7 +1940,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1940
 		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) {
 		pathtype = IFTODT(st.st_mode);
 	    }
@@ -2042,14 +2042,12 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L2042
 		break;
 	    }
 	    name = buf + pathlen + (dirsep != 0);
-	    if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) {
+	    if (dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) &&
 #ifdef DT_UNKNOWN
-		if ((new_pathtype = dp->d_type) != (rb_pathtype_t)DT_UNKNOWN)
-		    /* Got it. We need nothing more. */
-		    ;
-		else
+		((new_pathtype = dp->d_type) == (rb_pathtype_t)DT_UNKNOWN) &&
 		    /* fall back to call lstat(2) */
 #endif
+		recursive) {
 		/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
 		if (do_lstat(fd, buf, &st, flags, enc) == 0)
 		    new_pathtype = IFTODT(st.st_mode);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]