changeset 95430:04a952ac356f

* chartab.c (Foptimize_char_table, optimize_sub_char_table): Add a `test' argument so another predicate than `equal' can be used. (map_sub_char_table): Use `eq' rather than `equal' to merge ranges. (map_char_table): Remove unused vars `c' and `i'. * lisp.h (Foptimize_char_table): Adjust declaration. * charset.c (Fclear_charset_maps): Adjust call to Foptimize_char_table.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 30 May 2008 21:07:50 +0000
parents efb06c4d4792
children a86a38ec3662
files src/ChangeLog src/charset.c src/chartab.c src/lisp.h
diffstat 4 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri May 30 19:52:41 2008 +0000
+++ b/src/ChangeLog	Fri May 30 21:07:50 2008 +0000
@@ -1,7 +1,15 @@
+2008-05-30  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* chartab.c (Foptimize_char_table, optimize_sub_char_table):
+	Add a `test' argument so another predicate than `equal' can be used.
+	(map_sub_char_table): Use `eq' rather than `equal' to merge ranges.
+	(map_char_table): Remove unused vars `c' and `i'.
+	* lisp.h (Foptimize_char_table): Adjust declaration.
+	* charset.c (Fclear_charset_maps): Adjust call to Foptimize_char_table.
+
 2008-05-30  Kenichi Handa  <handa@m17n.org>
 
-	* font.c (Ffont_info): Define only if HAVE_WINDOW_SYSTEM is
-	defined.
+	* font.c (Ffont_info): Define only if HAVE_WINDOW_SYSTEM is defined.
 	(syms_of_font): Defsubr Sfont_info only if HAVE_WINDOW_SYSTEM is
 	defined.
 
--- a/src/charset.c	Fri May 30 19:52:41 2008 +0000
+++ b/src/charset.c	Fri May 30 21:07:50 2008 +0000
@@ -1952,7 +1952,7 @@
 
   if (CHAR_TABLE_P (Vchar_unified_charset_table))
     {
-      Foptimize_char_table (Vchar_unified_charset_table);
+      Foptimize_char_table (Vchar_unified_charset_table, Qnil);
       Vchar_unify_table = Vchar_unified_charset_table;
       Vchar_unified_charset_table = Qnil;
     }
--- a/src/chartab.c	Fri May 30 19:52:41 2008 +0000
+++ b/src/chartab.c	Fri May 30 21:07:50 2008 +0000
@@ -159,14 +159,12 @@
   XCHAR_TABLE (copy)->defalt = XCHAR_TABLE (table)->defalt;
   XCHAR_TABLE (copy)->parent = XCHAR_TABLE (table)->parent;
   XCHAR_TABLE (copy)->purpose = XCHAR_TABLE (table)->purpose;
-  XCHAR_TABLE (copy)->ascii = XCHAR_TABLE (table)->ascii;
   for (i = 0; i < chartab_size[0]; i++)
     XCHAR_TABLE (copy)->contents[i]
       = (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
 	 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
 	 : XCHAR_TABLE (table)->contents[i]);
-  if (SUB_CHAR_TABLE_P (XCHAR_TABLE (copy)->ascii))
-    XCHAR_TABLE (copy)->ascii = char_table_ascii (copy);
+  XCHAR_TABLE (copy)->ascii = char_table_ascii (copy);
   size -= VECSIZE (struct Lisp_Char_Table) - 1;
   for (i = 0; i < size; i++)
     XCHAR_TABLE (copy)->extras[i] = XCHAR_TABLE (table)->extras[i];
@@ -656,8 +654,8 @@
 }
 
 static Lisp_Object
-optimize_sub_char_table (table)
-     Lisp_Object table;
+optimize_sub_char_table (table, test)
+     Lisp_Object table, test;
 {
   struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table);
   int depth = XINT (tbl->depth);
@@ -666,7 +664,8 @@
 
   elt = XSUB_CHAR_TABLE (table)->contents[0];
   if (SUB_CHAR_TABLE_P (elt))
-    elt = XSUB_CHAR_TABLE (table)->contents[0] = optimize_sub_char_table (elt);
+    elt = XSUB_CHAR_TABLE (table)->contents[0]
+      = optimize_sub_char_table (elt, test);
   if (SUB_CHAR_TABLE_P (elt))
     return table;
   for (i = 1; i < chartab_size[depth]; i++)
@@ -674,9 +673,11 @@
       this = XSUB_CHAR_TABLE (table)->contents[i];
       if (SUB_CHAR_TABLE_P (this))
 	this = XSUB_CHAR_TABLE (table)->contents[i]
-	  = optimize_sub_char_table (this);
+	  = optimize_sub_char_table (this, test);
       if (SUB_CHAR_TABLE_P (this)
-	  || NILP (Fequal (this, elt)))
+	  || (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */
+	      : EQ (test, Qeq) ? !EQ (this, elt)      /* Optimize `eq' case.  */
+	      : NILP (call2 (test, this, elt))))
 	break;
     }
 
@@ -684,10 +685,12 @@
 }
 
 DEFUN ("optimize-char-table", Foptimize_char_table, Soptimize_char_table,
-       1, 1, 0,
-       doc: /* Optimize CHAR-TABLE.  */)
-     (char_table)
-     Lisp_Object char_table;
+       1, 2, 0,
+       doc: /* Optimize CHAR-TABLE.
+TEST is the comparison function used to decide whether two entries are
+equivalent and can be merged.  It defaults to `equal'.  */)
+     (char_table, test)
+     Lisp_Object char_table, test;
 {
   Lisp_Object elt;
   int i;
@@ -698,7 +701,8 @@
     {
       elt = XCHAR_TABLE (char_table)->contents[i];
       if (SUB_CHAR_TABLE_P (elt))
-	XCHAR_TABLE (char_table)->contents[i] = optimize_sub_char_table (elt);
+	XCHAR_TABLE (char_table)->contents[i]
+	  = optimize_sub_char_table (elt, test);
     }
   return Qnil;
 }
@@ -777,7 +781,7 @@
 	{
 	  if (NILP (this))
 	    this = default_val;
-	  if (NILP (Fequal (val, this)))
+	  if (!EQ (val, this))
 	    {
 	      int different_value = 1;
 
@@ -797,7 +801,7 @@
 						parent, arg, val, range,
 						XCHAR_TABLE (parent)->defalt,
 						XCHAR_TABLE (parent)->parent);
-		      if (! NILP (Fequal (val, this)))
+		      if (EQ (val, this))
 			different_value = 0;
 		    }
 		}
@@ -841,7 +845,6 @@
      Lisp_Object function, table, arg;
 {
   Lisp_Object range, val;
-  int c, i;
   struct gcpro gcpro1, gcpro2, gcpro3;
 
   range = Fcons (make_number (0), make_number (MAX_CHAR));
--- a/src/lisp.h	Fri May 30 19:52:41 2008 +0000
+++ b/src/lisp.h	Fri May 30 21:07:50 2008 +0000
@@ -2628,7 +2628,7 @@
 EXFUN (Fchar_table_range, 2);
 EXFUN (Fset_char_table_range, 3);
 EXFUN (Fset_char_table_default, 3);
-EXFUN (Foptimize_char_table, 1);
+EXFUN (Foptimize_char_table, 2);
 EXFUN (Fmap_char_table, 2);
 extern Lisp_Object copy_char_table P_ ((Lisp_Object));
 extern Lisp_Object sub_char_table_ref P_ ((Lisp_Object, int));