[gs-cvs] rev 9376 - trunk/ghostpdl/xps
tor at ghostscript.com
tor at ghostscript.com
Mon Jan 19 10:03:25 PST 2009
Author: tor
Date: 2009-01-19 10:03:24 -0800 (Mon, 19 Jan 2009)
New Revision: 9376
Modified:
trunk/ghostpdl/xps/ghostxps.h
trunk/ghostpdl/xps/xpshash.c
Log:
Fix bugs in hash table implementation.
Modified: trunk/ghostpdl/xps/ghostxps.h
===================================================================
--- trunk/ghostpdl/xps/ghostxps.h 2009-01-19 17:13:58 UTC (rev 9375)
+++ trunk/ghostpdl/xps/ghostxps.h 2009-01-19 18:03:24 UTC (rev 9376)
@@ -81,12 +81,18 @@
#endif
/*
+ * Conditional compile time options.
+ */
+#define noXPS_LOAD_TYPE_MAPS
+
+/*
* Forward declarations.
*/
typedef struct xps_context_s xps_context_t;
typedef struct xps_part_s xps_part_t;
+typedef struct xps_type_map_s xps_type_map_t;
typedef struct xps_relation_s xps_relation_t;
typedef struct xps_document_s xps_document_t;
typedef struct xps_page_s xps_page_t;
@@ -127,7 +133,7 @@
typedef struct xps_hash_table_s xps_hash_table_t;
xps_hash_table_t *xps_hash_new(xps_context_t *ctx);
-void xps_hash_free(xps_context_t *ctx, xps_hash_table_t *table, void (*)(xps_context_t*,void*));
+void xps_hash_free(xps_context_t *ctx, xps_hash_table_t *table);
void *xps_hash_lookup(xps_hash_table_t *table, char *key);
int xps_hash_insert(xps_context_t *ctx, xps_hash_table_t *table, char *key, void *value);
void xps_hash_debug(xps_hash_table_t *table);
@@ -139,6 +145,13 @@
int xps_process_data(xps_context_t *ctx, stream_cursor_read *buf);
int xps_process_part(xps_context_t *ctx, xps_part_t *part);
+struct xps_type_map_s
+{
+ char *name;
+ char *type;
+ xps_type_map_t *next;
+};
+
struct xps_relation_s
{
char *target;
@@ -172,12 +185,13 @@
gs_color_space *scrgb;
gs_color_space *cmyk;
- xps_hash_table_t *parts;
- xps_hash_table_t *defaults;
- xps_hash_table_t *overrides;
-
+ xps_hash_table_t *part_table;
+ xps_part_t *first_part;
xps_part_t *last_part;
+ xps_type_map_t *defaults;
+ xps_type_map_t *overrides;
+
char *start_part; /* fixed document sequence */
xps_document_t *first_fixdoc; /* first fixed document */
xps_document_t *last_fixdoc; /* last fixed document */
@@ -239,6 +253,8 @@
gs_color_space *icc; /* parsed icc profile resource */
int deobfuscated; /* have we deobfuscated the font data? */
+
+ xps_part_t *next;
};
xps_part_t *xps_new_part(xps_context_t *ctx, char *name, int capacity);
@@ -250,6 +266,7 @@
char *xps_get_content_type(xps_context_t *ctx, char *partname);
+void xps_free_type_map(xps_context_t *ctx, xps_type_map_t *node);
void xps_free_relations(xps_context_t *ctx, xps_relation_t *node);
void xps_free_fixed_pages(xps_context_t *ctx);
void xps_free_fixed_documents(xps_context_t *ctx);
Modified: trunk/ghostpdl/xps/xpshash.c
===================================================================
--- trunk/ghostpdl/xps/xpshash.c 2009-01-19 17:13:58 UTC (rev 9375)
+++ trunk/ghostpdl/xps/xpshash.c 2009-01-19 18:03:24 UTC (rev 9376)
@@ -1,7 +1,7 @@
/* Linear probe hash table.
*
* Simple hashtable with open adressing linear probe.
- * Makes an internal copy of the key string.
+ * Does not manage memory of key/value pointers.
* Does not support deleting entries.
*/
@@ -73,8 +73,13 @@
int i;
for (i = 0; primes[i] != 0; i++)
+ {
if (primes[i] > old_size)
+ {
new_size = primes[i];
+ break;
+ }
+ }
old_entries = table->entries;
new_entries = xps_alloc(ctx, sizeof(xps_hash_entry_t) * new_size);
@@ -83,34 +88,23 @@
table->size = new_size;
table->entries = new_entries;
+ table->load = 0;
+ memset(table->entries, 0, sizeof(xps_hash_entry_t) * table->size);
+
for (i = 0; i < old_size; i++)
- {
if (old_entries[i].value)
xps_hash_insert(ctx, table, old_entries[i].key, old_entries[i].value);
- }
xps_free(ctx, old_entries);
return 0;
}
-void xps_hash_free(xps_context_t *ctx, xps_hash_table_t *table, void (*value_free_func)(xps_context_t*,void*))
+void xps_hash_free(xps_context_t *ctx, xps_hash_table_t *table)
{
- int i;
-
- for (i = 0; i < table->size; i++)
- {
- if (table->entries[i].key)
- xps_free(ctx, table->entries[i].key);
- if (table->entries[i].value)
- value_free_func(ctx, table->entries[i].value);
- }
-
xps_free(ctx, table->entries);
xps_free(ctx, table);
-
- return 0;
}
void *xps_hash_lookup(xps_hash_table_t *table, char *key)
@@ -133,9 +127,8 @@
int xps_hash_insert(xps_context_t *ctx, xps_hash_table_t *table, char *key, void *value)
{
- xps_hash_entry_t *entries = table->entries;
- unsigned size = table->size;
- unsigned pos = hash(key) % size;
+ xps_hash_entry_t *entries;
+ unsigned int size, pos;
/* Grow the table at 80% load */
if (table->load > table->size * 8 / 10)
@@ -144,20 +137,24 @@
return gs_rethrow(-1, "cannot grow hash table");
}
+ entries = table->entries;
+ size = table->size;
+ pos = hash(key) % size;
+
while (1)
{
if (!entries[pos].value)
{
- entries[pos].key = xps_strdup(ctx, key);
- if (!entries[pos].key)
- return gs_rethrow(-1, "outofmem: cannot copy key string");
+ entries[pos].key = key;
entries[pos].value = value;
table->load ++;
return 0;
}
if (strcmp(key, entries[pos].key) == 0)
+ {
return 0;
+ }
pos = (pos + 1) % size;
}
@@ -167,15 +164,15 @@
{
int i;
- printf("cache load %d / %d", table->load, table->size);
+ printf("hash table load %d / %d\n", table->load, table->size);
for (i = 0; i < table->size; i++)
{
if (!table->entries[i].value)
printf("table % 4d: empty\n", i);
else
- printf("table % 4d: key=%s value=%s\n", i,
- table->entries[i].key, (char*)table->entries[i].value);
+ printf("table % 4d: key=%s value=%p\n", i,
+ table->entries[i].key, table->entries[i].value);
}
}
More information about the gs-cvs
mailing list