* canonicalize: Trim module dependencies
@ 2020-07-08 0:45 Bruno Haible
0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2020-07-08 0:45 UTC (permalink / raw)
To: bug-gnulib
The 'canonicalize' module has, among others, this dependency chain:
'canonicalize' -> 'hash-triple' -> 'same' -> {'fstatat','openat'} -> 'fchdir'
But the 'canonicalize' module needs only part of the 'hash-triple' module and,
in particular, only the part that does not need the 'same' module.
2020-07-07 Bruno Haible <bruno@clisp.org>
canonicalize: Trim module dependencies.
* lib/hash-triple.h: Group declarations.
* lib/hash-triple-simple.c: New file, extracted from lib/hash-triple.c.
* lib/hash-triple.c: Don't include <stdlib.h>, <string.h>, hash-pjw.h.
(STREQ): Remove macro.
(triple_hash, triple_compare_ino_str, triple_free): Remove functions.
* modules/hash-triple-simple: New file, based on modules/hash-triple.
* modules/hash-triple (Files): Remove lib/hash-triple.h.
(Depends-on): Add hash-triple-simple. Remove hash-pjw.
* modules/canonicalize (Depends-on): Remove hash-triple. Add
hash-triple-simple.
* modules/file-set (Depends-on): Likewise.
diff --git a/lib/hash-triple-simple.c b/lib/hash-triple-simple.c
new file mode 100644
index 0000000..98728f2
--- /dev/null
+++ b/lib/hash-triple-simple.c
@@ -0,0 +1,59 @@
+/* Hash functions for file-related triples: name, device, inode.
+ Copyright (C) 2007, 2009-2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* written by Jim Meyering */
+
+#include <config.h>
+
+/* Specification. */
+#include "hash-triple.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "hash-pjw.h"
+#include "same-inode.h"
+
+#define STREQ(a, b) (strcmp (a, b) == 0)
+
+/* Hash an F_triple, and *do* consider the file name. */
+size_t
+triple_hash (void const *x, size_t table_size)
+{
+ struct F_triple const *p = x;
+ size_t tmp = hash_pjw (p->name, table_size);
+
+ /* Ignoring the device number here should be fine. */
+ return (tmp ^ p->st_ino) % table_size;
+}
+
+/* Compare two F_triple structs. */
+bool
+triple_compare_ino_str (void const *x, void const *y)
+{
+ struct F_triple const *a = x;
+ struct F_triple const *b = y;
+ return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
+}
+
+/* Free an F_triple. */
+void
+triple_free (void *x)
+{
+ struct F_triple *a = x;
+ free (a->name);
+ free (a);
+}
diff --git a/lib/hash-triple.c b/lib/hash-triple.c
index 560e442..ad1a559 100644
--- a/lib/hash-triple.c
+++ b/lib/hash-triple.c
@@ -18,28 +18,12 @@
#include <config.h>
+/* Specification. */
#include "hash-triple.h"
-#include <stdlib.h>
-#include <string.h>
-
-#include "hash-pjw.h"
#include "same.h"
#include "same-inode.h"
-#define STREQ(a, b) (strcmp (a, b) == 0)
-
-/* Hash an F_triple, and *do* consider the file name. */
-size_t
-triple_hash (void const *x, size_t table_size)
-{
- struct F_triple const *p = x;
- size_t tmp = hash_pjw (p->name, table_size);
-
- /* Ignoring the device number here should be fine. */
- return (tmp ^ p->st_ino) % table_size;
-}
-
/* Hash an F_triple, without considering the file name. */
size_t
triple_hash_no_name (void const *x, size_t table_size)
@@ -58,20 +42,3 @@ triple_compare (void const *x, void const *y)
struct F_triple const *b = y;
return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
}
-
-bool
-triple_compare_ino_str (void const *x, void const *y)
-{
- struct F_triple const *a = x;
- struct F_triple const *b = y;
- return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
-}
-
-/* Free an F_triple. */
-void
-triple_free (void *x)
-{
- struct F_triple *a = x;
- free (a->name);
- free (a);
-}
diff --git a/lib/hash-triple.h b/lib/hash-triple.h
index c65450e..16f5330 100644
--- a/lib/hash-triple.h
+++ b/lib/hash-triple.h
@@ -31,12 +31,16 @@ struct F_triple
dev_t st_dev;
};
+/* Defined in module 'hash-triple-simple'. */
+
extern size_t triple_hash (void const *x, size_t table_size) _GL_ATTRIBUTE_PURE;
-extern size_t triple_hash_no_name (void const *x, size_t table_size)
- _GL_ATTRIBUTE_PURE;
-extern bool triple_compare (void const *x, void const *y);
extern bool triple_compare_ino_str (void const *x, void const *y)
_GL_ATTRIBUTE_PURE;
extern void triple_free (void *x);
+/* Defined in module 'hash-triple'. */
+extern size_t triple_hash_no_name (void const *x, size_t table_size)
+ _GL_ATTRIBUTE_PURE;
+extern bool triple_compare (void const *x, void const *y);
+
#endif
diff --git a/modules/canonicalize b/modules/canonicalize
index a59b9fb..16dfb69 100644
--- a/modules/canonicalize
+++ b/modules/canonicalize
@@ -13,7 +13,7 @@ errno
extensions
file-set
filename
-hash-triple
+hash-triple-simple
lstat
memmove
nocrash
diff --git a/modules/file-set b/modules/file-set
index 7895cda..532828c 100644
--- a/modules/file-set
+++ b/modules/file-set
@@ -7,7 +7,7 @@ lib/file-set.h
Depends-on:
hash
-hash-triple
+hash-triple-simple
stdbool
xalloc
xalloc-die
diff --git a/modules/hash-triple b/modules/hash-triple
index b746d47..b726192 100644
--- a/modules/hash-triple
+++ b/modules/hash-triple
@@ -3,10 +3,9 @@ Hash functions for file-related triples: name, device, inode.
Files:
lib/hash-triple.c
-lib/hash-triple.h
Depends-on:
-hash-pjw
+hash-triple-simple
same
same-inode
diff --git a/modules/hash-triple-simple b/modules/hash-triple-simple
new file mode 100644
index 0000000..1ef3209
--- /dev/null
+++ b/modules/hash-triple-simple
@@ -0,0 +1,24 @@
+Description:
+Hash functions for file-related triples: name, device, inode.
+
+Files:
+lib/hash-triple-simple.c
+lib/hash-triple.h
+
+Depends-on:
+hash-pjw
+same-inode
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += hash-triple-simple.c
+
+Include:
+"hash-triple.h"
+
+License:
+GPL
+
+Maintainer:
+Jim Meyering
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-07-08 0:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 0:45 canonicalize: Trim module dependencies Bruno Haible
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).