Changeset 5150

Show
Ignore:
Timestamp:
01/05/08 01:01:52 (8 months ago)
Author:
morris
Message:

Count directory entries with simple opendir/readdir loop instead of using fts for even more performance

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/trunk/wired/files.c

    r5066 r5150  
    7777static wi_boolean_t                                                     wd_files_read_comment(wi_file_t *, wi_string_t **, wi_string_t **); 
    7878 
    79 static WI_FTS *                                                         wd_files_fts_open(wi_string_t *, wi_boolean_t, wi_boolean_t); 
     79static WI_FTS *                                                         wd_files_fts_open(wi_string_t *, wi_boolean_t); 
    8080static wd_files_fts_action_t                            wd_files_fts_action(WI_FTSENT *, int *); 
    8181static int                                                                      wd_files_fts_namecmp(const WI_FTSENT **, const WI_FTSENT **); 
     
    146146        } 
    147147 
    148         fts = wd_files_fts_open(realpath, true, true); 
     148        fts = wd_files_fts_open(realpath, true); 
    149149         
    150150        if(!fts) { 
     
    188188                 
    189189                /* skip if we're not recursive */ 
    190                 if(!recursive && p->fts_level > 1) { 
     190                if(!recursive) 
    191191                        wi_fts_set(fts, p, WI_FTS_SKIP); 
    192  
    193                         continue; 
    194                 } 
    195192                 
    196193                /* create real path */ 
     
    284281 
    285282static wi_file_offset_t wd_files_count_path(wi_string_t *path, wi_boolean_t interactive) { 
    286         WI_FTS                                  *fts; 
    287         WI_FTSENT                               *p; 
     283        wi_string_t                             *filepath; 
     284        DIR                                             *dir; 
     285        struct dirent                   de, *dep; 
    288286        wi_file_offset_t                count = 0; 
    289         wd_files_fts_action_t   action; 
    290         int                                             error; 
    291          
    292         fts = wd_files_fts_open(path, false, false); 
    293  
    294         if(!fts) { 
     287         
     288        dir = opendir(wi_string_cstring(path)); 
     289         
     290        if(!dir) { 
    295291                wi_log_warn(WI_STR("Could not open %@: %s"), 
    296292                        path, strerror(errno)); 
     
    298294                if(interactive) 
    299295                        wd_reply_error(); 
    300  
     296                 
    301297                return 0; 
    302298        } 
    303299         
    304         while((p = wi_fts_read(fts))) { 
    305                 /* skip item? */ 
    306                 action = wd_files_fts_action(p, &error); 
    307                  
    308                 switch(action) { 
    309                         case WD_FILES_FTS_KEEP: 
    310                                 break; 
    311                                  
    312                         case WD_FILES_FTS_IGNORE: 
    313                         case WD_FILES_FTS_ERROR: 
     300        while(readdir_r(dir, &de, &dep) == 0 && dep) { 
     301                /* skip . files */ 
     302                if(dep->d_name[0] == '.') { 
     303                        if(!wd_settings.showdotfiles) 
    314304                                continue; 
    315                                break; 
    316                                 
    317                        case WD_FILES_FTS_SKIP: 
    318                                wi_fts_set(fts, p, WI_FTS_SKIP); 
    319                                 
     305                } 
     306                 
     307                /* skip regular expression */ 
     308                if(wd_settings.ignoreexpression) { 
     309                        if(wi_regexp_match_cstring(wd_settings.ignoreexpression, dep->d_name)) 
    320310                                continue; 
    321                                break; 
    322                 } 
    323                  
    324                 /* skip recursion */ 
    325                 if(p->fts_level > 1) { 
    326                         wi_fts_set(fts, p, WI_FTS_SKIP); 
    327  
    328                         continue; 
     311                } 
     312                 
     313                /* skip mac invisibles */ 
     314                if(!wd_settings.showinvisiblefiles) { 
     315                       filepath = wi_string_by_appending_format(path, WI_STR("/%s"), dep->d_name); 
     316 
     317                        if(wi_file_is_invisible(filepath)) 
     318                               continue; 
    329319                } 
    330320                 
    331321                count++; 
    332322        } 
    333          
    334         wi_fts_close(fts); 
     323 
     324        closedir(dir); 
    335325         
    336326        return count; 
     
    570560        wi_boolean_t                    alias, recurse; 
    571561 
    572         fts = wd_files_fts_open(path, false, true); 
     562        fts = wd_files_fts_open(path, false); 
    573563 
    574564        if(!fts) { 
     
    893883        } 
    894884 
    895         fts = wd_files_fts_open(path, false, true); 
     885        fts = wd_files_fts_open(path, false); 
    896886 
    897887        if(!fts) { 
     
    13661356#pragma mark - 
    13671357 
    1368 static WI_FTS * wd_files_fts_open(wi_string_t *path, wi_boolean_t sorted, wi_boolean_t logical) { 
     1358static WI_FTS * wd_files_fts_open(wi_string_t *path, wi_boolean_t sorted) { 
    13691359        WI_FTS          *fts; 
    13701360        char            *paths[2]; 
     
    13741364        paths[1] = NULL; 
    13751365 
    1376         options = WI_FTS_NOSTAT; 
    1377          
    1378         if(logical) 
    1379                 options |= WI_FTS_LOGICAL; 
    1380         else 
    1381                 options |= WI_FTS_PHYSICAL | WI_FTS_COMFOLLOW; 
    1382          
     1366        options = WI_FTS_NOSTAT | WI_FTS_LOGICAL; 
    13831367        errno = 0; 
    13841368        fts = wi_fts_open(paths, options, sorted ? wd_files_fts_namecmp : NULL);