From 43527c2cbca46e93061f762353647b742bbdc6d8 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 19 Aug 2000 19:20:04 +0000 Subject: [PATCH] If option -l is given, use memcmp for the comparison. --- ChangeLog | 4 ++++ src/key-list.cc | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2656b9..ad2714f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2000-08-19 Bruno Haible + * 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 . 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"); }