aboutsummaryrefslogtreecommitdiffstats
path: root/src/chartab.c
diff options
context:
space:
mode:
authorKenichi Handa2012-08-16 21:25:17 +0900
committerKenichi Handa2012-08-16 21:25:17 +0900
commitd75ffb4ed0b2e72a9361a07d16a5c884a9459728 (patch)
tree8ac5a6a8ae033fef7fbc7fb7b09a703ef4b0ed5b /src/chartab.c
parent69c41c4070c86baac11a627e9c3d366420aeb7cc (diff)
parent250c8ab9b8f6322959fa3122db83944c30c3894b (diff)
downloademacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.tar.gz
emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.zip
merge trunk
Diffstat (limited to 'src/chartab.c')
-rw-r--r--src/chartab.c108
1 files changed, 56 insertions, 52 deletions
diff --git a/src/chartab.c b/src/chartab.c
index e1252962612..6d3f83499d8 100644
--- a/src/chartab.c
+++ b/src/chartab.c
@@ -115,8 +115,8 @@ the char-table has no extra slot. */)
115 size = VECSIZE (struct Lisp_Char_Table) - 1 + n_extras; 115 size = VECSIZE (struct Lisp_Char_Table) - 1 + n_extras;
116 vector = Fmake_vector (make_number (size), init); 116 vector = Fmake_vector (make_number (size), init);
117 XSETPVECTYPE (XVECTOR (vector), PVEC_CHAR_TABLE); 117 XSETPVECTYPE (XVECTOR (vector), PVEC_CHAR_TABLE);
118 XCHAR_TABLE (vector)->parent = Qnil; 118 CSET (XCHAR_TABLE (vector), parent, Qnil);
119 XCHAR_TABLE (vector)->purpose = purpose; 119 CSET (XCHAR_TABLE (vector), purpose, purpose);
120 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); 120 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
121 return vector; 121 return vector;
122} 122}
@@ -167,9 +167,9 @@ copy_sub_char_table (Lisp_Object table)
167 { 167 {
168 val = XSUB_CHAR_TABLE (table)->contents[i]; 168 val = XSUB_CHAR_TABLE (table)->contents[i];
169 if (SUB_CHAR_TABLE_P (val)) 169 if (SUB_CHAR_TABLE_P (val))
170 XSUB_CHAR_TABLE (copy)->contents[i] = copy_sub_char_table (val); 170 sub_char_table_set_contents (copy, i, copy_sub_char_table (val));
171 else 171 else
172 XSUB_CHAR_TABLE (copy)->contents[i] = val; 172 sub_char_table_set_contents (copy, i, val);
173 } 173 }
174 174
175 return copy; 175 return copy;
@@ -185,18 +185,19 @@ copy_char_table (Lisp_Object table)
185 185
186 copy = Fmake_vector (make_number (size), Qnil); 186 copy = Fmake_vector (make_number (size), Qnil);
187 XSETPVECTYPE (XVECTOR (copy), PVEC_CHAR_TABLE); 187 XSETPVECTYPE (XVECTOR (copy), PVEC_CHAR_TABLE);
188 XCHAR_TABLE (copy)->defalt = XCHAR_TABLE (table)->defalt; 188 CSET (XCHAR_TABLE (copy), defalt, XCHAR_TABLE (table)->defalt);
189 XCHAR_TABLE (copy)->parent = XCHAR_TABLE (table)->parent; 189 CSET (XCHAR_TABLE (copy), parent, XCHAR_TABLE (table)->parent);
190 XCHAR_TABLE (copy)->purpose = XCHAR_TABLE (table)->purpose; 190 CSET (XCHAR_TABLE (copy), purpose, XCHAR_TABLE (table)->purpose);
191 for (i = 0; i < chartab_size[0]; i++) 191 for (i = 0; i < chartab_size[0]; i++)
192 XCHAR_TABLE (copy)->contents[i] 192 char_table_set_contents
193 = (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i]) 193 (copy, i,
194 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i]) 194 (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
195 : XCHAR_TABLE (table)->contents[i]); 195 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
196 XCHAR_TABLE (copy)->ascii = char_table_ascii (copy); 196 : XCHAR_TABLE (table)->contents[i]));
197 CSET (XCHAR_TABLE (copy), ascii, char_table_ascii (copy));
197 size -= VECSIZE (struct Lisp_Char_Table) - 1; 198 size -= VECSIZE (struct Lisp_Char_Table) - 1;
198 for (i = 0; i < size; i++) 199 for (i = 0; i < size; i++)
199 XCHAR_TABLE (copy)->extras[i] = XCHAR_TABLE (table)->extras[i]; 200 char_table_set_extras (copy, i, XCHAR_TABLE (table)->extras[i]);
200 201
201 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy)); 202 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy));
202 return copy; 203 return copy;
@@ -394,7 +395,7 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
394 Lisp_Object sub; 395 Lisp_Object sub;
395 396
396 if (depth == 3) 397 if (depth == 3)
397 tbl->contents[i] = val; 398 sub_char_table_set_contents (table, i, val);
398 else 399 else
399 { 400 {
400 sub = tbl->contents[i]; 401 sub = tbl->contents[i];
@@ -407,7 +408,7 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
407 sub = make_sub_char_table (depth + 1, 408 sub = make_sub_char_table (depth + 1,
408 min_char + i * chartab_chars[depth], 409 min_char + i * chartab_chars[depth],
409 sub); 410 sub);
410 tbl->contents[i] = sub; 411 sub_char_table_set_contents (table, i, sub);
411 } 412 }
412 } 413 }
413 sub_char_table_set (sub, c, val, is_uniprop); 414 sub_char_table_set (sub, c, val, is_uniprop);
@@ -421,9 +422,7 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val)
421 422
422 if (ASCII_CHAR_P (c) 423 if (ASCII_CHAR_P (c)
423 && SUB_CHAR_TABLE_P (tbl->ascii)) 424 && SUB_CHAR_TABLE_P (tbl->ascii))
424 { 425 sub_char_table_set_contents (tbl->ascii, c, val);
425 XSUB_CHAR_TABLE (tbl->ascii)->contents[c] = val;
426 }
427 else 426 else
428 { 427 {
429 int i = CHARTAB_IDX (c, 0, 0); 428 int i = CHARTAB_IDX (c, 0, 0);
@@ -433,11 +432,11 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val)
433 if (! SUB_CHAR_TABLE_P (sub)) 432 if (! SUB_CHAR_TABLE_P (sub))
434 { 433 {
435 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 434 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
436 tbl->contents[i] = sub; 435 char_table_set_contents (table, i, sub);
437 } 436 }
438 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table)); 437 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table));
439 if (ASCII_CHAR_P (c)) 438 if (ASCII_CHAR_P (c))
440 tbl->ascii = char_table_ascii (table); 439 CSET (tbl, ascii, char_table_ascii (table));
441 } 440 }
442 return val; 441 return val;
443} 442}
@@ -461,7 +460,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
461 if (c > to) 460 if (c > to)
462 break; 461 break;
463 if (from <= c && c + chars_in_block - 1 <= to) 462 if (from <= c && c + chars_in_block - 1 <= to)
464 tbl->contents[i] = val; 463 sub_char_table_set_contents (table, i, val);
465 else 464 else
466 { 465 {
467 Lisp_Object sub = tbl->contents[i]; 466 Lisp_Object sub = tbl->contents[i];
@@ -472,7 +471,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
472 else 471 else
473 { 472 {
474 sub = make_sub_char_table (depth + 1, c, sub); 473 sub = make_sub_char_table (depth + 1, c, sub);
475 tbl->contents[i] = sub; 474 sub_char_table_set_contents (table, i, sub);
476 } 475 }
477 } 476 }
478 sub_char_table_set_range (sub, from, to, val, is_uniprop); 477 sub_char_table_set_range (sub, from, to, val, is_uniprop);
@@ -500,20 +499,20 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val)
500 if (c > to) 499 if (c > to)
501 break; 500 break;
502 if (from <= c && c + chartab_chars[0] - 1 <= to) 501 if (from <= c && c + chartab_chars[0] - 1 <= to)
503 tbl->contents[i] = val; 502 char_table_set_contents (table, i, val);
504 else 503 else
505 { 504 {
506 Lisp_Object sub = tbl->contents[i]; 505 Lisp_Object sub = tbl->contents[i];
507 if (! SUB_CHAR_TABLE_P (sub)) 506 if (! SUB_CHAR_TABLE_P (sub))
508 { 507 {
509 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 508 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
510 tbl->contents[i] = sub; 509 char_table_set_contents (table, i, sub);
511 } 510 }
512 sub_char_table_set_range (sub, from, to, val, is_uniprop); 511 sub_char_table_set_range (sub, from, to, val, is_uniprop);
513 } 512 }
514 } 513 }
515 if (ASCII_CHAR_P (from)) 514 if (ASCII_CHAR_P (from))
516 tbl->ascii = char_table_ascii (table); 515 CSET (tbl, ascii, char_table_ascii (table));
517 } 516 }
518 return val; 517 return val;
519} 518}
@@ -563,7 +562,7 @@ Return PARENT. PARENT must be either nil or another char-table. */)
563 error ("Attempt to make a chartable be its own parent"); 562 error ("Attempt to make a chartable be its own parent");
564 } 563 }
565 564
566 XCHAR_TABLE (char_table)->parent = parent; 565 CSET (XCHAR_TABLE (char_table), parent, parent);
567 566
568 return parent; 567 return parent;
569} 568}
@@ -594,7 +593,8 @@ DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot,
594 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table))) 593 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table)))
595 args_out_of_range (char_table, n); 594 args_out_of_range (char_table, n);
596 595
597 return XCHAR_TABLE (char_table)->extras[XINT (n)] = value; 596 char_table_set_extras (char_table, XINT (n), value);
597 return value;
598} 598}
599 599
600DEFUN ("char-table-range", Fchar_table_range, Schar_table_range, 600DEFUN ("char-table-range", Fchar_table_range, Schar_table_range,
@@ -640,12 +640,12 @@ or a character code. Return VALUE. */)
640 { 640 {
641 int i; 641 int i;
642 642
643 XCHAR_TABLE (char_table)->ascii = value; 643 CSET (XCHAR_TABLE (char_table), ascii, value);
644 for (i = 0; i < chartab_size[0]; i++) 644 for (i = 0; i < chartab_size[0]; i++)
645 XCHAR_TABLE (char_table)->contents[i] = value; 645 char_table_set_contents (char_table, i, value);
646 } 646 }
647 else if (EQ (range, Qnil)) 647 else if (EQ (range, Qnil))
648 XCHAR_TABLE (char_table)->defalt = value; 648 CSET (XCHAR_TABLE (char_table), defalt, value);
649 else if (CHARACTERP (range)) 649 else if (CHARACTERP (range))
650 char_table_set (char_table, XINT (range), value); 650 char_table_set (char_table, XINT (range), value);
651 else if (CONSP (range)) 651 else if (CONSP (range))
@@ -693,15 +693,19 @@ optimize_sub_char_table (Lisp_Object table, Lisp_Object test)
693 693
694 elt = XSUB_CHAR_TABLE (table)->contents[0]; 694 elt = XSUB_CHAR_TABLE (table)->contents[0];
695 if (SUB_CHAR_TABLE_P (elt)) 695 if (SUB_CHAR_TABLE_P (elt))
696 elt = XSUB_CHAR_TABLE (table)->contents[0] 696 {
697 = optimize_sub_char_table (elt, test); 697 elt = optimize_sub_char_table (elt, test);
698 sub_char_table_set_contents (table, 0, elt);
699 }
698 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1; 700 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1;
699 for (i = 1; i < chartab_size[depth]; i++) 701 for (i = 1; i < chartab_size[depth]; i++)
700 { 702 {
701 this = XSUB_CHAR_TABLE (table)->contents[i]; 703 this = XSUB_CHAR_TABLE (table)->contents[i];
702 if (SUB_CHAR_TABLE_P (this)) 704 if (SUB_CHAR_TABLE_P (this))
703 this = XSUB_CHAR_TABLE (table)->contents[i] 705 {
704 = optimize_sub_char_table (this, test); 706 this = optimize_sub_char_table (this, test);
707 sub_char_table_set_contents (table, i, this);
708 }
705 if (optimizable 709 if (optimizable
706 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */ 710 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */
707 : EQ (test, Qeq) ? !EQ (this, elt) /* Optimize `eq' case. */ 711 : EQ (test, Qeq) ? !EQ (this, elt) /* Optimize `eq' case. */
@@ -728,11 +732,11 @@ equivalent and can be merged. It defaults to `equal'. */)
728 { 732 {
729 elt = XCHAR_TABLE (char_table)->contents[i]; 733 elt = XCHAR_TABLE (char_table)->contents[i];
730 if (SUB_CHAR_TABLE_P (elt)) 734 if (SUB_CHAR_TABLE_P (elt))
731 XCHAR_TABLE (char_table)->contents[i] 735 char_table_set_contents
732 = optimize_sub_char_table (elt, test); 736 (char_table, i, optimize_sub_char_table (elt, test));
733 } 737 }
734 /* Reset the `ascii' cache, in case it got optimized away. */ 738 /* Reset the `ascii' cache, in case it got optimized away. */
735 XCHAR_TABLE (char_table)->ascii = char_table_ascii (char_table); 739 CSET (XCHAR_TABLE (char_table), ascii, char_table_ascii (char_table));
736 740
737 return Qnil; 741 return Qnil;
738} 742}
@@ -824,9 +828,9 @@ map_sub_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
824 828
825 /* This is to get a value of FROM in PARENT 829 /* This is to get a value of FROM in PARENT
826 without checking the parent of PARENT. */ 830 without checking the parent of PARENT. */
827 XCHAR_TABLE (parent)->parent = Qnil; 831 CSET (XCHAR_TABLE (parent), parent, Qnil);
828 val = CHAR_TABLE_REF (parent, from); 832 val = CHAR_TABLE_REF (parent, from);
829 XCHAR_TABLE (parent)->parent = temp; 833 CSET (XCHAR_TABLE (parent), parent, temp);
830 XSETCDR (range, make_number (c - 1)); 834 XSETCDR (range, make_number (c - 1));
831 val = map_sub_char_table (c_function, function, 835 val = map_sub_char_table (c_function, function,
832 parent, arg, val, range, 836 parent, arg, val, range,
@@ -906,9 +910,9 @@ map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
906 temp = XCHAR_TABLE (parent)->parent; 910 temp = XCHAR_TABLE (parent)->parent;
907 /* This is to get a value of FROM in PARENT without checking the 911 /* This is to get a value of FROM in PARENT without checking the
908 parent of PARENT. */ 912 parent of PARENT. */
909 XCHAR_TABLE (parent)->parent = Qnil; 913 CSET (XCHAR_TABLE (parent), parent, Qnil);
910 val = CHAR_TABLE_REF (parent, from); 914 val = CHAR_TABLE_REF (parent, from);
911 XCHAR_TABLE (parent)->parent = temp; 915 CSET (XCHAR_TABLE (parent), parent, temp);
912 val = map_sub_char_table (c_function, function, parent, arg, val, range, 916 val = map_sub_char_table (c_function, function, parent, arg, val, range,
913 parent); 917 parent);
914 table = parent; 918 table = parent;
@@ -945,11 +949,11 @@ map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
945 949
946DEFUN ("map-char-table", Fmap_char_table, Smap_char_table, 950DEFUN ("map-char-table", Fmap_char_table, Smap_char_table,
947 2, 2, 0, 951 2, 2, 0,
948 doc: /* 952 doc: /* Call FUNCTION for each character in CHAR-TABLE that has non-nil value.
949Call FUNCTION for each character in CHAR-TABLE that has non-nil value. 953FUNCTION is called with two arguments, KEY and VALUE.
950FUNCTION is called with two arguments--a key and a value. 954KEY is a character code or a cons of character codes specifying a
951The key is a character code or a cons of character codes specifying a 955range of characters that have the same value.
952range of characters that have the same value. */) 956VALUE is what (char-table-range CHAR-TABLE KEY) returns. */)
953 (Lisp_Object function, Lisp_Object char_table) 957 (Lisp_Object function, Lisp_Object char_table)
954{ 958{
955 CHECK_CHAR_TABLE (char_table); 959 CHECK_CHAR_TABLE (char_table);
@@ -1143,10 +1147,9 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1143 int min_char = (XINT (XSUB_CHAR_TABLE (table)->min_char) 1147 int min_char = (XINT (XSUB_CHAR_TABLE (table)->min_char)
1144 + chartab_chars[2] * idx); 1148 + chartab_chars[2] * idx);
1145 Lisp_Object sub = make_sub_char_table (3, min_char, Qnil); 1149 Lisp_Object sub = make_sub_char_table (3, min_char, Qnil);
1146 struct Lisp_Sub_Char_Table *subtbl = XSUB_CHAR_TABLE (sub);
1147 const unsigned char *p, *pend; 1150 const unsigned char *p, *pend;
1148 1151
1149 XSUB_CHAR_TABLE (table)->contents[idx] = sub; 1152 sub_char_table_set_contents (table, idx, sub);
1150 p = SDATA (val), pend = p + SBYTES (val); 1153 p = SDATA (val), pend = p + SBYTES (val);
1151 if (*p == 1) 1154 if (*p == 1)
1152 { 1155 {
@@ -1156,7 +1159,8 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1156 while (p < pend && idx < chartab_chars[2]) 1159 while (p < pend && idx < chartab_chars[2])
1157 { 1160 {
1158 int v = STRING_CHAR_ADVANCE (p); 1161 int v = STRING_CHAR_ADVANCE (p);
1159 subtbl->contents[idx++] = v > 0 ? make_number (v) : Qnil; 1162 sub_char_table_set_contents
1163 (sub, idx++, v > 0 ? make_number (v) : Qnil);
1160 } 1164 }
1161 } 1165 }
1162 else if (*p == 2) 1166 else if (*p == 2)
@@ -1181,7 +1185,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1181 } 1185 }
1182 } 1186 }
1183 while (count-- > 0) 1187 while (count-- > 0)
1184 subtbl->contents[idx++] = make_number (v); 1188 sub_char_table_set_contents (sub, idx++, make_number (v));
1185 } 1189 }
1186 } 1190 }
1187/* It seems that we don't need this function because C code won't need 1191/* It seems that we don't need this function because C code won't need
@@ -1284,7 +1288,7 @@ uniprop_encode_value_numeric (Lisp_Object table, Lisp_Object value)
1284 1288
1285 args[0] = XCHAR_TABLE (table)->extras[4]; 1289 args[0] = XCHAR_TABLE (table)->extras[4];
1286 args[1] = Fmake_vector (make_number (1), value); 1290 args[1] = Fmake_vector (make_number (1), value);
1287 XCHAR_TABLE (table)->extras[4] = Fvconcat (2, args); 1291 char_table_set_extras (table, 4, Fvconcat (2, args));
1288 } 1292 }
1289 return make_number (i); 1293 return make_number (i);
1290} 1294}
@@ -1346,7 +1350,7 @@ uniprop_table (Lisp_Object prop)
1346 : ! NILP (val)) 1350 : ! NILP (val))
1347 return Qnil; 1351 return Qnil;
1348 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */ 1352 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */
1349 XCHAR_TABLE (table)->ascii = char_table_ascii (table); 1353 CSET (XCHAR_TABLE (table), ascii, char_table_ascii (table));
1350 return table; 1354 return table;
1351} 1355}
1352 1356