aboutsummaryrefslogtreecommitdiffstats
path: root/src/chartab.c
diff options
context:
space:
mode:
authorJoakim Verona2012-08-19 02:44:11 +0200
committerJoakim Verona2012-08-19 02:44:11 +0200
commit5436d1df5e2ba0b4d4f72b03a1cd09b20403654b (patch)
tree532faa27319b3bb199d414dc85e63a58246d30b0 /src/chartab.c
parentd02344322b0d2fea8dd9ad9dd0a6c70e058f967b (diff)
parente757f1c6f393cf82057dbee0a4325b07f0fd55c4 (diff)
downloademacs-5436d1df5e2ba0b4d4f72b03a1cd09b20403654b.tar.gz
emacs-5436d1df5e2ba0b4d4f72b03a1cd09b20403654b.zip
upstream
Diffstat (limited to 'src/chartab.c')
-rw-r--r--src/chartab.c112
1 files changed, 55 insertions, 57 deletions
diff --git a/src/chartab.c b/src/chartab.c
index c022bc03e66..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 XCHAR_TABLE (vector)->parent = Qnil; 118 set_char_table_parent (vector, Qnil);
119 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 XSUB_CHAR_TABLE (copy)->contents[i] = copy_sub_char_table (val); 168 (copy, i, SUB_CHAR_TABLE_P (val) ? copy_sub_char_table (val) : val);
171 else
172 XSUB_CHAR_TABLE (copy)->contents[i] = val;
173 } 169 }
174 170
175 return copy; 171 return copy;
@@ -185,18 +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 XCHAR_TABLE (copy)->defalt = XCHAR_TABLE (table)->defalt; 184 set_char_table_defalt (copy, XCHAR_TABLE (table)->defalt);
189 XCHAR_TABLE (copy)->parent = XCHAR_TABLE (table)->parent; 185 set_char_table_parent (copy, XCHAR_TABLE (table)->parent);
190 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 XCHAR_TABLE (copy)->contents[i] 188 set_char_table_contents
193 = (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i]) 189 (copy, i,
194 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i]) 190 (SUB_CHAR_TABLE_P (XCHAR_TABLE (table)->contents[i])
195 : XCHAR_TABLE (table)->contents[i]); 191 ? copy_sub_char_table (XCHAR_TABLE (table)->contents[i])
196 XCHAR_TABLE (copy)->ascii = char_table_ascii (copy); 192 : XCHAR_TABLE (table)->contents[i]));
193 set_char_table_ascii (copy, char_table_ascii (copy));
197 size -= VECSIZE (struct Lisp_Char_Table) - 1; 194 size -= VECSIZE (struct Lisp_Char_Table) - 1;
198 for (i = 0; i < size; i++) 195 for (i = 0; i < size; i++)
199 XCHAR_TABLE (copy)->extras[i] = XCHAR_TABLE (table)->extras[i]; 196 set_char_table_extras (copy, i, XCHAR_TABLE (table)->extras[i]);
200 197
201 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy)); 198 XSETCHAR_TABLE (copy, XCHAR_TABLE (copy));
202 return copy; 199 return copy;
@@ -394,7 +391,7 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
394 Lisp_Object sub; 391 Lisp_Object sub;
395 392
396 if (depth == 3) 393 if (depth == 3)
397 tbl->contents[i] = val; 394 set_sub_char_table_contents (table, i, val);
398 else 395 else
399 { 396 {
400 sub = tbl->contents[i]; 397 sub = tbl->contents[i];
@@ -407,23 +404,21 @@ sub_char_table_set (Lisp_Object table, int c, Lisp_Object val, int is_uniprop)
407 sub = make_sub_char_table (depth + 1, 404 sub = make_sub_char_table (depth + 1,
408 min_char + i * chartab_chars[depth], 405 min_char + i * chartab_chars[depth],
409 sub); 406 sub);
410 tbl->contents[i] = sub; 407 set_sub_char_table_contents (table, i, sub);
411 } 408 }
412 } 409 }
413 sub_char_table_set (sub, c, val, is_uniprop); 410 sub_char_table_set (sub, c, val, is_uniprop);
414 } 411 }
415} 412}
416 413
417Lisp_Object 414void
418char_table_set (Lisp_Object table, int c, Lisp_Object val) 415char_table_set (Lisp_Object table, int c, Lisp_Object val)
419{ 416{
420 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 417 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
421 418
422 if (ASCII_CHAR_P (c) 419 if (ASCII_CHAR_P (c)
423 && SUB_CHAR_TABLE_P (tbl->ascii)) 420 && SUB_CHAR_TABLE_P (tbl->ascii))
424 { 421 set_sub_char_table_contents (tbl->ascii, c, val);
425 XSUB_CHAR_TABLE (tbl->ascii)->contents[c] = val;
426 }
427 else 422 else
428 { 423 {
429 int i = CHARTAB_IDX (c, 0, 0); 424 int i = CHARTAB_IDX (c, 0, 0);
@@ -433,13 +428,12 @@ char_table_set (Lisp_Object table, int c, Lisp_Object val)
433 if (! SUB_CHAR_TABLE_P (sub)) 428 if (! SUB_CHAR_TABLE_P (sub))
434 { 429 {
435 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 430 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
436 tbl->contents[i] = sub; 431 set_char_table_contents (table, i, sub);
437 } 432 }
438 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table)); 433 sub_char_table_set (sub, c, val, UNIPROP_TABLE_P (table));
439 if (ASCII_CHAR_P (c)) 434 if (ASCII_CHAR_P (c))
440 tbl->ascii = char_table_ascii (table); 435 set_char_table_ascii (table, char_table_ascii (table));
441 } 436 }
442 return val;
443} 437}
444 438
445static void 439static void
@@ -461,7 +455,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
461 if (c > to) 455 if (c > to)
462 break; 456 break;
463 if (from <= c && c + chars_in_block - 1 <= to) 457 if (from <= c && c + chars_in_block - 1 <= to)
464 tbl->contents[i] = val; 458 set_sub_char_table_contents (table, i, val);
465 else 459 else
466 { 460 {
467 Lisp_Object sub = tbl->contents[i]; 461 Lisp_Object sub = tbl->contents[i];
@@ -472,7 +466,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
472 else 466 else
473 { 467 {
474 sub = make_sub_char_table (depth + 1, c, sub); 468 sub = make_sub_char_table (depth + 1, c, sub);
475 tbl->contents[i] = sub; 469 set_sub_char_table_contents (table, i, sub);
476 } 470 }
477 } 471 }
478 sub_char_table_set_range (sub, from, to, val, is_uniprop); 472 sub_char_table_set_range (sub, from, to, val, is_uniprop);
@@ -481,7 +475,7 @@ sub_char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val,
481} 475}
482 476
483 477
484Lisp_Object 478void
485char_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)
486{ 480{
487 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); 481 struct Lisp_Char_Table *tbl = XCHAR_TABLE (table);
@@ -500,22 +494,21 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val)
500 if (c > to) 494 if (c > to)
501 break; 495 break;
502 if (from <= c && c + chartab_chars[0] - 1 <= to) 496 if (from <= c && c + chartab_chars[0] - 1 <= to)
503 tbl->contents[i] = val; 497 set_char_table_contents (table, i, val);
504 else 498 else
505 { 499 {
506 Lisp_Object sub = tbl->contents[i]; 500 Lisp_Object sub = tbl->contents[i];
507 if (! SUB_CHAR_TABLE_P (sub)) 501 if (! SUB_CHAR_TABLE_P (sub))
508 { 502 {
509 sub = make_sub_char_table (1, i * chartab_chars[0], sub); 503 sub = make_sub_char_table (1, i * chartab_chars[0], sub);
510 tbl->contents[i] = sub; 504 set_char_table_contents (table, i, sub);
511 } 505 }
512 sub_char_table_set_range (sub, from, to, val, is_uniprop); 506 sub_char_table_set_range (sub, from, to, val, is_uniprop);
513 } 507 }
514 } 508 }
515 if (ASCII_CHAR_P (from)) 509 if (ASCII_CHAR_P (from))
516 tbl->ascii = char_table_ascii (table); 510 set_char_table_ascii (table, char_table_ascii (table));
517 } 511 }
518 return val;
519} 512}
520 513
521 514
@@ -563,7 +556,7 @@ Return PARENT. PARENT must be either nil or another char-table. */)
563 error ("Attempt to make a chartable be its own parent"); 556 error ("Attempt to make a chartable be its own parent");
564 } 557 }
565 558
566 XCHAR_TABLE (char_table)->parent = parent; 559 set_char_table_parent (char_table, parent);
567 560
568 return parent; 561 return parent;
569} 562}
@@ -594,7 +587,8 @@ DEFUN ("set-char-table-extra-slot", Fset_char_table_extra_slot,
594 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table))) 587 || XINT (n) >= CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (char_table)))
595 args_out_of_range (char_table, n); 588 args_out_of_range (char_table, n);
596 589
597 return XCHAR_TABLE (char_table)->extras[XINT (n)] = value; 590 set_char_table_extras (char_table, XINT (n), value);
591 return value;
598} 592}
599 593
600DEFUN ("char-table-range", Fchar_table_range, Schar_table_range, 594DEFUN ("char-table-range", Fchar_table_range, Schar_table_range,
@@ -640,12 +634,12 @@ or a character code. Return VALUE. */)
640 { 634 {
641 int i; 635 int i;
642 636
643 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 XCHAR_TABLE (char_table)->contents[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 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))
@@ -693,15 +687,19 @@ optimize_sub_char_table (Lisp_Object table, Lisp_Object test)
693 687
694 elt = XSUB_CHAR_TABLE (table)->contents[0]; 688 elt = XSUB_CHAR_TABLE (table)->contents[0];
695 if (SUB_CHAR_TABLE_P (elt)) 689 if (SUB_CHAR_TABLE_P (elt))
696 elt = XSUB_CHAR_TABLE (table)->contents[0] 690 {
697 = optimize_sub_char_table (elt, test); 691 elt = optimize_sub_char_table (elt, test);
692 set_sub_char_table_contents (table, 0, elt);
693 }
698 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1; 694 optimizable = SUB_CHAR_TABLE_P (elt) ? 0 : 1;
699 for (i = 1; i < chartab_size[depth]; i++) 695 for (i = 1; i < chartab_size[depth]; i++)
700 { 696 {
701 this = XSUB_CHAR_TABLE (table)->contents[i]; 697 this = XSUB_CHAR_TABLE (table)->contents[i];
702 if (SUB_CHAR_TABLE_P (this)) 698 if (SUB_CHAR_TABLE_P (this))
703 this = XSUB_CHAR_TABLE (table)->contents[i] 699 {
704 = optimize_sub_char_table (this, test); 700 this = optimize_sub_char_table (this, test);
701 set_sub_char_table_contents (table, i, this);
702 }
705 if (optimizable 703 if (optimizable
706 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */ 704 && (NILP (test) ? NILP (Fequal (this, elt)) /* defaults to `equal'. */
707 : EQ (test, Qeq) ? !EQ (this, elt) /* Optimize `eq' case. */ 705 : EQ (test, Qeq) ? !EQ (this, elt) /* Optimize `eq' case. */
@@ -728,11 +726,11 @@ equivalent and can be merged. It defaults to `equal'. */)
728 { 726 {
729 elt = XCHAR_TABLE (char_table)->contents[i]; 727 elt = XCHAR_TABLE (char_table)->contents[i];
730 if (SUB_CHAR_TABLE_P (elt)) 728 if (SUB_CHAR_TABLE_P (elt))
731 XCHAR_TABLE (char_table)->contents[i] 729 set_char_table_contents
732 = optimize_sub_char_table (elt, test); 730 (char_table, i, optimize_sub_char_table (elt, test));
733 } 731 }
734 /* Reset the `ascii' cache, in case it got optimized away. */ 732 /* Reset the `ascii' cache, in case it got optimized away. */
735 XCHAR_TABLE (char_table)->ascii = char_table_ascii (char_table); 733 set_char_table_ascii (char_table, char_table_ascii (char_table));
736 734
737 return Qnil; 735 return Qnil;
738} 736}
@@ -824,9 +822,9 @@ map_sub_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
824 822
825 /* This is to get a value of FROM in PARENT 823 /* This is to get a value of FROM in PARENT
826 without checking the parent of PARENT. */ 824 without checking the parent of PARENT. */
827 XCHAR_TABLE (parent)->parent = Qnil; 825 set_char_table_parent (parent, Qnil);
828 val = CHAR_TABLE_REF (parent, from); 826 val = CHAR_TABLE_REF (parent, from);
829 XCHAR_TABLE (parent)->parent = temp; 827 set_char_table_parent (parent, temp);
830 XSETCDR (range, make_number (c - 1)); 828 XSETCDR (range, make_number (c - 1));
831 val = map_sub_char_table (c_function, function, 829 val = map_sub_char_table (c_function, function,
832 parent, arg, val, range, 830 parent, arg, val, range,
@@ -906,9 +904,9 @@ map_char_table (void (*c_function) (Lisp_Object, Lisp_Object, Lisp_Object),
906 temp = XCHAR_TABLE (parent)->parent; 904 temp = XCHAR_TABLE (parent)->parent;
907 /* 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
908 parent of PARENT. */ 906 parent of PARENT. */
909 XCHAR_TABLE (parent)->parent = Qnil; 907 set_char_table_parent (parent, Qnil);
910 val = CHAR_TABLE_REF (parent, from); 908 val = CHAR_TABLE_REF (parent, from);
911 XCHAR_TABLE (parent)->parent = temp; 909 set_char_table_parent (parent, temp);
912 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,
913 parent); 911 parent);
914 table = parent; 912 table = parent;
@@ -1143,10 +1141,9 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1143 int min_char = (XINT (XSUB_CHAR_TABLE (table)->min_char) 1141 int min_char = (XINT (XSUB_CHAR_TABLE (table)->min_char)
1144 + chartab_chars[2] * idx); 1142 + chartab_chars[2] * idx);
1145 Lisp_Object sub = make_sub_char_table (3, min_char, Qnil); 1143 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; 1144 const unsigned char *p, *pend;
1148 1145
1149 XSUB_CHAR_TABLE (table)->contents[idx] = sub; 1146 set_sub_char_table_contents (table, idx, sub);
1150 p = SDATA (val), pend = p + SBYTES (val); 1147 p = SDATA (val), pend = p + SBYTES (val);
1151 if (*p == 1) 1148 if (*p == 1)
1152 { 1149 {
@@ -1156,7 +1153,8 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1156 while (p < pend && idx < chartab_chars[2]) 1153 while (p < pend && idx < chartab_chars[2])
1157 { 1154 {
1158 int v = STRING_CHAR_ADVANCE (p); 1155 int v = STRING_CHAR_ADVANCE (p);
1159 subtbl->contents[idx++] = v > 0 ? make_number (v) : Qnil; 1156 set_sub_char_table_contents
1157 (sub, idx++, v > 0 ? make_number (v) : Qnil);
1160 } 1158 }
1161 } 1159 }
1162 else if (*p == 2) 1160 else if (*p == 2)
@@ -1181,7 +1179,7 @@ uniprop_table_uncompress (Lisp_Object table, int idx)
1181 } 1179 }
1182 } 1180 }
1183 while (count-- > 0) 1181 while (count-- > 0)
1184 subtbl->contents[idx++] = make_number (v); 1182 set_sub_char_table_contents (sub, idx++, make_number (v));
1185 } 1183 }
1186 } 1184 }
1187/* 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
@@ -1284,7 +1282,7 @@ uniprop_encode_value_numeric (Lisp_Object table, Lisp_Object value)
1284 1282
1285 args[0] = XCHAR_TABLE (table)->extras[4]; 1283 args[0] = XCHAR_TABLE (table)->extras[4];
1286 args[1] = Fmake_vector (make_number (1), value); 1284 args[1] = Fmake_vector (make_number (1), value);
1287 XCHAR_TABLE (table)->extras[4] = Fvconcat (2, args); 1285 set_char_table_extras (table, 4, Fvconcat (2, args));
1288 } 1286 }
1289 return make_number (i); 1287 return make_number (i);
1290} 1288}
@@ -1346,7 +1344,7 @@ uniprop_table (Lisp_Object prop)
1346 : ! NILP (val)) 1344 : ! NILP (val))
1347 return Qnil; 1345 return Qnil;
1348 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */ 1346 /* Prepare ASCII values in advance for CHAR_TABLE_REF. */
1349 XCHAR_TABLE (table)->ascii = char_table_ascii (table); 1347 set_char_table_ascii (table, char_table_ascii (table));
1350 return table; 1348 return table;
1351} 1349}
1352 1350