aboutsummaryrefslogtreecommitdiff
path: root/gcc/lto-streamer.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/lto-streamer.h')
-rw-r--r--gcc/lto-streamer.h47
1 files changed, 46 insertions, 1 deletions
diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
index 95fe33a..e0db8b10 100644
--- a/gcc/lto-streamer.h
+++ b/gcc/lto-streamer.h
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see
#define GCC_LTO_STREAMER_H
#include "plugin-api.h"
+#include "hash-table.h"
#include "tree.h"
#include "gimple.h"
#include "target.h"
@@ -627,6 +628,50 @@ struct lto_simple_output_block
struct lto_output_stream *main_stream;
};
+/* String hashing. */
+
+struct string_slot
+{
+ const char *s;
+ int len;
+ unsigned int slot_num;
+};
+
+/* Hashtable helpers. */
+
+struct string_slot_hasher : typed_noop_remove <string_slot>
+{
+ typedef string_slot value_type;
+ typedef string_slot compare_type;
+ static inline hashval_t hash (const value_type *);
+ static inline bool equal (const value_type *, const compare_type *);
+};
+
+/* Returns a hash code for DS. Adapted from libiberty's htab_hash_string
+ to support strings that may not end in '\0'. */
+
+inline hashval_t
+string_slot_hasher::hash (const value_type *ds)
+{
+ hashval_t r = ds->len;
+ int i;
+
+ for (i = 0; i < ds->len; i++)
+ r = r * 67 + (unsigned)ds->s[i] - 113;
+ return r;
+}
+
+/* Returns nonzero if DS1 and DS2 are equal. */
+
+inline bool
+string_slot_hasher::equal (const value_type *ds1, const compare_type *ds2)
+{
+ if (ds1->len == ds2->len)
+ return memcmp (ds1->s, ds2->s, ds1->len) == 0;
+
+ return 0;
+}
+
/* Data structure holding all the data and descriptors used when writing
an LTO file. */
struct output_block
@@ -645,7 +690,7 @@ struct output_block
/* The hash table that contains the set of strings we have seen so
far and the indexes assigned to them. */
- htab_t string_hash_table;
+ hash_table <string_slot_hasher> string_hash_table;
/* The current cgraph_node that we are currently serializing. Null
if we are serializing something else. */