[base, bdf] Use a union as a hash key. We want to support both an integer and a string key later on. * include/freetype/internal/fthash.h (FT_Hashkey): New union. (FT_HashnodeRec): Updated. (ft_hash_insert, ft_hash_lookup): Renamed to ... (ft_hash_str_insert, ft_hash_str_lookup): ... this. * src/base/fthash.c (hash_bucket): Updated. (ft_hash_insert, ft_hash_lookup): Renamed to ... (hash_insert, hash_lookup): ... this. (ft_hash_str_insert, ft_hash_str_lookup): New wrapper functions. * src/bdf/bdflib.c: Updated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
diff --git a/ChangeLog b/ChangeLog
index 24bab49..54ebb86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2015-12-20 Werner Lemberg <wl@gnu.org>
+
+ [base, bdf] Use a union as a hash key.
+
+ We want to support both an integer and a string key later on.
+
+ * include/freetype/internal/fthash.h (FT_Hashkey): New union.
+ (FT_HashnodeRec): Updated.
+ (ft_hash_insert, ft_hash_lookup): Renamed to ...
+ (ft_hash_str_insert, ft_hash_str_lookup): ... this.
+
+ * src/base/fthash.c (hash_bucket): Updated.
+ (ft_hash_insert, ft_hash_lookup): Renamed to ...
+ (hash_insert, hash_lookup): ... this.
+ (ft_hash_str_insert, ft_hash_str_lookup): New wrapper functions.
+
+ * src/bdf/bdflib.c: Updated.
+
2015-12-19 Werner Lemberg <wl@gnu.org>
[bdf] Use new hash functions.
diff --git a/include/freetype/internal/fthash.h b/include/freetype/internal/fthash.h
index 46496d6..3449b75 100644
--- a/include/freetype/internal/fthash.h
+++ b/include/freetype/internal/fthash.h
@@ -50,10 +50,18 @@
FT_BEGIN_HEADER
+ typedef union FT_Hashkey_
+ {
+ FT_Int num;
+ const char* str;
+
+ } FT_Hashkey;
+
+
typedef struct FT_HashnodeRec_
{
- const char* key;
- size_t data;
+ FT_Hashkey key;
+ size_t data;
} FT_HashnodeRec;
@@ -82,14 +90,14 @@ FT_BEGIN_HEADER
FT_Memory memory );
FT_Error
- ft_hash_insert( char* key,
- size_t data,
- FT_Hash hash,
- FT_Memory memory );
+ ft_hash_str_insert( const char* key,
+ size_t data,
+ FT_Hash hash,
+ FT_Memory memory );
FT_Hashnode
- ft_hash_lookup( const char* key,
- FT_Hash hash );
+ ft_hash_str_lookup( const char* key,
+ FT_Hash hash );
FT_END_HEADER
diff --git a/src/base/fthash.c b/src/base/fthash.c
index c26077c..091646a 100644
--- a/src/base/fthash.c
+++ b/src/base/fthash.c
@@ -47,10 +47,10 @@
static FT_Hashnode*
- hash_bucket( const char* key,
- FT_Hash hash )
+ hash_bucket( FT_Hashkey key,
+ FT_Hash hash )
{
- const char* kp = key;
+ const char* kp = key.str;
FT_ULong res = 0;
FT_Hashnode* bp = hash->table;
FT_Hashnode* ndp;
@@ -63,10 +63,10 @@
ndp = bp + ( res % hash->size );
while ( *ndp )
{
- kp = (*ndp)->key;
+ kp = (*ndp)->key.str;
- if ( kp[0] == key[0] &&
- ft_strcmp( kp, key ) == 0 )
+ if ( kp[0] == key.str[0] &&
+ ft_strcmp( kp, key.str ) == 0 )
break;
ndp--;
@@ -149,11 +149,11 @@
}
- FT_Error
- ft_hash_insert( char* key,
- size_t data,
- FT_Hash hash,
- FT_Memory memory )
+ static FT_Error
+ hash_insert( FT_Hashkey key,
+ size_t data,
+ FT_Hash hash,
+ FT_Memory memory )
{
FT_Hashnode nn;
FT_Hashnode* bp = hash_bucket( key, hash );
@@ -187,9 +187,24 @@
}
- FT_Hashnode
- ft_hash_lookup( const char* key,
- FT_Hash hash )
+ FT_Error
+ ft_hash_str_insert( const char* key,
+ size_t data,
+ FT_Hash hash,
+ FT_Memory memory )
+ {
+ FT_Hashkey hk;
+
+
+ hk.str = key;
+
+ return hash_insert( hk, data, hash, memory );
+ }
+
+
+ static FT_Hashnode
+ hash_lookup( FT_Hashkey key,
+ FT_Hash hash )
{
FT_Hashnode* np = hash_bucket( key, hash );
@@ -198,4 +213,17 @@
}
+ FT_Hashnode
+ ft_hash_str_lookup( const char* key,
+ FT_Hash hash )
+ {
+ FT_Hashkey hk;
+
+
+ hk.str = key;
+
+ return hash_lookup( hk, hash );
+ }
+
+
/* END */
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index d4c22e2..34410a2 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -812,7 +812,7 @@
/* First check whether the property has */
/* already been added or not. If it has, then */
/* simply ignore it. */
- if ( ft_hash_lookup( name, &(font->proptbl) ) )
+ if ( ft_hash_str_lookup( name, &(font->proptbl) ) )
goto Exit;
if ( FT_RENEW_ARRAY( font->user_props,
@@ -837,7 +837,7 @@
n = _num_bdf_properties + font->nuser_props;
- error = ft_hash_insert( p->name, n, &(font->proptbl), memory );
+ error = ft_hash_str_insert( p->name, n, &(font->proptbl), memory );
if ( error )
goto Exit;
@@ -859,7 +859,7 @@
if ( name == 0 || *name == 0 )
return 0;
- if ( ( hn = ft_hash_lookup( name, &(font->proptbl) ) ) == 0 )
+ if ( ( hn = ft_hash_str_lookup( name, &(font->proptbl) ) ) == 0 )
return 0;
propid = hn->data;
@@ -1084,7 +1084,7 @@
/* First, check whether the property already exists in the font. */
- if ( ( hn = ft_hash_lookup( name, (FT_Hash)font->internal ) ) != 0 )
+ if ( ( hn = ft_hash_str_lookup( name, (FT_Hash)font->internal ) ) != 0 )
{
/* The property already exists in the font, so simply replace */
/* the value of the property with the current value. */
@@ -1120,13 +1120,13 @@
/* See whether this property type exists yet or not. */
/* If not, create it. */
- hn = ft_hash_lookup( name, &(font->proptbl) );
+ hn = ft_hash_str_lookup( name, &(font->proptbl) );
if ( hn == 0 )
{
error = bdf_create_property( name, BDF_ATOM, font );
if ( error )
goto Exit;
- hn = ft_hash_lookup( name, &(font->proptbl) );
+ hn = ft_hash_str_lookup( name, &(font->proptbl) );
}
/* Allocate another property if this is overflow. */
@@ -1187,10 +1187,10 @@
if ( _bdf_strncmp( name, "COMMENT", 7 ) != 0 )
{
/* Add the property to the font property table. */
- error = ft_hash_insert( fp->name,
- font->props_used,
- (FT_Hash)font->internal,
- memory );
+ error = ft_hash_str_insert( fp->name,
+ font->props_used,
+ (FT_Hash)font->internal,
+ memory );
if ( error )
goto Exit;
}
@@ -1947,8 +1947,8 @@
for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
i < _num_bdf_properties; i++, prop++ )
{
- error = ft_hash_insert( prop->name, i,
- &(font->proptbl), memory );
+ error = ft_hash_str_insert( prop->name, i,
+ &(font->proptbl), memory );
if ( error )
goto Exit;
}
@@ -2414,7 +2414,7 @@
if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 )
return 0;
- hn = ft_hash_lookup( name, (FT_Hash)font->internal );
+ hn = ft_hash_str_lookup( name, (FT_Hash)font->internal );
return hn ? ( font->props + hn->data ) : 0;
}