aboutsummaryrefslogtreecommitdiffstats
path: root/src/chartab.c
diff options
context:
space:
mode:
authorKenichi Handa2012-08-22 18:05:50 +0900
committerKenichi Handa2012-08-22 18:05:50 +0900
commitfabc1281e9cde34ff9a19d843316d2ceca8647ad (patch)
treef38f13cab3ec6c32ab8ab49ea2e60f64969a0d22 /src/chartab.c
parent4ff819d728960bf5e52b72501c606f4bb3fde028 (diff)
parent842e3a93aa3a0826cb4148376e54cd1527d10901 (diff)
downloademacs-fabc1281e9cde34ff9a19d843316d2ceca8647ad.tar.gz
emacs-fabc1281e9cde34ff9a19d843316d2ceca8647ad.zip
merge trunk
Diffstat (limited to 'src/chartab.c')
-rw-r--r--src/chartab.c92
1 files changed, 43 insertions, 49 deletions
diff --git a/src/chartab.c b/src/chartab.c
index 6d3f83499d8..711a49ed397 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 CSET (XCHAR_TABLE (vector), parent, Qnil); 118 set_char_table_parent (vector, Qnil);
119 CSET (XCHAR_TABLE (vector), purpose, purpose); 119 set_char_table_purpose (vector, purpose);
120 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector)); 120 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
121 return vector; 121 return vector;
122} 122}
@@ -155,21 +155,17 @@ char_table_ascii (Lisp_Object table)
155static Lisp_Object 155static Lisp_Object
156copy_sub_char_table (Lisp_Object table) 156copy_sub_char_table (Lisp_Object table)
157{ 157{
158 Lisp_Object copy;
159 int depth = XINT (XSUB_CHAR_TABLE (table)->depth); 158 int depth = XINT (XSUB_CHAR_TABLE (table)->depth);
160 int min_char = XINT (XSUB_CHAR_TABLE (table)->min_char); 159 int min_char = XINT (XSUB_CHAR_TABLE (table)->min_char);
161 Lisp_Object val; 160 Lisp_Object copy = make_sub_char_table (depth, min_char, Qnil);
162 int i; 161 int i;
163 162
164 copy = make_sub_char_table (depth, min_char, Qnil);
165 /* Recursively copy any sub char-tables. */ 163 /* Recursively copy any sub char-tables. */
166 for (i = 0; i < chartab_size[depth]; i++) 164 for (i = 0; i < chartab_size[depth]; i++)
167 { 165 {
168 val = XSUB_CHAR_TABLE (table)->contents[i]; 166 Lisp_Object val = XSUB_CHAR_TABLE (table)->contents[i];
169 if (SUB_CHAR_TABLE_P (val)) 167 set_sub_char_table_contents
170 sub_char_table_set_contents (copy, i, copy_sub_char_table (val)); 168 (copy, i, SUB_CHAR_TABLE_P (val) ? copy_sub_char_table (val) : val);
171 else
172 sub_char_table_set_contents (copy, i, val);
173 } 169 }
174 170
175 return copy; 171 return copy;
@@ -185,19 +181,19 @@ copy_char_table (Lisp_Object table)
185 181
186 copy = Fmake_vector (make_number (size), Qnil); 182 copy = Fmake_vector (make_number (size), Qnil);
187 XSETPVECTYPE (XVECTOR (copy), PVEC_CHAR_TABLE); 183 XSETPVECTYPE (XVECTOR (copy), PVEC_CHAR_TABLE);
188 CSET (XCHAR_TABLE (copy), defalt, XCHAR_TABLE (table)->defalt); 184 set_char_table_defalt (copy, XCHAR_TABLE (table)->defalt);
189 CSET (XCHAR_TABLE (copy), parent, XCHAR_TABLE (table)->parent); 185 set_char_table_parent (copy, XCHAR_TABLE (table)->parent);
190 CSET (XCHAR_TABLE (copy), purpose, XCHAR_TABLE (table)->purpose); 186 set_char_table_purpose (copy, XCHAR_TABLE (table)->purpose);
191 for (i = 0; i < chartab_size[0]; i++) 187 for (i = 0; i < chartab_size[0]; i++)
192 char_table_set_contents 188 set_char_table_contents
193 (copy, i, 189 (copy, i,
194 (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i]) 190 (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
195 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i]) 191 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
196 : XCHAR_TABLE (table)->contents[i])); 192 : XCHAR_TABLE (table)->contents[i]));
197 CSET (XCHAR_TABLE (copy), ascii, char_table_ascii (copy)); 193 set_char_table_ascii (copy, char_table_ascii (copy));
198 size -= VECSIZE (struct Lisp_Char_Table) - 1; 194 size -= VECSIZE (struct Lisp_Char_Table) - 1;
199 for (i = 0; i < size; i++) 195 for (i = 0; i < size; i++)
200 char_table_set_extras (copy, i, XCHAR_TABLE (table)->extras[i]); 196 set_char_table_extras (copy, i, XCHAR_TABLE (table)->extras[i]);
201 197
202 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy)); 198 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy));
203 return copy; 199 return copy;
@@ -395,7 +391,7 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
395 Lisp_Object sub; 391 Lisp_Object sub;
396 392
397 if (depth == 3) 393 if (depth == 3)
398 sub_char_table_set_contents (table, i, val); 394 set_sub_char_table_contents (table, i, val);
399 else 395 else
400 { 396 {
401 sub = tbl->contents[i]; 397 sub = tbl->contents[i];
@@ -408,21 +404,21 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
408 sub = make_sub_char_table (depth + 1, 404 sub = make_sub_char_table (depth + 1,
409 min_char + i * chartab_chars[depth], 405 min_char + i * chartab_chars[depth],
410 sub); 406 sub);
411 sub_char_table_set_contents (table, i, sub); 407 set_sub_char_table_contents (table, i, sub);
412 } 408 }
413 } 409 }
414 sub_char_table_set (sub, c, val, is_uniprop); 410 sub_char_table_set (sub, c, val, is_uniprop);
415 } 411 }
416} 412}
417 413
418Lisp_Object 414void
419char_table_set (Lisp_Object table, int c, Lisp_Object val) 415char_table_set (Lisp_Object table, int c, Lisp_Object val)
420{ 416{
421 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 417 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
422 418
423 if (ASCII_CHAR_P (c) 419 if (ASCII_CHAR_P (c)
424 && SUB_CHAR_TABLE_P (tbl->ascii)) 420 && SUB_CHAR_TABLE_P (tbl->ascii))
425 sub_char_table_set_contents (tbl->ascii, c, val); 421 set_sub_char_table_contents (tbl->ascii, c, val);
426 else 422 else
427 { 423 {
428 int i = CHARTAB_IDX (c, 0, 0); 424 int i = CHARTAB_IDX (c, 0, 0);
@@ -432,13 +428,12 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val)
432 if (! SUB_CHAR_TABLE_P (sub)) 428 if (! SUB_CHAR_TABLE_P (sub))
433 { 429 {
434 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 430 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
435 char_table_set_contents (table, i, sub); 431 set_char_table_contents (table, i, sub);
436 } 432 }
437 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table)); 433 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table));
438 if (ASCII_CHAR_P (c)) 434 if (ASCII_CHAR_P (c))
439 CSET (tbl, ascii, char_table_ascii (table)); 435 set_char_table_ascii (table, char_table_ascii (table));
440 } 436 }
441 return val;
442} 437}
443 438
444static void 439static void
@@ -460,7 +455,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
460 if (c > to) 455 if (c > to)
461 break; 456 break;
462 if (from <= c && c + chars_in_block - 1 <= to) 457 if (from <= c && c + chars_in_block - 1 <= to)
463 sub_char_table_set_contents (table, i, val); 458 set_sub_char_table_contents (table, i, val);
464 else 459 else
465 { 460 {
466 Lisp_Object sub = tbl->contents[i]; 461 Lisp_Object sub = tbl->contents[i];
@@ -471,7 +466,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
471 else 466 else
472 { 467 {
473 sub = make_sub_char_table (depth + 1, c, sub); 468 sub = make_sub_char_table (depth + 1, c, sub);
474 sub_char_table_set_contents (table, i, sub); 469 set_sub_char_table_contents (table, i, sub);
475 } 470 }
476 } 471 }
477 sub_char_table_set_range (sub, from, to, val, is_uniprop); 472 sub_char_table_set_range (sub, from, to, val, is_uniprop);
@@ -480,7 +475,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
480} 475}
481 476
482 477
483Lisp_Object 478void
484char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val) 479char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val)
485{ 480{
486 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 481 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
@@ -499,22 +494,21 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val)
499 if (c > to) 494 if (c > to)
500 break; 495 break;
501 if (from <= c && c + chartab_chars[0] - 1 <= to) 496 if (from <= c && c + chartab_chars[0] - 1 <= to)
502 char_table_set_contents (table, i, val); 497 set_char_table_contents (table, i, val);
503 else 498 else
504 { 499 {
505 Lisp_Object sub = tbl->contents[i]; 500 Lisp_Object sub = tbl->contents[i];
506 if (! SUB_CHAR_TABLE_P (sub)) 501 if (! SUB_CHAR_TABLE_P (sub))
507 { 502 {
508 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 503 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
509 char_table_set_contents (table, i, sub); 504 set_char_table_contents (table, i, sub);
510 } 505 }
511 sub_char_table_set_range (sub, from, to, val, is_uniprop); 506 sub_char_table_set_range (sub, from, to, val, is_uniprop);
512 } 507 }
513 } 508 }
514 if (ASCII_CHAR_P (from)) 509 if (ASCII_CHAR_P (from))
515 CSET (tbl, ascii, char_table_ascii (table)); 510 set_char_table_ascii (table, char_table_ascii (table));
516 } 511 }
517 return val;
518} 512}
519 513
520 514
@@ -562,7 +556,7 @@ Return PARENT. PARENT must be either nil or another char-table. */)
562 error ("Attempt to make a chartable be its own parent"); 556 error ("Attempt to make a chartable be its own parent");
563 } 557 }
564 558
565 CSET (XCHAR_TABLE (char_table), parent, parent); 559 set_char_table_parent (char_table, parent);
566 560
567 return parent; 561 return parent;
568} 562}
@@ -593,7 +587,7 @@ DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot,
593 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table))) 587 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table)))
594 args_out_of_range (char_table, n); 588 args_out_of_range (char_table, n);
595 589
596 char_table_set_extras (char_table, XINT (n), value); 590 set_char_table_extras (char_table, XINT (n), value);
597 return value; 591 return value;
598} 592}
599 593
@@ -640,12 +634,12 @@ or a character code. Return VALUE. */)
640 { 634 {
641 int i; 635 int i;
642 636
643 CSET (XCHAR_TABLE (char_table), ascii, value); 637 set_char_table_ascii (char_table, value);
644 for (i = 0; i < chartab_size[0]; i++) 638 for (i = 0; i < chartab_size[0]; i++)
645 char_table_set_contents (char_table, i, value); 639 set_char_table_contents (char_table, i, value);
646 } 640 }
647 else if (EQ (range, Qnil)) 641 else if (EQ (range, Qnil))
648 CSET (XCHAR_TABLE (char_table), defalt, value); 642 set_char_table_defalt (char_table, value);
649 else if (CHARACTERP (range)) 643 else if (CHARACTERP (range))
650 char_table_set (char_table, XINT (range), value); 644 char_table_set (char_table, XINT (range), value);
651 else if (CONSP (range)) 645 else if (CONSP (range))
@@ -695,7 +689,7 @@ optimize_sub_char_table (Lisp_Object table, Lisp_Object test)
695 if (SUB_CHAR_TABLE_P (elt)) 689 if (SUB_CHAR_TABLE_P (elt))
696 { 690 {
697 elt = optimize_sub_char_table (elt, test); 691 elt = optimize_sub_char_table (elt, test);
698 sub_char_table_set_contents (table, 0, elt); 692 set_sub_char_table_contents (table, 0, elt);
699 } 693 }
700 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1; 694 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1;
701 for (i = 1; i < chartab_size[depth]; i++) 695 for (i = 1; i < chartab_size[depth]; i++)
@@ -704,7 +698,7 @@ optimize_sub_char_table (Lisp_Object table, Lisp_Object test)
704 if (SUB_CHAR_TABLE_P (this)) 698 if (SUB_CHAR_TABLE_P (this))
705 { 699 {
706 this = optimize_sub_char_table (this, test); 700 this = optimize_sub_char_table (this, test);
707 sub_char_table_set_contents (table, i, this); 701 set_sub_char_table_contents (table, i, this);
708 } 702 }
709 if (optimizable 703 if (optimizable
710 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */ 704 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */
@@ -732,11 +726,11 @@ equivalent and can be merged. It defaults to `equal'. */)
732 { 726 {
733 elt = XCHAR_TABLE (char_table)->contents[i]; 727 elt = XCHAR_TABLE (char_table)->contents[i];
734 if (SUB_CHAR_TABLE_P (elt)) 728 if (SUB_CHAR_TABLE_P (elt))
735 char_table_set_contents 729 set_char_table_contents
736 (char_table, i, optimize_sub_char_table (elt, test)); 730 (char_table, i, optimize_sub_char_table (elt, test));
737 } 731 }
738 /* Reset the `ascii' cache, in case it got optimized away. */ 732 /* Reset the `ascii' cache, in case it got optimized away. */
739 CSET (XCHAR_TABLE (char_table), ascii, char_table_ascii (char_table)); 733 set_char_table_ascii (char_table, char_table_ascii (char_table));
740 734
741 return Qnil; 735 return Qnil;
742} 736}
@@ -828,9 +822,9 @@ map_sub_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
828 822
829 /* This is to get a value of FROM in PARENT 823 /* This is to get a value of FROM in PARENT
830 without checking the parent of PARENT. */ 824 without checking the parent of PARENT. */
831 CSET (XCHAR_TABLE (parent), parent, Qnil); 825 set_char_table_parent (parent, Qnil);
832 val = CHAR_TABLE_REF (parent, from); 826 val = CHAR_TABLE_REF (parent, from);
833 CSET (XCHAR_TABLE (parent), parent, temp); 827 set_char_table_parent (parent, temp);
834 XSETCDR (range, make_number (c - 1)); 828 XSETCDR (range, make_number (c - 1));
835 val = map_sub_char_table (c_function, function, 829 val = map_sub_char_table (c_function, function,
836 parent, arg, val, range, 830 parent, arg, val, range,
@@ -910,9 +904,9 @@ map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
910 temp = XCHAR_TABLE (parent)->parent; 904 temp = XCHAR_TABLE (parent)->parent;
911 /* This is to get a value of FROM in PARENT without checking the 905 /* This is to get a value of FROM in PARENT without checking the
912 parent of PARENT. */ 906 parent of PARENT. */
913 CSET (XCHAR_TABLE (parent), parent, Qnil); 907 set_char_table_parent (parent, Qnil);
914 val = CHAR_TABLE_REF (parent, from); 908 val = CHAR_TABLE_REF (parent, from);
915 CSET (XCHAR_TABLE (parent), parent, temp); 909 set_char_table_parent (parent, temp);
916 val = map_sub_char_table (c_function, function, parent, arg, val, range, 910 val = map_sub_char_table (c_function, function, parent, arg, val, range,
917 parent); 911 parent);
918 table = parent; 912 table = parent;
@@ -1149,7 +1143,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1149 Lisp_Object sub = make_sub_char_table (3, min_char, Qnil); 1143 Lisp_Object sub = make_sub_char_table (3, min_char, Qnil);
1150 const unsigned char *p, *pend; 1144 const unsigned char *p, *pend;
1151 1145
1152 sub_char_table_set_contents (table, idx, sub); 1146 set_sub_char_table_contents (table, idx, sub);
1153 p = SDATA (val), pend = p + SBYTES (val); 1147 p = SDATA (val), pend = p + SBYTES (val);
1154 if (*p == 1) 1148 if (*p == 1)
1155 { 1149 {
@@ -1159,7 +1153,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1159 while (p < pend && idx < chartab_chars[2]) 1153 while (p < pend && idx < chartab_chars[2])
1160 { 1154 {
1161 int v = STRING_CHAR_ADVANCE (p); 1155 int v = STRING_CHAR_ADVANCE (p);
1162 sub_char_table_set_contents 1156 set_sub_char_table_contents
1163 (sub, idx++, v > 0 ? make_number (v) : Qnil); 1157 (sub, idx++, v > 0 ? make_number (v) : Qnil);
1164 } 1158 }
1165 } 1159 }
@@ -1185,7 +1179,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1185 } 1179 }
1186 } 1180 }
1187 while (count-- > 0) 1181 while (count-- > 0)
1188 sub_char_table_set_contents (sub, idx++, make_number (v)); 1182 set_sub_char_table_contents (sub, idx++, make_number (v));
1189 } 1183 }
1190 } 1184 }
1191/* It seems that we don't need this function because C code won't need 1185/* It seems that we don't need this function because C code won't need
@@ -1288,7 +1282,7 @@ uniprop_encode_value_numeric (Lisp_Object table, Lisp_Object value)
1288 1282
1289 args[0] = XCHAR_TABLE (table)->extras[4]; 1283 args[0] = XCHAR_TABLE (table)->extras[4];
1290 args[1] = Fmake_vector (make_number (1), value); 1284 args[1] = Fmake_vector (make_number (1), value);
1291 char_table_set_extras (table, 4, Fvconcat (2, args)); 1285 set_char_table_extras (table, 4, Fvconcat (2, args));
1292 } 1286 }
1293 return make_number (i); 1287 return make_number (i);
1294} 1288}
@@ -1350,7 +1344,7 @@ uniprop_table (Lisp_Object prop)
1350 : ! NILP (val)) 1344 : ! NILP (val))
1351 return Qnil; 1345 return Qnil;
1352 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */ 1346 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */
1353 CSET (XCHAR_TABLE (table), ascii, char_table_ascii (table)); 1347 set_char_table_ascii (table, char_table_ascii (table));
1354 return table; 1348 return table;
1355} 1349}
1356 1350