summaryrefslogtreecommitdiff
path: root/gs/psi/idstack.c
diff options
context:
space:
mode:
Diffstat (limited to 'gs/psi/idstack.c')
-rw-r--r--gs/psi/idstack.c238
1 files changed, 119 insertions, 119 deletions
diff --git a/gs/psi/idstack.c b/gs/psi/idstack.c
index c340ea77d..a35cc2ff3 100644
--- a/gs/psi/idstack.c
+++ b/gs/psi/idstack.c
@@ -1,6 +1,6 @@
/* Copyright (C) 2001-2006 Artifex Software, Inc.
All Rights Reserved.
-
+
This software is provided AS-IS with no warranty, either express or
implied.
@@ -52,22 +52,22 @@ dstack_find_name_by_index(dict_stack_t * pds, uint nidx)
INCR(lookups);
if (dict_is_packed(pdict)) {
- uint hash =
- dict_hash_mod(dict_name_index_hash(nidx), npairs(pdict)) + 1;
+ uint hash =
+ dict_hash_mod(dict_name_index_hash(nidx), npairs(pdict)) + 1;
- if (pdict->keys.value.packed[hash] ==
- pt_tag(pt_literal_name) + nidx
- )
- INCR(probes[0]);
- else if (pdict->keys.value.packed[hash - 1] ==
- pt_tag(pt_literal_name) + nidx
- )
- INCR(probes[1]);
+ if (pdict->keys.value.packed[hash] ==
+ pt_tag(pt_literal_name) + nidx
+ )
+ INCR(probes[0]);
+ else if (pdict->keys.value.packed[hash - 1] ==
+ pt_tag(pt_literal_name) + nidx
+ )
+ INCR(probes[1]);
}
if (gs_debug_c('d') && !(stats_dstack.lookups % 1000))
- dlprintf3("[d]lookups=%ld probe1=%ld probe2=%ld\n",
- stats_dstack.lookups, stats_dstack.probes[0],
- stats_dstack.probes[1]);
+ dlprintf3("[d]lookups=%ld probe1=%ld probe2=%ld\n",
+ stats_dstack.lookups, stats_dstack.probes[0],
+ stats_dstack.probes[1]);
return pvalue;
}
#define dstack_find_name_by_index real_dstack_find_name_by_index
@@ -81,15 +81,15 @@ dstack_dict_is_permanent(const dict_stack_t * pds, const ref * pdref)
int i;
if (pds->stack.extension_size == 0) { /* Only one block of d-stack. */
- for (i = 0; i < pds->min_size; ++i)
- if (pds->stack.bot[i].value.pdict == pdict)
- return true;
+ for (i = 0; i < pds->min_size; ++i)
+ if (pds->stack.bot[i].value.pdict == pdict)
+ return true;
} else { /* More than one block of d-stack. */
- uint count = ref_stack_count(&pds->stack);
+ uint count = ref_stack_count(&pds->stack);
- for (i = count - pds->min_size; i < count; ++i)
- if (ref_stack_index(&pds->stack, i)->value.pdict == pdict)
- return true;
+ for (i = count - pds->min_size; i < count; ++i)
+ if (ref_stack_index(&pds->stack, i)->value.pdict == pdict)
+ return true;
}
return false;
}
@@ -109,88 +109,88 @@ dstack_find_name_by_index(dict_stack_t * pds, uint nidx)
ref_packed kpack = packed_name_key(nidx);
do {
- dict *pdict = pdref->value.pdict;
- uint size = npairs(pdict);
+ dict *pdict = pdref->value.pdict;
+ uint size = npairs(pdict);
#ifdef DEBUG
- if (gs_debug_c('D')) {
- const gs_memory_t *mem = dict_mem(pdict);
- ref dnref;
+ if (gs_debug_c('D')) {
+ const gs_memory_t *mem = dict_mem(pdict);
+ ref dnref;
- name_index_ref(mem, nidx, &dnref);
- dlputs("[D]lookup ");
- debug_print_name(mem, &dnref);
- dprintf3(" in 0x%lx(%u/%u)\n",
- (ulong) pdict, dict_length(pdref),
- dict_maxlength(pdref));
- }
+ name_index_ref(mem, nidx, &dnref);
+ dlputs("[D]lookup ");
+ debug_print_name(mem, &dnref);
+ dprintf3(" in 0x%lx(%u/%u)\n",
+ (ulong) pdict, dict_length(pdref),
+ dict_maxlength(pdref));
+ }
#endif
#define INCR_DEPTH(pdref)\
INCR(depth[min(MAX_STATS_DEPTH, pds->stack.p - pdref)])
- if (dict_is_packed(pdict)) {
+ if (dict_is_packed(pdict)) {
# define found INCR_DEPTH(pdref); return packed_search_value_pointer
-# define deleted
+# define deleted
# define missing break;
# include "idicttpl.h"
# undef missing
# undef deleted
# undef found
- } else {
- /*
- * The name_index macro takes mem as its first argument, but
- * does not actually use it. The following is a little ugly,
- * but it avoids a compiler warning.
- */
- /*const gs_memory_t *_mem_not_used = dict_mem(pdict);*/
- ref *kbot = pdict->keys.value.refs;
- register ref *kp;
- int wrap = 0;
+ } else {
+ /*
+ * The name_index macro takes mem as its first argument, but
+ * does not actually use it. The following is a little ugly,
+ * but it avoids a compiler warning.
+ */
+ /*const gs_memory_t *_mem_not_used = dict_mem(pdict);*/
+ ref *kbot = pdict->keys.value.refs;
+ register ref *kp;
+ int wrap = 0;
- /* Search the dictionary */
- for (kp = kbot + dict_hash_mod(hash, size) + 2;;) {
- --kp;
- if (r_has_type(kp, t_name)) {
- if (name_index(_mem_not_used, kp) == nidx) {
- INCR_DEPTH(pdref);
- return pdict->values.value.refs + (kp - kbot);
- }
- } else if (r_has_type(kp, t_null)) { /* Empty, deleted, or wraparound. */
- /* Figure out which. */
- if (!r_has_attr(kp, a_executable))
- break;
- if (kp == kbot) { /* wrap */
- if (wrap++)
- break; /* 2 wraps */
- kp += size + 1;
- }
- }
- }
- }
+ /* Search the dictionary */
+ for (kp = kbot + dict_hash_mod(hash, size) + 2;;) {
+ --kp;
+ if (r_has_type(kp, t_name)) {
+ if (name_index(_mem_not_used, kp) == nidx) {
+ INCR_DEPTH(pdref);
+ return pdict->values.value.refs + (kp - kbot);
+ }
+ } else if (r_has_type(kp, t_null)) { /* Empty, deleted, or wraparound. */
+ /* Figure out which. */
+ if (!r_has_attr(kp, a_executable))
+ break;
+ if (kp == kbot) { /* wrap */
+ if (wrap++)
+ break; /* 2 wraps */
+ kp += size + 1;
+ }
+ }
+ }
+ }
#undef INCR_DEPTH
}
while (pdref-- > pds->stack.bot);
/* The name isn't in the top dictionary block. */
/* If there are other blocks, search them now (more slowly). */
if (!pds->stack.extension_size) /* no more blocks */
- return (ref *) 0;
+ return (ref *) 0;
{ /* We could use the STACK_LOOP macros, but for now, */
- /* we'll do things the simplest way. */
- ref key;
- uint i = pds->stack.p + 1 - pds->stack.bot;
- uint size = ref_stack_count(&pds->stack);
- ref *pvalue;
-
- dict *pdict = pds->stack.p->value.pdict;
- const gs_memory_t *mem = dict_mem(pdict);
+ /* we'll do things the simplest way. */
+ ref key;
+ uint i = pds->stack.p + 1 - pds->stack.bot;
+ uint size = ref_stack_count(&pds->stack);
+ ref *pvalue;
+
+ dict *pdict = pds->stack.p->value.pdict;
+ const gs_memory_t *mem = dict_mem(pdict);
- name_index_ref(mem, nidx, &key);
- for (; i < size; i++) {
- if (dict_find(ref_stack_index(&pds->stack, i),
- &key, &pvalue) > 0
- ) {
- INCR(depth[min(MAX_STATS_DEPTH, i)]);
- return pvalue;
- }
- }
+ name_index_ref(mem, nidx, &key);
+ for (; i < size; i++) {
+ if (dict_find(ref_stack_index(&pds->stack, i),
+ &key, &pvalue) > 0
+ ) {
+ INCR(depth[min(MAX_STATS_DEPTH, i)]);
+ return pvalue;
+ }
+ }
}
return (ref *) 0;
#undef hash
@@ -207,21 +207,21 @@ dstack_set_top(dict_stack_t * pds)
dict *pdict = dsp->value.pdict;
if_debug3('d', "[d]dsp = 0x%lx -> 0x%lx, key array type = %d\n",
- (ulong) dsp, (ulong) pdict, r_type(&pdict->keys));
+ (ulong) dsp, (ulong) pdict, r_type(&pdict->keys));
if (dict_is_packed(pdict) &&
- r_has_attr(dict_access_ref(dsp), a_read)
- ) {
- pds->top_keys = pdict->keys.value.packed;
- pds->top_npairs = npairs(pdict);
- pds->top_values = pdict->values.value.refs;
+ r_has_attr(dict_access_ref(dsp), a_read)
+ ) {
+ pds->top_keys = pdict->keys.value.packed;
+ pds->top_npairs = npairs(pdict);
+ pds->top_values = pdict->values.value.refs;
} else {
- pds->top_keys = no_packed_keys;
- pds->top_npairs = 1;
+ pds->top_keys = no_packed_keys;
+ pds->top_npairs = 1;
}
if (!r_has_attr(dict_access_ref(dsp), a_write))
- pds->def_space = -1;
+ pds->def_space = -1;
else
- pds->def_space = r_space(dsp);
+ pds->def_space = r_space(dsp);
}
/* After a garbage collection, scan the permanent dictionaries and */
@@ -233,33 +233,33 @@ dstack_gc_cleanup(dict_stack_t * pds)
uint dsi;
for (dsi = pds->min_size; dsi > 0; --dsi) {
- const dict *pdict =
- ref_stack_index(&pds->stack, count - dsi)->value.pdict;
- uint size = nslots(pdict);
- ref *pvalue = pdict->values.value.refs;
- uint i;
+ const dict *pdict =
+ ref_stack_index(&pds->stack, count - dsi)->value.pdict;
+ uint size = nslots(pdict);
+ ref *pvalue = pdict->values.value.refs;
+ uint i;
- for (i = 0; i < size; ++i, ++pvalue) {
- ref key;
- ref *old_pvalue;
+ for (i = 0; i < size; ++i, ++pvalue) {
+ ref key;
+ ref *old_pvalue;
- array_get(dict_mem(pdict), &pdict->keys, (long)i, &key);
- if (r_has_type(&key, t_name) &&
- pv_valid(old_pvalue = key.value.pname->pvalue)
- ) { /*
- * The name only has a single definition,
- * so it must be this one. Check to see if
- * no relocation is actually needed; if so,
- * we can skip the entire dictionary.
- */
- if (old_pvalue == pvalue) {
- if_debug1('d', "[d]skipping dstack entry %d\n",
- dsi - 1);
- break;
- }
- /* Update the value pointer. */
- key.value.pname->pvalue = pvalue;
- }
- }
+ array_get(dict_mem(pdict), &pdict->keys, (long)i, &key);
+ if (r_has_type(&key, t_name) &&
+ pv_valid(old_pvalue = key.value.pname->pvalue)
+ ) { /*
+ * The name only has a single definition,
+ * so it must be this one. Check to see if
+ * no relocation is actually needed; if so,
+ * we can skip the entire dictionary.
+ */
+ if (old_pvalue == pvalue) {
+ if_debug1('d', "[d]skipping dstack entry %d\n",
+ dsi - 1);
+ break;
+ }
+ /* Update the value pointer. */
+ key.value.pname->pvalue = pvalue;
+ }
+ }
}
}