[DTrace-devel] [PATCH 10/17] htab: move str2hval() to dt_htab
Kris Van Hees
kris.van.hees at oracle.com
Sat Jun 7 06:15:02 UTC 2025
Signed-off-by: Kris Van Hees <kris.van.hees at oracle.com>
Reviewed-by: Nick Alcock <nick.alcock at oracle.com>
---
libcommon/dt_htab.c | 28 ++++++++++++++++++++++++++++
libcommon/dt_htab.h | 2 ++
libdtrace/dt_string.c | 30 +-----------------------------
libdtrace/dt_string.h | 3 +--
4 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/libcommon/dt_htab.c b/libcommon/dt_htab.c
index 43782202..ee119031 100644
--- a/libcommon/dt_htab.c
+++ b/libcommon/dt_htab.c
@@ -62,6 +62,34 @@ struct dt_htab_next {
int exhausted;
};
+/*
+ * Calculate a hash value based on a given string and an initial value. The
+ * initial value is used to calculate compound hash values, e.g.
+ *
+ * uint32_t hval;
+ *
+ * hval = str2hval(str1, 0);
+ * hval = str2hval(str2, hval);
+ */
+uint32_t str2hval(const char *p, uint32_t hval)
+{
+ uint32_t g;
+
+ if (!p)
+ return hval;
+
+ while (*p) {
+ hval = (hval << 4) + *p++;
+ g = hval & 0xf0000000;
+ if (g != 0) {
+ hval ^= (g >> 24);
+ hval ^= g;
+ }
+ }
+
+ return hval;
+}
+
/*
* Create a new (empty) hashtable.
*/
diff --git a/libcommon/dt_htab.h b/libcommon/dt_htab.h
index 906c91fd..13de552a 100644
--- a/libcommon/dt_htab.h
+++ b/libcommon/dt_htab.h
@@ -91,6 +91,8 @@ typedef struct dt_hentry {
typedef struct dt_htab dt_htab_t;
typedef struct dt_htab_next dt_htab_next_t;
+extern uint32_t str2hval(const char *p, uint32_t hval);
+
extern dt_htab_t *dt_htab_create(dt_htab_ops_t *ops);
extern void dt_htab_destroy(dt_htab_t *htab);
extern int dt_htab_insert(dt_htab_t *htab, void *entry);
diff --git a/libdtrace/dt_string.c b/libdtrace/dt_string.c
index c3096947..414f1bb8 100644
--- a/libdtrace/dt_string.c
+++ b/libdtrace/dt_string.c
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -13,34 +13,6 @@
#include <dt_string.h>
-/*
- * Calculate a hash value based on a given string and an initial value. The
- * initial value is used to calculate compound hash values, e.g.
- *
- * uint32_t hval;
- *
- * hval = str2hval(str1, 0);
- * hval = str2hval(str2, hval);
- */
-uint32_t str2hval(const char *p, uint32_t hval)
-{
- uint32_t g;
-
- if (!p)
- return hval;
-
- while (*p) {
- hval = (hval << 4) + *p++;
- g = hval & 0xf0000000;
- if (g != 0) {
- hval ^= (g >> 24);
- hval ^= g;
- }
- }
-
- return hval;
-}
-
/*
* Transform string s inline, converting each embedded C escape sequence string
* to the corresponding character. For example, the substring "\n" is replaced
diff --git a/libdtrace/dt_string.h b/libdtrace/dt_string.h
index e04e2ab5..854c0fb7 100644
--- a/libdtrace/dt_string.h
+++ b/libdtrace/dt_string.h
@@ -1,6 +1,6 @@
/*
* Oracle Linux DTrace.
- * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
@@ -16,7 +16,6 @@
extern "C" {
#endif
-extern uint32_t str2hval(const char *, uint32_t);
extern size_t stresc2chr(char *);
extern char *strchr2esc(const char *, size_t);
extern const char *strbasename(const char *);
--
2.45.2
More information about the DTrace-devel
mailing list