summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-04-01 08:13:30 +0000
committerBruno Haible <bruno@clisp.org>2003-04-01 08:13:30 +0000
commit0093e3316356271066b5df254ff193cdbc74b905 (patch)
tree43455762f0b3144d496e9079d31fbc6a4881b7bb
parent8193024d960a8aa2a780fefe8b50321f4e6c5a93 (diff)
downloadgperf-0093e3316356271066b5df254ff193cdbc74b905.tar.gz
Fill unused asso_values[] entries in search.cc, not in output.cc.
-rw-r--r--ChangeLog8
-rw-r--r--src/main.cc1
-rw-r--r--src/output.cc7
-rw-r--r--src/output.h3
-rw-r--r--src/search.cc15
5 files changed, 26 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f7e8d3f..f552e91 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2002-12-10 Bruno Haible <bruno@clisp.org>
+ * src/search.cc (Search::optimize): Fill unused asso_values[] entries
+ with a large value.
+ * src/output.h (Output::Output): Remove occurrences argument.
+ (Output::_occurrences): Remove field.
+ * src/output.cc (Output::Output): Remove occurrences argument.
+ (Output::output_hash_function): Ignore _occurrences.
+ * src/main.cc (main): Don't pass the _occurrences to Output.
+
* src/search.cc (Search::preprepare): Exit if keywords contain
out-of-range characters.
diff --git a/src/main.cc b/src/main.cc
index ec772c8..4248766 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -109,7 +109,6 @@ main (int argc, char *argv[])
searcher._alpha_inc,
searcher._total_duplicates,
searcher._alpha_size,
- searcher._occurrences,
searcher._asso_values);
outputter.output ();
diff --git a/src/output.cc b/src/output.cc
index e898254..a92a9a3 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -89,7 +89,7 @@ Output::Output (KeywordExt_List *head, const char *struct_decl,
int total_keys, int max_key_len, int min_key_len,
const Positions& positions, const unsigned int *alpha_inc,
int total_duplicates, unsigned int alpha_size,
- const int *occurrences, const int *asso_values)
+ const int *asso_values)
: _head (head), _struct_decl (struct_decl),
_struct_decl_lineno (struct_decl_lineno), _return_type (return_type),
_struct_tag (struct_tag),
@@ -103,7 +103,7 @@ Output::Output (KeywordExt_List *head, const char *struct_decl,
_max_key_len (max_key_len), _min_key_len (min_key_len),
_key_positions (positions), _alpha_inc (alpha_inc),
_total_duplicates (total_duplicates), _alpha_size (alpha_size),
- _occurrences (occurrences), _asso_values (asso_values)
+ _asso_values (asso_values)
{
}
@@ -492,8 +492,7 @@ Output::output_hash_function () const
printf (",");
if ((count % columns) == 0)
printf ("\n ");
- printf ("%*d", field_width,
- _occurrences[count] ? _asso_values[count] : _max_hash_value + 1);
+ printf ("%*d", field_width, _asso_values[count]);
}
printf ("\n"
diff --git a/src/output.h b/src/output.h
index d600547..843fdad 100644
--- a/src/output.h
+++ b/src/output.h
@@ -54,7 +54,6 @@ public:
const unsigned int *alpha_inc,
int total_duplicates,
unsigned int alpha_size,
- const int *occurrences,
const int *asso_values);
/* Generates the hash function and the key word recognizer function. */
@@ -132,8 +131,6 @@ private:
int _max_hash_value;
/* Size of alphabet. */
unsigned int const _alpha_size;
- /* Counts occurrences of each key set character. */
- const int * const _occurrences;
/* Value associated with each character. */
const int * const _asso_values;
};
diff --git a/src/search.cc b/src/search.cc
index f24a0c7..730a1ac 100644
--- a/src/search.cc
+++ b/src/search.cc
@@ -1477,6 +1477,21 @@ Search::optimize ()
/* Sorts the keyword list by hash value. */
sort ();
+
+ /* Set unused asso_values[c] to max_hash_value + 1. This is not absolutely
+ necessary, but speeds up the lookup function in many cases of lookup
+ failure: no string comparison is needed once the hash value of a string
+ is larger than the hash value of any keyword. */
+ int max_hash_value;
+ {
+ KeywordExt_List *temp;
+ for (temp = _head; temp->rest(); temp = temp->rest())
+ ;
+ max_hash_value = temp->first()->_hash_value;
+ }
+ for (unsigned int c = 0; c < _alpha_size; c++)
+ if (_occurrences[c] == 0)
+ _asso_values[c] = max_hash_value + 1;
}
/* Prints out some diagnostics upon completion. */