My earlier patch missed a few cases. The attached patch cleans those up. This change is probably too large to be included in findutils 4.10.0 at this point.
James.
From 3f0f5f8f485b5ca89075f63c2dd9986a74b54df5 Mon Sep 17 00:00:00 2001 From: James Youngman <ja...@youngman.org> Date: Mon, 27 May 2024 22:10:45 +0100 Subject: [PATCH] Use "optimization" rather than "optimisation". To: findutils-patc...@gnu.org * configure.ac: --enable-leaf-optimization and --enable-leaf-optimisation are synonyms. * NEWS: update spelling. * doc/find.texi: Likewise. * find/defs.h: Likewise. * find/find.1: Likewise. * find/ftsfind.c: Likewise. * find/pred.c: Likewise. * find/testsuite/config/unix.exp: Likewise. * find/testsuite/find.posix/exec-nogaps.exp: Likewise. * find/tree.c: Likewise. * locate/locate.c: Likewise. * find/parser.c: Likewise, and use the LEAF_OPTIMIZATION macro. * find/util.c: Likewise, and use the LEAF_OPTIMIZATION macro. --- configure.ac | 15 ++++++--- doc/find.texi | 40 +++++++++++------------ find/defs.h | 4 +-- find/find.1 | 28 ++++++++-------- find/ftsfind.c | 2 +- find/parser.c | 9 +++-- find/pred.c | 2 +- find/testsuite/config/unix.exp | 16 ++++----- find/testsuite/find.posix/exec-nogaps.exp | 2 +- find/tree.c | 14 ++++---- find/util.c | 20 ++++++------ locate/locate.c | 2 +- 12 files changed, 82 insertions(+), 72 deletions(-) diff --git a/configure.ac b/configure.ac index 8ad4b21f..365d748c 100644 --- a/configure.ac +++ b/configure.ac @@ -53,9 +53,16 @@ AC_CONFIG_MACRO_DIR(gl/m4) AC_SUBST(AUXDIR,$ac_aux_dir) +AC_ARG_ENABLE(leaf-optimization, + AS_HELP_STRING(--enable-leaf-optimization,Enable an optimization which saves lstat calls to identify subdirectories on filesystems having traditional Unix semantics), + [ac_cv_leaf_optimization=$enableval],[ac_cv_leaf_optimization=yes]) + +dnl This one has no default, because otherwise we would have to say +dnl both --enable-leaf-optimisation=no and --enable-leaf-optimization=no +dnl to turn it off. AC_ARG_ENABLE(leaf-optimisation, - AS_HELP_STRING(--enable-leaf-optimisation,Enable an optimisation which saves lstat calls to identify subdirectories on filesystems having traditional Unix semantics), - [ac_cv_leaf_optimisation=$enableval],[ac_cv_leaf_optimisation=yes]) + AS_HELP_STRING(--enable-leaf-optimisation,Synonym for --enable-leaf-optimization), + [ac_cv_leaf_optimization=$enableval],[]) AC_ARG_ENABLE(d_type-optimization, AS_HELP_STRING(--enable-d_type-optimization,Make use of the file type data returned in struct dirent.d_type by readdir()), @@ -69,12 +76,12 @@ AC_ARG_ENABLE(d_type-optimisation, [ac_cv_d_type=$enableval],[]) -AC_MSG_CHECKING([for leaf optimisation]) +AC_MSG_CHECKING([for leaf optimization]) if test x$ac_cv_leaf_optimisation = xno; then AC_MSG_RESULT([no]) else AC_MSG_RESULT([yes]) - AC_DEFINE([LEAF_OPTIMISATION], 1, [Define if you want to use the leaf optimisation (this can still be turned off with -noleaf)]) + AC_DEFINE([LEAF_OPTIMIZATION], 1, [Define if you want to use the leaf optimisation (this can still be turned off with -noleaf)]) fi AC_ARG_VAR([DEFAULT_ARG_SIZE], [Default size of arguments to child processes diff --git a/doc/find.texi b/doc/find.texi index b3eff2d0..ebc5d2b7 100644 --- a/doc/find.texi +++ b/doc/find.texi @@ -3340,12 +3340,12 @@ the @code{--help} output, or not normally useful. Options which are useful or which are not obvious are explained here. @menu -* Leaf Optimisation:: Take advantage of Unix file system semantics. -* d_type Optimisation:: Take advantage of file type information. +* Leaf Optimization:: Take advantage of Unix file system semantics. +* d_type Optimization:: Take advantage of file type information. @end menu -@node Leaf Optimisation -@section Leaf Optimisation +@node Leaf Optimization +@section Leaf Optimization Files in Unix file systems have a link count which indicates how many names point to the same inode. Directories in Unix filssytems have a @@ -3364,11 +3364,11 @@ in response to a successful call to @code{stat}. If you are building @code{find} for a system on which the value of @code{st_nlinks} is unreliable, you can specify -@code{--disable-leaf-optimisation} to @code{configure} to prevent this +@code{--disable-leaf-optimization} to @code{configure} to prevent this assumption being made. -@node d_type Optimisation -@section d_type Optimisation +@node d_type Optimization +@section d_type Optimization When this feature is enabled, @code{find} takes advantage of the fact that on some systems @code{readdir} will return the type of a file in @@ -3434,7 +3434,7 @@ The @samp{-version} option is a synonym for @samp{--version} @menu * Filesystem Traversal Options:: * Warning Messages:: -* Optimisation Options:: +* Optimization Options:: * Debug Options:: * Find Expressions:: @end menu @@ -3520,24 +3520,24 @@ Use of an unrecognised backslash escape sequence with @samp{-fprintf} Use of an unrecognised formatting directive with @samp{-fprintf} @end itemize -@node Optimisation Options -@subsection Optimisation Options +@node Optimization Options +@subsection Optimization Options -The @samp{-O@var{level}} option sets @code{find}'s optimisation level -to @var{level}. The default optimisation level is 1. +The @samp{-O@var{level}} option sets @code{find}'s optimization level +to @var{level}. The default optimization level is 1. -At certain optimisation levels (but not by default), @code{find} +At certain optimization levels (but not by default), @code{find} reorders tests to speed up execution while preserving the overall effect; that is, predicates with side effects are not reordered -relative to each other. The optimisations performed at each -optimisation level are as follows. +relative to each other. The optimizations performed at each +optimization level are as follows. @table @asis @item 0 -Currently equivalent to optimisation level 1. +Currently equivalent to optimization level 1. @item 1 -This is the default optimisation level and corresponds to the +This is the default optimization level and corresponds to the traditional behaviour. Expressions are reordered so that tests based only on the names of files (for example@samp{ -name} and @samp{-regex}) are performed first. @@ -3555,7 +3555,7 @@ type @samp{FOO} which is not known (that is, present in equivalent to @samp{-false}. @item 3 -At this optimisation level, the full cost-based query optimizer is +At this optimization level, the full cost-based query optimizer is enabled. The order of tests is modified so that cheap (i.e., fast) tests are performed first and more expensive ones are performed later, if necessary. Within each cost band, predicates are evaluated earlier @@ -3572,7 +3572,7 @@ re-ordering. If they are run in the order @samp{-empty -readable}, an error message will be issued for unreadable directories. If they are run in the order @samp{-readable -empty}, no error message will be issued. This is the reason why such operation re-ordering is not -performed at the default optimisation level. +performed at the default optimization level. @node Debug Options @subsection Debug Options @@ -3594,7 +3594,7 @@ Show the expression tree in its original and optimized form. Print messages as files are examined with the stat and lstat system calls. The find program tries to minimise such calls. @item opt -Prints diagnostic information relating to the optimisation of the +Prints diagnostic information relating to the optimization of the expression tree; see the @samp{-O} option. @item rates Prints a summary indicating how often each predicate succeeded or diff --git a/find/defs.h b/find/defs.h index 453dc272..83309d0a 100644 --- a/find/defs.h +++ b/find/defs.h @@ -613,7 +613,7 @@ struct options /* Optimisation level. One is the default. */ - unsigned short optimisation_level; + unsigned short optimization_level; /* How should we quote filenames in error messages and so forth? @@ -661,7 +661,7 @@ struct state /* True if there are any execdirs. This saves us a pair of fchdir() * calls for every directory we leave if it is false. This is just - * an optimisation. Set to true if you want to be conservative. + * an optimization. Set to true if you want to be conservative. */ bool execdirs_outstanding; diff --git a/find/find.1 b/find/find.1 index 319aa63e..d361cf31 100644 --- a/find/find.1 +++ b/find/find.1 @@ -236,7 +236,7 @@ Valid debug options include .IP exec Show diagnostic information relating to \-exec, \-execdir, \-ok and \-okdir .IP opt -Prints diagnostic information relating to the optimisation of the +Prints diagnostic information relating to the optimization of the expression tree; see the \-O option. .IP rates Prints a summary indicating how often each predicate succeeded or @@ -260,18 +260,18 @@ Enable all of the other debug options (but Explain the debugging options. .RE .IP \-Olevel -Enables query optimisation. +Enables query optimization. The .B find program reorders tests to speed up execution while preserving the overall effect; that is, predicates with side effects are not -reordered relative to each other. The optimisations performed at each -optimisation level are as follows. +reordered relative to each other. The optimizations performed at each +optimization level are as follows. .RS .IP 0 -Equivalent to optimisation level 1. +Equivalent to optimization level 1. .IP 1 -This is the default optimisation level and corresponds to the +This is the default optimization level and corresponds to the traditional behaviour. Expressions are reordered so that tests based only on the names of files (for example .B \-name @@ -298,7 +298,7 @@ which is not known (that is, present in `/etc/mtab') at the time starts, that predicate is equivalent to .BR \-false . .IP 3 -At this optimisation level, the full cost-based query optimizer is +At this optimization level, the full cost-based query optimizer is enabled. The order of tests is modified so that cheap (i.e.\& fast) tests are performed first and more expensive ones are performed later, if necessary. Within each cost band, predicates are evaluated earlier @@ -318,13 +318,13 @@ is assumed to be more likely to succeed than The cost-based optimizer is currently being evaluated. If it does not actually improve the performance of .BR find , -it will be removed again. Conversely, optimisations that prove to be -reliable, robust and effective may be enabled at lower optimisation -levels over time. However, the default behaviour (i.e.\& optimisation +it will be removed again. Conversely, optimizations that prove to be +reliable, robust and effective may be enabled at lower optimization +levels over time. However, the default behaviour (i.e.\& optimization level 1) will not be changed in the 4.3.x release series. The findutils test suite runs all the tests on .B find -at each optimisation level and ensures that the result is the same. +at each optimization level and ensures that the result is the same. The re-ordering of operations performed by the cost-based optimizer can result in user-visible behaviour change. For example, the @@ -337,7 +337,7 @@ an error message will be issued for unreadable directories. If they are run in the order .B \-readable \-empty no error message will be issued. This is the reason why such operation -re-ordering is not performed at the default optimisation level. +re-ordering is not performed at the default optimization level. . .SH EXPRESSION The part of the command line after the list of starting points is the @@ -2081,7 +2081,7 @@ which is actually a link to an ancestor. Since does not actually enter such a subdirectory, it is allowed to avoid emitting a diagnostic message. Although this behaviour may be somewhat confusing, it is unlikely that anybody actually depends on -this behaviour. If the leaf optimisation has been turned off with +this behaviour. If the leaf optimization has been turned off with .BR \-noleaf , the directory entry will always be examined and the diagnostic message will be issued where it is appropriate. Symbolic links cannot be used @@ -2092,7 +2092,7 @@ option or the option is in use, a diagnostic message is issued when .B find encounters a loop of symbolic links. As with loops containing hard -links, the leaf optimisation will often mean that +links, the leaf optimization will often mean that .B find knows that it doesn't need to call .I stat() diff --git a/find/ftsfind.c b/find/ftsfind.c index b7f69a0f..7274f021 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -233,7 +233,7 @@ issue_loop_warning (FTSENT * ent) { /* We have found an infinite loop. POSIX requires us to * issue a diagnostic. Usually we won't get to here - * because when the leaf optimisation is on, it will cause + * because when the leaf optimization is on, it will cause * the subdirectory to be skipped. If /a/b/c/d is a hard * link to /a/b, then the link count of /a/b/c is 2, * because the ".." entry of /a/b/c/d points to /a, not diff --git a/find/parser.c b/find/parser.c index b86e6856..6f8012c8 100644 --- a/find/parser.c +++ b/find/parser.c @@ -1089,7 +1089,7 @@ parse_fstype (const struct parser_table* entry, char **argv, int *arg_ptr) const char *typename; if (collect_arg (argv, arg_ptr, &typename)) { - if (options.optimisation_level < 2 || is_used_fs_type (typename)) + if (options.optimization_level < 2 || is_used_fs_type (typename)) { struct predicate *our_pred = insert_primary (entry, typename); our_pred->args.str = typename; @@ -2433,7 +2433,10 @@ parse_version (const struct parser_table* entry, char **argv, int *arg_ptr) printf ("O_NOFOLLOW(%s) ", (options.open_nofollow_available ? "enabled" : "disabled")); #endif -#if defined LEAF_OPTIMISATION +#if defined LEAF_OPTIMIZATION + /* Note spelling difference, we're retaining it in order not to + * break code which currently depends on this spelling. + */ printf ("LEAF_OPTIMISATION "); #endif if (0 < is_selinux_enabled ()) @@ -2450,7 +2453,7 @@ parse_version (const struct parser_table* entry, char **argv, int *arg_ptr) printf ("FTS() "); } - printf ("CBO(level=%d) ", (int)(options.optimisation_level)); + printf ("CBO(level=%d) ", (int)(options.optimization_level)); printf ("\n"); exit (EXIT_SUCCESS); diff --git a/find/pred.c b/find/pred.c index c61c94c4..5c8a341f 100644 --- a/find/pred.c +++ b/find/pred.c @@ -929,7 +929,7 @@ pred_size (const char *pathname, struct stat *stat_buf, struct predicate *pred_p bool pred_samefile (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) { - /* Potential optimisation: because of the loop protection, we always + /* Potential optimization: because of the loop protection, we always * know the device of the current directory, hence the device number * of the file we're currently considering. If -L is not in effect, * and the device number of the file we're looking for is not the diff --git a/find/testsuite/config/unix.exp b/find/testsuite/config/unix.exp index ad7a73d4..1d15da4c 100644 --- a/find/testsuite/config/unix.exp +++ b/find/testsuite/config/unix.exp @@ -175,13 +175,13 @@ proc do_find_start { suffix findprogram flags passfail options infile output } { pass "$testname" } -proc optimisation_levels_to_test {} { - global OPTIMISATION_LEVELS - if [info exists OPTIMISATION_LEVELS] { - send_log "Running find at optimisation levels $OPTIMISATION_LEVELS\n" - return $OPTIMISATION_LEVELS +proc optimization_levels_to_test {} { + global OPTIMIZATION_LEVELS + if [info exists OPTIMIZATION_LEVELS] { + send_log "Running find at optimization levels $OPTIMIZATION_LEVELS\n" + return $OPTIMIZATION_LEVELS } else { - send_log "Running find at default optimisation levels\n" + send_log "Running find at default optimization levels\n" return {0 1 2 3} } } @@ -202,8 +202,8 @@ proc find_start { passfail options {infile ""} {output ""} {setup ""}} { exit 1 } - # Now run the test with each binary, once with each optimisation level. - foreach optlevel [optimisation_levels_to_test] { + # Now run the test with each binary, once with each optimization level. + foreach optlevel [optimization_levels_to_test] { set flags "$FINDFLAGS -O$optlevel" if { ![info exists SKIP_NEW] || !$SKIP_NEW } { eval $setup diff --git a/find/testsuite/find.posix/exec-nogaps.exp b/find/testsuite/find.posix/exec-nogaps.exp index 108a7a15..90933a08 100644 --- a/find/testsuite/find.posix/exec-nogaps.exp +++ b/find/testsuite/find.posix/exec-nogaps.exp @@ -25,7 +25,7 @@ send_log "creeating files $file_list\n" foreach filename $file_list { } -set OPTIMISATION_LEVELS {3} +set OPTIMIZATION_LEVELS {3} find_start p { tmp/a/ -type f -exec echo \{\} \; } find_start p { tmp/a/ -type f -exec sh tmp/list.sh \{\} \+ } diff --git a/find/tree.c b/find/tree.c index b828a03e..b26e19d1 100644 --- a/find/tree.c +++ b/find/tree.c @@ -300,7 +300,7 @@ predicate_is_cost_free (const struct predicate *p) */ return true; } - else if (options.optimisation_level > 0) + else if (options.optimization_level > 0) { if (pred_is(p, pred_and) || pred_is(p, pred_negate) || @@ -673,7 +673,7 @@ do_arm_swaps (struct predicate *p) of a group by definition do not have side effects. Both -regex and -iregex both use pred_regex. - If higher optimisation levels have been selected, reordering also + If higher optimization levels have been selected, reordering also occurs according to the p_cost member of each predicate (which reflects the performance cost of the test). The ordering also bears in mind whether these operations are more likely to succeed @@ -780,7 +780,7 @@ opt_expr (struct predicate **eval_treep) if (options.debug_options & DebugTreeOpt) { fprintf (stderr, "-O%d: promoting cheap predicate ", - (int)options.optimisation_level); + (int)options.optimization_level); print_predicate (stderr, curr->pred_right); fprintf (stderr, " into name_list\n"); } @@ -794,18 +794,18 @@ opt_expr (struct predicate **eval_treep) continue; } - reorder = ((options.optimisation_level > 1) + reorder = ((options.optimization_level > 1) && (NeedsType == curr->pred_right->p_cost || NeedsInodeNumber == curr->pred_right->p_cost) && !curr->pred_right->need_stat) || - (options.optimisation_level > 2); + (options.optimization_level > 2); if (reorder) { if (options.debug_options & DebugTreeOpt) { fprintf (stderr, "-O%d: categorising predicate ", - (int)options.optimisation_level); + (int)options.optimization_level); print_predicate (stderr, curr->pred_right); fprintf (stderr, " by cost (%s)\n", cost_name(curr->pred_right->p_cost)); @@ -1430,7 +1430,7 @@ build_expression_tree (int argc, char *argv[], int end_of_leading_options) /* Check that the tree is in normalised order (opt_expr does this) */ check_normalization (eval_tree, true); - if (options.optimisation_level > 1) + if (options.optimization_level > 1) { do_arm_swaps (eval_tree); } diff --git a/find/util.c b/find/util.c index 88dafd7b..b8a3cb19 100644 --- a/find/util.c +++ b/find/util.c @@ -53,7 +53,7 @@ struct debug_option_assoc static struct debug_option_assoc debugassoc[] = { { "exec", DebugExec, "Show diagnostic information relating to -exec, -execdir, -ok and -okdir" }, - { "opt", DebugExpressionTree|DebugTreeOpt, "Show diagnostic information relating to optimisation" }, + { "opt", DebugExpressionTree|DebugTreeOpt, "Show diagnostic information relating to optimization" }, { "rates", DebugSuccessRates, "Indicate how often each predicate succeeded" }, { "search",DebugSearch, "Navigate the directory tree verbosely" }, { "stat", DebugStat, "Trace calls to stat(2) and lstat(2)" }, @@ -847,7 +847,7 @@ process_debug_options (char *arg) static void -process_optimisation_option (const char *arg) +process_optimization_option (const char *arg) { if (0 == arg[0]) { @@ -878,12 +878,12 @@ process_optimisation_option (const char *arg) else if (*end) { /* unwanted trailing characters. */ - error (EXIT_FAILURE, 0, _("Invalid optimisation level %s"), arg); + error (EXIT_FAILURE, 0, _("Invalid optimization level %s"), arg); } else if ( (ULONG_MAX==opt_level) && errno) { error (EXIT_FAILURE, errno, - _("Invalid optimisation level %s"), arg); + _("Invalid optimization level %s"), arg); } else if (opt_level > USHRT_MAX) { @@ -898,7 +898,7 @@ process_optimisation_option (const char *arg) } else { - options.optimisation_level = opt_level; + options.optimization_level = opt_level; errno = prev_errno; } } @@ -945,7 +945,7 @@ process_leading_options (int argc, char *argv[]) } else if (0 == strncmp ("-O", argv[i], 2)) { - process_optimisation_option (argv[i]+2); + process_optimization_option (argv[i]+2); } else { @@ -1035,7 +1035,7 @@ set_option_defaults (struct options *p) p->output_block_size = 1024; p->debug_options = 0uL; - p->optimisation_level = 1; + p->optimization_level = 1; if (getenv ("FIND_BLOCK_SIZE")) { @@ -1045,11 +1045,11 @@ set_option_defaults (struct options *p) "POSIXLY_CORRECT environment variable")); } -#if LEAF_OPTIMISATION - /* The leaf optimisation is enabled. */ +#if LEAF_OPTIMIZATION + /* The leaf optimization is enabled. */ p->no_leaf_check = false; #else - /* The leaf optimisation is disabled. */ + /* The leaf optimization is disabled. */ p->no_leaf_check = true; #endif diff --git a/locate/locate.c b/locate/locate.c index aefb3793..faaf1502 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -1210,7 +1210,7 @@ search_one_database (int argc, visitfunc matcher; if (1 == MB_CUR_MAX) { - /* As an optimisation, use a strstr () matcher if we are + /* As an optimization, use a strstr () matcher if we are * in a unibyte locale. This can give a x2 speedup in * the C locale. Some light testing reveals that * glibc's strstr () is somewhere around 40% faster than -- 2.39.2