Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/cp Remove fts sorting. It was originally put there to c...



details:   https://anonhg.NetBSD.org/src/rev/0edfcedd8e18
branches:  trunk
changeset: 747725:0edfcedd8e18
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Sep 29 13:30:17 2009 +0000

description:
Remove fts sorting.  It was originally put there to copy files
before directories since files (usually) are in the same cylinder
group and subdirectories aren't.  However, this mostly changed with
the new ffs dirpref algorithm in 2001.

No sorting has two effects:
1) copy appears to be somewhat faster (e.g. on my laptop cp'ing build
   objdir to tmpfs is 7% faster after the change)
2) source file parameters no longer get randomly shuffled due to
   fts doing an unstable sort of them.  this means that
   "cp 1 2 3 4 dest/" will copy the files in that order instead
   of e.g. 3 4 1 2.

diffstat:

 bin/cp/cp.c |  33 +++------------------------------
 1 files changed, 3 insertions(+), 30 deletions(-)

diffs (65 lines):

diff -r 335d962543de -r 0edfcedd8e18 bin/cp/cp.c
--- a/bin/cp/cp.c       Tue Sep 29 11:58:18 2009 +0000
+++ b/bin/cp/cp.c       Tue Sep 29 13:30:17 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $ */
+/* $NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $ */
 
 /*
  * Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)cp.c       8.5 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: cp.c,v 1.51 2008/07/20 00:52:39 lukem Exp $");
+__RCSID("$NetBSD: cp.c,v 1.52 2009/09/29 13:30:17 pooka Exp $");
 #endif
 #endif /* not lint */
 
@@ -92,7 +92,6 @@
 
 int    main(int, char *[]);
 int    copy(char *[], enum op, int);
-int    mastercmp(const FTSENT **, const FTSENT **);
 
 int
 main(int argc, char *argv[])
@@ -295,7 +294,7 @@
        dne = 0;
        base = 0;       /* XXX gcc -Wuninitialized (see comment below) */
 
-       if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
+       if ((ftsp = fts_open(argv, fts_options, NULL)) == NULL)
                err(EXIT_FAILURE, "%s", argv[0]);
                /* NOTREACHED */
        for (any_failed = 0; (curr = fts_read(ftsp)) != NULL;) {
@@ -515,29 +514,3 @@
        (void)fts_close(ftsp);
        return (any_failed);
 }
-
-/*
- * mastercmp --
- *     The comparison function for the copy order.  The order is to copy
- *     non-directory files before directory files.  The reason for this
- *     is because files tend to be in the same cylinder group as their
- *     parent directory, whereas directories tend not to be.  Copying the
- *     files first reduces seeking.
- */
-int
-mastercmp(const FTSENT **a, const FTSENT **b)
-{
-       int a_info, b_info;
-
-       a_info = (*a)->fts_info;
-       if (a_info == FTS_ERR || a_info == FTS_NS || a_info == FTS_DNR)
-               return (0);
-       b_info = (*b)->fts_info;
-       if (b_info == FTS_ERR || b_info == FTS_NS || b_info == FTS_DNR)
-               return (0);
-       if (a_info == FTS_D)
-               return (-1);
-       if (b_info == FTS_D)
-               return (1);
-       return (0);
-}



Home | Main Index | Thread Index | Old Index