diff options
author | Bruno Haible <bruno@clisp.org> | 2000-08-19 19:20:04 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2000-08-19 19:20:04 +0000 |
commit | 43527c2cbca46e93061f762353647b742bbdc6d8 (patch) | |
tree | c6eb71a87c086559d8d771bd08abbc1a93868605 | |
parent | 03a6a86a99d923380f079c87a05c59c9e2ac1be5 (diff) | |
download | gperf-43527c2cbca46e93061f762353647b742bbdc6d8.tar.gz |
If option -l is given, use memcmp for the comparison.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/key-list.cc | 39 |
2 files changed, 40 insertions, 3 deletions
@@ -1,5 +1,9 @@ 2000-08-19 Bruno Haible <bruno@linuix.math.u-bordeaux.fr> + * src/key-list.cc (Output_Compare_Memcmp): New class. + (Key_List::output_lookup_function): When option -l is given, use + memcmp instead of strcmp or strncmp. + * doc/gperf.texi: The bug report address is <bug-gnu-utils@gnu.org>. The download address is ftp.gnu.org. Remove mention of -a and -g options (now nops). Explain effect of -c option. diff --git a/src/key-list.cc b/src/key-list.cc index 33c3906..27a2ff8 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -810,6 +810,34 @@ void Output_Compare_Strncmp::output_comparison (const Output_Expr& expr1, printf ("[len] == '\\0'"); } +/* This class outputs a comparison using memcmp. + Note that the length of expr1 (available through the local variable `len') + must be verified to be equal to the length of expr2 prior to this + comparison. */ + +struct Output_Compare_Memcmp : public Output_Compare +{ + virtual void output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const; + Output_Compare_Memcmp () {} + virtual ~Output_Compare_Memcmp () {} +}; + +void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1, + const Output_Expr& expr2) const +{ + T (Trace t ("Output_Compare_Memcmp::output_comparison");) + printf ("*"); + expr1.output_expr (); + printf (" == *"); + expr2.output_expr (); + printf (" && !memcmp ("); + expr1.output_expr (); + printf (" + 1, "); + expr2.output_expr (); + printf (" + 1, len - 1)"); +} + /* ------------------------------------------------------------------------- */ /* Generates C code for the hash function that returns the @@ -1820,10 +1848,15 @@ Key_List::output_lookup_function (void) if (!option[GLOBAL]) output_lookup_tables (); - if (option[COMP]) - output_lookup_function_body (Output_Compare_Strncmp ()); + if (option[LENTABLE]) + output_lookup_function_body (Output_Compare_Memcmp ()); else - output_lookup_function_body (Output_Compare_Strcmp ()); + { + if (option[COMP]) + output_lookup_function_body (Output_Compare_Strncmp ()); + else + output_lookup_function_body (Output_Compare_Strcmp ()); + } printf ("}\n"); } |