yet another function and date name update
Related to the overhaul of glyphname hash indices
This commit is contained in:
+1
-1
@@ -344,7 +344,7 @@ struct instance_globals_d {
|
||||
/* new */
|
||||
boolean deferred_showpaths;
|
||||
char *deferred_showpaths_dir;
|
||||
boolean disable_glyphname_hashtable_prefill;
|
||||
boolean disable_glyphname_hash_indices_prefill;
|
||||
|
||||
boolean havestate;
|
||||
};
|
||||
|
||||
+3
-3
@@ -1185,9 +1185,9 @@ extern int glyphrep(const char *) NONNULLARG1;
|
||||
extern int match_glyph(char *) NONNULLARG1;
|
||||
extern void dump_all_glyphnames(FILE *fp) NONNULLARG1;
|
||||
extern void wizcustom_glyphnames(winid win);
|
||||
extern void populate_glyphname_hashtable(void);
|
||||
extern void empty_glyphname_hashtable(void);
|
||||
extern boolean glyphname_hashtable_loaded(void);
|
||||
extern void populate_glyphname_hash_indices(void);
|
||||
extern void empty_glyphname_hash_indices(void);
|
||||
extern boolean glyphname_hash_indices_loaded(void);
|
||||
extern void apply_customizations(enum graphics_sets which_set,
|
||||
enum do_customizations docustomize);
|
||||
extern void purge_custom_entries(enum graphics_sets which_set);
|
||||
|
||||
+2
-2
@@ -313,7 +313,7 @@ static const struct instance_globals_d g_init_d = {
|
||||
FALSE, /* decor_levitate_override */
|
||||
FALSE, /* deferred_showpaths */
|
||||
NULL, /* deferred_showpaths_dir */
|
||||
FALSE, /* disable_glyphname_hashtable_prefill */
|
||||
FALSE, /* disable_glyphname_hash_indices_prefill */
|
||||
TRUE, /* havestate*/
|
||||
};
|
||||
|
||||
@@ -1186,7 +1186,7 @@ decl_globals_init(void)
|
||||
gu.urole = urole_init_data;
|
||||
gu.urace = urace_init_data;
|
||||
#ifdef DISABLE_GLYPHID_CACHE_PREFILL
|
||||
gd.disable_glyphname_hashtable_prefill = TRUE;
|
||||
gd.disable_glyphname_hash_indices_prefill = TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+34
-34
@@ -26,12 +26,12 @@ struct find_struct {
|
||||
genericptr_t reserved;
|
||||
};
|
||||
static const struct find_struct zero_find = { 0 };
|
||||
struct glyphname_hashtable_entry_t {
|
||||
struct glyphname_hash_index_entry_t {
|
||||
uint32 hash;
|
||||
int glyphnum; /* NO_GLYPH (==MAX_GLYPH) marks an empty bucket */
|
||||
};
|
||||
static struct glyphname_hashtable_entry_t *glyphname_hashtable_ptr;
|
||||
static size_t glyphname_hashtable_count;
|
||||
static struct glyphname_hash_index_entry_t *glyphname_hash_indices_ptr;
|
||||
static size_t glyphname_hash_indices_count;
|
||||
static struct find_struct to_custom_symbol_find;
|
||||
static const long nonzero_black = CLR_BLACK | NH_BASIC_COLOR;
|
||||
|
||||
@@ -117,7 +117,7 @@ glyphrep_to_custom_map_entries(
|
||||
long rgb = 0L;
|
||||
boolean slash = FALSE, colon = FALSE;
|
||||
|
||||
if (!glyphname_hashtable_ptr)
|
||||
if (!glyphname_hash_indices_ptr)
|
||||
reslt = 1; /* for debugger use only; no cache available */
|
||||
nhUse(reslt);
|
||||
|
||||
@@ -198,7 +198,7 @@ fix_glyphname(char *str)
|
||||
* Returns 1 if a name was produced, 0 if this glyph has no canonical name
|
||||
* (a few unused object indices); buf[0] is set to '\0' in that case.
|
||||
* Used by parse_id's bulk-iteration paths, by find_glyph_in_hashtable to
|
||||
* verify hash matches, by populate_glyphname_hashtable to fill the table,
|
||||
* verify hash matches, by populate_glyphname_hash_indices to fill the table,
|
||||
* and by wizcustom_glyphnames. */
|
||||
staticfn int
|
||||
compose_glyph_name(int glyph, char *buf, size_t bufsz)
|
||||
@@ -514,8 +514,8 @@ glyph_find_core(
|
||||
}
|
||||
|
||||
/*
|
||||
* glyphname_hashtable is a sorted (hash, glyph) index of canonical
|
||||
* "G_xxx" identifiers. populate_glyphname_hashtable() allocates one
|
||||
* glyphname_hash_indices is a sorted (hash, glyph) index of canonical
|
||||
* "G_xxx" identifiers. populate_glyphname_hash_indices() allocates one
|
||||
* block of MAX_GLYPH * sizeof(entry) (some entries go unused for the
|
||||
* scroll/gem appearance gaps), fills it via compose_glyph_name(), and
|
||||
* sorts ascending by hash. Lookup is bsearch on the hash with
|
||||
@@ -534,8 +534,8 @@ glyph_find_core(
|
||||
staticfn int
|
||||
cmp_glyphname_entry(const void *a, const void *b)
|
||||
{
|
||||
uint32 ha = ((const struct glyphname_hashtable_entry_t *) a)->hash;
|
||||
uint32 hb = ((const struct glyphname_hashtable_entry_t *) b)->hash;
|
||||
uint32 ha = ((const struct glyphname_hash_index_entry_t *) a)->hash;
|
||||
uint32 hb = ((const struct glyphname_hash_index_entry_t *) b)->hash;
|
||||
|
||||
if (ha < hb)
|
||||
return -1;
|
||||
@@ -545,59 +545,59 @@ cmp_glyphname_entry(const void *a, const void *b)
|
||||
}
|
||||
|
||||
void
|
||||
populate_glyphname_hashtable(void)
|
||||
populate_glyphname_hash_indices(void)
|
||||
{
|
||||
int glyph;
|
||||
size_t n = 0;
|
||||
char buf[BUFSZ];
|
||||
|
||||
if (glyphname_hashtable_ptr)
|
||||
if (glyphname_hash_indices_ptr)
|
||||
return;
|
||||
glyphname_hashtable_ptr = (struct glyphname_hashtable_entry_t *) alloc(
|
||||
MAX_GLYPH * sizeof (struct glyphname_hashtable_entry_t));
|
||||
glyphname_hash_indices_ptr = (struct glyphname_hash_index_entry_t *) alloc(
|
||||
MAX_GLYPH * sizeof (struct glyphname_hash_index_entry_t));
|
||||
|
||||
for (glyph = 0; glyph < MAX_GLYPH; ++glyph) {
|
||||
if (compose_glyph_name(glyph, buf, sizeof buf)) {
|
||||
glyphname_hashtable_ptr[n].hash = glyph_hash(buf);
|
||||
glyphname_hashtable_ptr[n].glyphnum = glyph;
|
||||
glyphname_hash_indices_ptr[n].hash = glyph_hash(buf);
|
||||
glyphname_hash_indices_ptr[n].glyphnum = glyph;
|
||||
++n;
|
||||
}
|
||||
}
|
||||
qsort(glyphname_hashtable_ptr, n,
|
||||
sizeof glyphname_hashtable_ptr[0], cmp_glyphname_entry);
|
||||
glyphname_hashtable_count = n;
|
||||
qsort(glyphname_hash_indices_ptr, n,
|
||||
sizeof glyphname_hash_indices_ptr[0], cmp_glyphname_entry);
|
||||
glyphname_hash_indices_count = n;
|
||||
}
|
||||
|
||||
void
|
||||
empty_glyphname_hashtable(void)
|
||||
empty_glyphname_hash_indices(void)
|
||||
{
|
||||
if (!glyphname_hashtable_ptr)
|
||||
if (!glyphname_hash_indices_ptr)
|
||||
return;
|
||||
free(glyphname_hashtable_ptr);
|
||||
glyphname_hashtable_ptr = (struct glyphname_hashtable_entry_t *) 0;
|
||||
glyphname_hashtable_count = 0;
|
||||
free(glyphname_hash_indices_ptr);
|
||||
glyphname_hash_indices_ptr = (struct glyphname_hash_index_entry_t *) 0;
|
||||
glyphname_hash_indices_count = 0;
|
||||
}
|
||||
|
||||
staticfn int
|
||||
find_glyph_in_hashtable(const char *id)
|
||||
{
|
||||
uint32 want = glyph_hash(id);
|
||||
size_t lo = 0, hi = glyphname_hashtable_count, mid;
|
||||
size_t lo = 0, hi = glyphname_hash_indices_count, mid;
|
||||
char buf[BUFSZ];
|
||||
|
||||
/* Binary-search the sorted array for the first entry whose hash >= want. */
|
||||
while (lo < hi) {
|
||||
mid = (lo + hi) >> 1;
|
||||
if (glyphname_hashtable_ptr[mid].hash < want)
|
||||
if (glyphname_hash_indices_ptr[mid].hash < want)
|
||||
lo = mid + 1;
|
||||
else
|
||||
hi = mid;
|
||||
}
|
||||
/* Walk forward across any equal-hash neighbours, verifying each by
|
||||
reconstructing the canonical name and strcmpi'ing it back. */
|
||||
while (lo < glyphname_hashtable_count
|
||||
&& glyphname_hashtable_ptr[lo].hash == want) {
|
||||
int g = glyphname_hashtable_ptr[lo].glyphnum;
|
||||
while (lo < glyphname_hash_indices_count
|
||||
&& glyphname_hash_indices_ptr[lo].hash == want) {
|
||||
int g = glyphname_hash_indices_ptr[lo].glyphnum;
|
||||
|
||||
if (compose_glyph_name(g, buf, sizeof buf) && !strcmpi(id, buf))
|
||||
return g;
|
||||
@@ -624,9 +624,9 @@ glyph_hash(const char *id)
|
||||
}
|
||||
|
||||
boolean
|
||||
glyphname_hashtable_loaded(void)
|
||||
glyphname_hash_indices_loaded(void)
|
||||
{
|
||||
return (glyphname_hashtable_ptr != 0);
|
||||
return (glyphname_hash_indices_ptr != 0);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -646,7 +646,7 @@ glyphrep(const char *op)
|
||||
{
|
||||
int reslt = 0, glyph = NO_GLYPH;
|
||||
|
||||
if (!glyphname_hashtable_ptr)
|
||||
if (!glyphname_hash_indices_ptr)
|
||||
reslt = 1; /* for debugger use only; no cache available */
|
||||
nhUse(reslt);
|
||||
reslt = glyphrep_to_custom_map_entries(op, &glyph);
|
||||
@@ -1036,9 +1036,9 @@ parse_id(
|
||||
}
|
||||
if (is_G && id) {
|
||||
/* Populate the hash table lazily, on first G_xxx lookup. */
|
||||
if (!glyphname_hashtable_ptr)
|
||||
populate_glyphname_hashtable();
|
||||
if (glyphname_hashtable_ptr) {
|
||||
if (!glyphname_hash_indices_ptr)
|
||||
populate_glyphname_hash_indices();
|
||||
if (glyphname_hash_indices_ptr) {
|
||||
int val = find_glyph_in_hashtable(id);
|
||||
|
||||
if (val >= 0) {
|
||||
|
||||
+9
-9
@@ -4224,11 +4224,11 @@ optfn_symset(
|
||||
if (req == do_handler) {
|
||||
int reslt;
|
||||
|
||||
if (!glyphname_hashtable_loaded())
|
||||
populate_glyphname_hashtable();
|
||||
if (!glyphname_hash_indices_loaded())
|
||||
populate_glyphname_hash_indices();
|
||||
reslt = handler_symset(optidx);
|
||||
if (glyphname_hashtable_loaded())
|
||||
empty_glyphname_hashtable();
|
||||
if (glyphname_hash_indices_loaded())
|
||||
empty_glyphname_hash_indices();
|
||||
/* apply_customizations(gc.currentgraphics,
|
||||
(do_custom_colors | do_custom_symbols)); */
|
||||
return reslt;
|
||||
@@ -7152,9 +7152,9 @@ initoptions_init(void)
|
||||
}
|
||||
|
||||
/* make any symbol parsing quicker, but only if
|
||||
* gd.disable_glyphname_hashtable_prefill is not set to TRUE */
|
||||
if (!glyphname_hashtable_loaded() && !gd.disable_glyphname_hashtable_prefill)
|
||||
populate_glyphname_hashtable();
|
||||
* gd.disable_glyphname_hash_indices_prefill is not set to TRUE */
|
||||
if (!glyphname_hash_indices_loaded() && !gd.disable_glyphname_hash_indices_prefill)
|
||||
populate_glyphname_hash_indices();
|
||||
|
||||
/* set up the command parsing */
|
||||
reset_commands(TRUE); /* init */
|
||||
@@ -7377,8 +7377,8 @@ initoptions_finish(void)
|
||||
iflags.wc_ascii_map = FALSE, iflags.wc_tiled_map = TRUE;
|
||||
|
||||
#ifdef ENHANCED_SYMBOLS
|
||||
if (glyphname_hashtable_loaded())
|
||||
empty_glyphname_hashtable();
|
||||
if (glyphname_hash_indices_loaded())
|
||||
empty_glyphname_hash_indices();
|
||||
apply_customizations(gc.currentgraphics,
|
||||
do_custom_symbols | do_custom_colors);
|
||||
#endif
|
||||
|
||||
+2
-2
@@ -1175,8 +1175,8 @@ freedynamicdata(void)
|
||||
if (options_set_window_colors_flag)
|
||||
options_free_window_colors();
|
||||
|
||||
if (glyphname_hashtable_loaded())
|
||||
empty_glyphname_hashtable();
|
||||
if (glyphname_hash_indices_loaded())
|
||||
empty_glyphname_hash_indices();
|
||||
|
||||
if (tnhfp) {
|
||||
close_nhfile(tnhfp);
|
||||
|
||||
+4
-4
@@ -1069,12 +1069,12 @@ do_symset(boolean rogueflag)
|
||||
if (gs.symset[which_set].name) {
|
||||
/* non-default symbols */
|
||||
int ok;
|
||||
if (!glyphname_hashtable_loaded()) {
|
||||
populate_glyphname_hashtable();
|
||||
if (!glyphname_hash_indices_loaded()) {
|
||||
populate_glyphname_hash_indices();
|
||||
}
|
||||
ok = read_sym_file(which_set);
|
||||
if (glyphname_hashtable_loaded()) {
|
||||
empty_glyphname_hashtable();
|
||||
if (glyphname_hash_indices_loaded()) {
|
||||
empty_glyphname_hash_indices();
|
||||
}
|
||||
if (ok) {
|
||||
ready_to_switch = TRUE;
|
||||
|
||||
+4
-4
@@ -1945,8 +1945,8 @@ wiz_custom(void)
|
||||
#endif
|
||||
menu_item *pick_list = (menu_item *) 0;
|
||||
|
||||
if (!glyphname_hashtable_loaded())
|
||||
populate_glyphname_hashtable();
|
||||
if (!glyphname_hash_indices_loaded())
|
||||
populate_glyphname_hash_indices();
|
||||
|
||||
win = create_nhwindow(NHW_MENU);
|
||||
start_menu(win, MENU_BEHAVE_STANDARD);
|
||||
@@ -1975,8 +1975,8 @@ wiz_custom(void)
|
||||
#endif
|
||||
if (n >= 1)
|
||||
free((genericptr_t) pick_list);
|
||||
if (glyphname_hashtable_loaded())
|
||||
empty_glyphname_hashtable();
|
||||
if (glyphname_hash_indices_loaded())
|
||||
empty_glyphname_hash_indices();
|
||||
docrt();
|
||||
} else
|
||||
pline(unavailcmd, ecname_from_fn(wiz_custom));
|
||||
|
||||
Reference in New Issue
Block a user