[Mesa-dev] [PATCH 23/23] mesa/glsl: Move string_to_uint_map into the util folder

Thomas Helland thomashelland90 at gmail.com
Tue Aug 16 20:10:36 UTC 2016


This clears the last bits of the usecases of the hash table
located in mesa/program, allowing us to remove it.

Signed-off-by: Thomas Helland <thomashelland90 at gmail.com>
---
 src/compiler/glsl/link_uniform_initializers.cpp    |   2 +-
 src/compiler/glsl/link_uniforms.cpp                |   2 +-
 src/compiler/glsl/linker.cpp                       |   2 +-
 src/compiler/glsl/standalone.cpp                   |   2 +-
 .../glsl/tests/set_uniform_initializer_tests.cpp   |   2 +-
 src/mesa/Makefile.sources                          |   2 -
 src/mesa/main/shader_query.cpp                     |   2 +-
 src/mesa/main/shaderobj.c                          |   2 +-
 src/mesa/program/ir_to_mesa.cpp                    |   2 +-
 src/mesa/state_tracker/st_glsl_to_nir.cpp          |   2 +-
 src/util/Makefile.sources                          |   2 +
 src/{mesa/program => util}/string_to_uint_map.cpp  |   2 +-
 .../hash_table.h => util/string_to_uint_map.h}     | 160 +--------------------
 13 files changed, 17 insertions(+), 167 deletions(-)
 rename src/{mesa/program => util}/string_to_uint_map.cpp (97%)
 rename src/{mesa/program/hash_table.h => util/string_to_uint_map.h} (56%)

diff --git a/src/compiler/glsl/link_uniform_initializers.cpp b/src/compiler/glsl/link_uniform_initializers.cpp
index 021e950..68ba167 100644
--- a/src/compiler/glsl/link_uniform_initializers.cpp
+++ b/src/compiler/glsl/link_uniform_initializers.cpp
@@ -22,10 +22,10 @@
  */
 
 #include "main/core.h"
-#include "program/hash_table.h"
 #include "ir.h"
 #include "linker.h"
 #include "ir_uniform.h"
+#include "util/string_to_uint_map.h"
 
 /* These functions are put in a "private" namespace instead of being marked
  * static so that the unit tests can access them.  See
diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
index 9f8adcc..4d3fc6d 100644
--- a/src/compiler/glsl/link_uniforms.cpp
+++ b/src/compiler/glsl/link_uniforms.cpp
@@ -26,8 +26,8 @@
 #include "linker.h"
 #include "ir_uniform.h"
 #include "glsl_symbol_table.h"
-#include "program/hash_table.h"
 #include "program.h"
+#include "util/string_to_uint_map.h"
 
 /**
  * \file link_uniforms.cpp
diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
index 379a5cc..a150377 100644
--- a/src/compiler/glsl/linker.cpp
+++ b/src/compiler/glsl/linker.cpp
@@ -71,9 +71,9 @@
 #include "glsl_parser_extras.h"
 #include "ir.h"
 #include "program.h"
-#include "program/hash_table.h"
 #include "program/prog_instruction.h"
 #include "util/set.h"
+#include "util/string_to_uint_map.h"
 #include "linker.h"
 #include "link_varyings.h"
 #include "ir_optimization.h"
diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index 88fe5fd..d6e6829 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -33,10 +33,10 @@
 #include "glsl_parser_extras.h"
 #include "ir_optimization.h"
 #include "program.h"
-#include "program/hash_table.h"
 #include "loop_analysis.h"
 #include "standalone_scaffolding.h"
 #include "standalone.h"
+#include "util/string_to_uint_map.h"
 
 static const struct standalone_options *options;
 
diff --git a/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp b/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp
index 9d41017..245494c 100644
--- a/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp
+++ b/src/compiler/glsl/tests/set_uniform_initializer_tests.cpp
@@ -24,8 +24,8 @@
 #include "main/compiler.h"
 #include "main/mtypes.h"
 #include "main/macros.h"
-#include "program/hash_table.h"
 #include "util/ralloc.h"
+#include "util/string_to_uint_map.h"
 #include "uniform_initializer_utils.h"
 
 namespace linker {
diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
index d113fd3..0562443 100644
--- a/src/mesa/Makefile.sources
+++ b/src/mesa/Makefile.sources
@@ -517,7 +517,6 @@ STATETRACKER_FILES = \
 PROGRAM_FILES = \
 	program/arbprogparse.c \
 	program/arbprogparse.h \
-	program/hash_table.h \
 	program/ir_to_mesa.cpp \
 	program/ir_to_mesa.h \
 	program/lex.yy.c \
@@ -548,7 +547,6 @@ PROGRAM_FILES = \
 	program/program_parser.h \
 	program/prog_statevars.c \
 	program/prog_statevars.h \
-	program/string_to_uint_map.cpp \
 	program/symbol_table.c \
 	program/symbol_table.h
 
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 0eae39a..5c42006 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -37,7 +37,7 @@
 #include "compiler/glsl/glsl_symbol_table.h"
 #include "compiler/glsl/ir.h"
 #include "compiler/glsl/program.h"
-#include "program/hash_table.h"
+#include "util/string_to_uint_map.h"
 #include "util/strndup.h"
 
 
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 0075a6d..350b677 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -39,8 +39,8 @@
 #include "main/uniforms.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
-#include "program/hash_table.h"
 #include "util/ralloc.h"
+#include "util/string_to_uint_map.h"
 
 /**********************************************************************/
 /*** Shader object functions                                        ***/
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index e74d94f..530c00f 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -46,12 +46,12 @@
 #include "compiler/glsl_types.h"
 #include "compiler/glsl/linker.h"
 #include "compiler/glsl/program.h"
-#include "program/hash_table.h"
 #include "program/prog_instruction.h"
 #include "program/prog_optimize.h"
 #include "program/prog_print.h"
 #include "program/program.h"
 #include "program/prog_parameter.h"
+#include "util/string_to_uint_map.h"
 
 
 static int swizzle_for_size(int size);
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp
index 73a692a..9e1f160 100644
--- a/src/mesa/state_tracker/st_glsl_to_nir.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp
@@ -31,11 +31,11 @@
 #include "program/prog_statevars.h"
 #include "program/prog_parameter.h"
 #include "program/ir_to_mesa.h"
-#include "program/hash_table.h"
 #include "main/mtypes.h"
 #include "main/errors.h"
 #include "main/shaderapi.h"
 #include "main/uniforms.h"
+#include "util/string_to_uint_map.h"
 
 #include "st_context.h"
 #include "st_program.h"
diff --git a/src/util/Makefile.sources b/src/util/Makefile.sources
index 6def4f7..a778457 100644
--- a/src/util/Makefile.sources
+++ b/src/util/Makefile.sources
@@ -25,6 +25,8 @@ MESA_UTIL_FILES :=	\
 	set.c \
 	set.h \
 	simple_list.h \
+	string_to_uint_map.h \
+	string_to_uint_map.cpp \
 	strndup.c \
 	strndup.h \
 	strtod.c \
diff --git a/src/mesa/program/string_to_uint_map.cpp b/src/util/string_to_uint_map.cpp
similarity index 97%
rename from src/mesa/program/string_to_uint_map.cpp
rename to src/util/string_to_uint_map.cpp
index cfa73ab..35fb76b 100644
--- a/src/mesa/program/string_to_uint_map.cpp
+++ b/src/util/string_to_uint_map.cpp
@@ -27,7 +27,7 @@
  *
  * \author Ian Romanick <ian.d.romanick at intel.com>
  */
-#include "hash_table.h"
+#include "string_to_uint_map.h"
 
 extern "C" struct string_to_uint_map *
 string_to_uint_map_ctor()
diff --git a/src/mesa/program/hash_table.h b/src/util/string_to_uint_map.h
similarity index 56%
rename from src/mesa/program/hash_table.h
rename to src/util/string_to_uint_map.h
index bd50615..256773d 100644
--- a/src/mesa/program/hash_table.h
+++ b/src/util/string_to_uint_map.h
@@ -17,26 +17,16 @@
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file hash_table.h
- * \brief Implementation of a generic, opaque hash table data type.
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
  *
- * \author Ian Romanick <ian.d.romanick at intel.com>
  */
 
-#ifndef HASH_TABLE_H
-#define HASH_TABLE_H
+#ifndef STRING_TO_UINT_MAP_H
+#define STRING_TO_UINT_MAP_H
 
 #include <string.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdint.h>
 #include <limits.h>
-#include <assert.h>
 #include "util/hash_table.h"
 
 struct string_to_uint_map;
@@ -45,146 +35,6 @@ struct string_to_uint_map;
 extern "C" {
 #endif
 
-typedef unsigned (*hash_func_t)(const void *key);
-typedef bool (*hash_compare_func_t)(const void *key1, const void *key2);
-
-/**
- * Hash table constructor
- *
- * Creates a hash table with the specified number of buckets.  The supplied
- * \c hash and \c compare routines are used when adding elements to the table
- * and when searching for elements in the table.
- *
- * \param num_buckets  Number of buckets (bins) in the hash table.
- * \param hash         Function used to compute hash value of input keys.
- * \param compare      Function used to compare keys.
- */
-static inline struct hash_table *hash_table_ctor(UNUSED unsigned num_buckets,
-    hash_func_t hash, hash_compare_func_t compare)
-{
-   return _mesa_hash_table_create(NULL, hash, compare);
-}
-
-/**
- * Release all memory associated with a hash table
- *
- * \warning
- * This function does not release memory occupied either by keys or data.
- */
-static inline void hash_table_dtor(struct hash_table *ht)
-{
-   return _mesa_hash_table_destroy(ht, NULL);
-}
-
-/**
- * Flush all entries from a hash table
- *
- * \param ht  Table to be cleared of its entries.
- */
-static inline void hash_table_clear(struct hash_table *ht)
-{
-   return _mesa_hash_table_clear(ht, NULL);
-}
-
-/**
- * Search a hash table for a specific element
- *
- * \param ht   Table to be searched
- * \param key  Key of the desired element
- *
- * \return
- * The \c data value supplied to \c hash_table_insert when the element with
- * the matching key was added.  If no matching key exists in the table,
- * \c NULL is returned.
- */
-static inline void *hash_table_find(struct hash_table *ht, const void *key)
-{
-   struct hash_entry *entry = _mesa_hash_table_search(ht, key);
-   if (!entry)
-      return NULL;
-   return entry->data;
-}
-
-/**
- * Add an element to a hash table
- *
- * \warning
- * The value passed by \c key is kept in the hash table and is used by later
- * calls to \c hash_table_find.
- */
-static inline void hash_table_insert(struct hash_table *ht, void *data,
-                                     const void *key)
-{
-   _mesa_hash_table_insert(ht, key, data);
-}
-
-/**
- * Remove a specific element from a hash table.
- */
-static inline void hash_table_remove(struct hash_table *ht, const void *key)
-{
-   struct hash_entry *entry = _mesa_hash_table_search(ht, key);
-
-   if (entry)
-      _mesa_hash_table_remove(ht, entry);
-}
-
-/**
- * Compute hash value of a string
- *
- * \param key  Pointer to a NUL terminated string to be hashed.
- *
- * \sa hash_table_string_compare
- */
-static unsigned
-hash_table_string_hash(const void *key)
-{
-   const char *str = (const char *) key;
-   uint32_t hash = _mesa_hash_string(str);
-   return hash;
-}
-
-/**
- * Compare two strings used as keys
- *
- * This is just a wrapper around \c strcmp.
- *
- * \sa hash_table_string_hash
- */
-static bool
-hash_table_string_compare(const void *a, const void *b)
-{
-   return _mesa_key_string_equal(a, b);
-}
-
-/**
- * Compute hash value of a pointer
- *
- * \param key  Pointer to be used as a hash key
- *
- * \note
- * The memory pointed to by \c key is \b never accessed.  The value of \c key
- * itself is used as the hash key
- *
- * \sa hash_table_pointer_compare
- */
-static unsigned
-hash_table_pointer_hash(const void *key)
-{
-   return _mesa_hash_pointer(key);
-}
-
-/**
- * Compare two pointers used as keys
- *
- * \sa hash_table_pointer_hash
- */
-static bool
-hash_table_pointer_compare(const void *key1, const void *key2)
-{
-   return _mesa_key_pointer_equal(key1, key2);
-}
-
 struct string_to_uint_map *
 string_to_uint_map_ctor();
 
@@ -320,4 +170,4 @@ private:
 };
 
 #endif /* __cplusplus */
-#endif /* HASH_TABLE_H */
+#endif /* STRING_TO_UINT_MAP_H */
-- 
2.9.2



More information about the mesa-dev mailing list