Changeset 3005 for trunk/src/lib/nt/fts-nt.c
- Timestamp:
- Nov 6, 2016, 1:07:37 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt/fts-nt.c
r3004 r3005 118 118 #define MAX(a, b) ( (a) >= (b) ? (a) : (b) ) 119 119 120 /** Enables BirdDir_T reuse. (Saves malloc and free calls.) */ 121 #define FTS_WITH_DIRHANDLE_REUSE 122 /** Enables allocation statistics. */ 123 //#define FTS_WITH_STATISTICS 124 /** Enables FTSENT allocation cache. */ 120 125 #define FTS_WITH_ALLOC_CACHE 121 126 /** Number of size buckets for the FTSENT allocation cache. */ 122 #define FTS_NUM_FREE_BUCKETS 127 #define FTS_NUM_FREE_BUCKETS 64 123 128 /** Shift for converting size to free bucket index. */ 124 129 #define FTS_FREE_BUCKET_SHIFT 4 125 130 /** The FTSENT allocation alignment. */ 126 #define FTS_ALIGN_FTSENT (1U << FTS_FREE_BUCKET_SHIFT) 127 /** Enables allocation statistics. */ 128 //#define FTS_WITH_STATISTICS 131 #define FTS_ALIGN_FTSENT (1U << FTS_FREE_BUCKET_SHIFT) 129 132 130 133 /* … … 135 138 struct _fts_private { 136 139 FTS ftsp_fts; 140 #ifdef FTS_WITH_DIRHANDLE_REUSE 141 /** Statically allocate directory handle. */ 142 BirdDir_T dirhandle; 143 #endif 137 144 #ifdef FTS_WITH_ALLOC_CACHE 138 145 /** Number of free entries in the above buckets. */ … … 403 410 #endif 404 411 nt_fts_free_alloc_cache(sp); 412 #ifdef FTS_WITH_DIRHANDLE_REUSE 413 birdDirClose(&((struct _fts_private *)sp)->dirhandle); 414 #endif 405 415 406 416 /* Free up the stream pointer. */ … … 461 471 wchar_t *pwc; 462 472 463 /* If finished or unrecoverable error, return NULL. */464 if (sp->fts_cur == NULL || ISSET(FTS_STOP))465 return (NULL);466 467 473 /* Set current node pointer. */ 468 474 p = sp->fts_cur; 475 476 /* If finished or unrecoverable error, return NULL. */ 477 if (p != NULL && !ISSET(FTS_STOP)) { 478 /* likely */ 479 } else { 480 return (NULL); 481 } 469 482 470 483 /* Save and zero out user instructions. */ … … 473 486 474 487 /* Any type of file may be re-visited; re-stat and re-turn. */ 475 if (instr == FTS_AGAIN) { 488 if (instr != FTS_AGAIN) { 489 /* likely */ 490 } else { 476 491 p->fts_info = fts_stat(sp, p, 0, INVALID_HANDLE_VALUE); 477 492 return (p); … … 487 502 * here in case a API client checks it. 488 503 */ 489 if (instr == FTS_FOLLOW && 490 (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { 504 if ( instr != FTS_FOLLOW 505 || (p->fts_info != FTS_SL && p->fts_info != FTS_SLNONE)) { 506 /* likely */ 507 } else { 491 508 p->fts_info = fts_stat(sp, p, 1, INVALID_HANDLE_VALUE); 492 509 if (p->fts_info == FTS_D /*&& !ISSET(FTS_NOCHDIR)*/) { … … 499 516 if (p->fts_info == FTS_D) { 500 517 /* If skipped or crossed mount point, do post-order visit. */ 501 if ( instr == FTS_SKIP ||502 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {518 if ( instr == FTS_SKIP 519 || (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { 503 520 if (sp->fts_child) { 504 521 fts_lfree(sp->fts_child); … … 528 545 * FTS_STOP or the fts_info field of the node. 529 546 */ 530 if (sp->fts_child != NULL) { 531 /* nothing to do */ 532 } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { 533 if (ISSET(FTS_STOP)) 534 return (NULL); 535 return (p); 536 } 537 p = sp->fts_child; 538 sp->fts_child = NULL; 547 if (sp->fts_child == NULL) { 548 p = fts_build(sp, BREAD); 549 if (p != NULL) { 550 /* likely */ 551 } else { 552 if (ISSET(FTS_STOP)) 553 return (NULL); 554 return sp->fts_cur; 555 } 556 557 } else { 558 p = sp->fts_child; 559 sp->fts_child = NULL; 560 } 539 561 goto name; 540 562 } … … 547 569 * the root of the tree), and load the paths for the next root. 548 570 */ 549 if (p->fts_level == FTS_ROOTLEVEL) { 571 if (p->fts_level != FTS_ROOTLEVEL) { 572 /* likely */ 573 } else { 550 574 fts_free_entry(sp, tmp); 551 575 fts_load(sp, p); … … 558 582 * get back if necessary. 559 583 */ 560 if (p->fts_instr == FTS_SKIP) { 584 if (p->fts_instr != FTS_SKIP) { 585 /* likely */ 586 } else { 561 587 fts_free_entry(sp, tmp); 562 588 goto next; 563 589 } 564 if (p->fts_instr == FTS_FOLLOW) { 590 if (p->fts_instr != FTS_FOLLOW) { 591 /* likely */ 592 } else { 565 593 p->fts_info = fts_stat(sp, p, 1, INVALID_HANDLE_VALUE); 566 594 /* NT: See above regarding fts_flags. */ … … 588 616 p = tmp->fts_parent; 589 617 590 if (p->fts_level == FTS_ROOTPARENTLEVEL) { 618 if (p->fts_level != FTS_ROOTPARENTLEVEL) { 619 /* likely */ 620 } else { 591 621 /* 592 622 * Done; free everything up and set errno to 0 so the user … … 787 817 fDirOpenFlags |= BIRDDIR_F_RESTART_SCAN; 788 818 } 819 #ifdef FTS_WITH_DIRHANDLE_REUSE 820 dirp = birdDirOpenFromHandleWithReuse(&((struct _fts_private *)sp)->dirhandle, cur->fts_dirfd, NULL, 821 fDirOpenFlags | BIRDDIR_F_STATIC_ALLOC); 822 #else 789 823 dirp = birdDirOpenFromHandle(cur->fts_dirfd, NULL, fDirOpenFlags); 824 #endif 790 825 if (dirp == NULL) { 791 826 l_open_err: … … 856 891 free(p); 857 892 fts_lfree(head); 893 #ifndef FTS_WITH_DIRHANDLE_REUSE 858 894 birdDirClose(dirp); 895 #endif 859 896 birdCloseFile(cur->fts_dirfd); 860 897 cur->fts_dirfd = INVALID_HANDLE_VALUE; … … 887 924 } 888 925 926 #ifndef FTS_WITH_DIRHANDLE_REUSE 889 927 birdDirClose(dirp); 928 #endif 890 929 891 930 /*
Note:
See TracChangeset
for help on using the changeset viewer.