diff options
| author | Joakim Verona | 2011-06-16 00:22:07 +0200 |
|---|---|---|
| committer | Joakim Verona | 2011-06-16 00:22:07 +0200 |
| commit | a7513ade3bc0fe79430d5541d88c9dcda0932bec (patch) | |
| tree | 4383951ba698a11e9f8933a9d8c72e00aa872a10 /src/chartab.c | |
| parent | 4bd51ad5c3445b644dfb017d5b57b10a90aa325f (diff) | |
| parent | 4bba86e6210a74326e843a8fdc8409127105e1fe (diff) | |
| download | emacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.tar.gz emacs-a7513ade3bc0fe79430d5541d88c9dcda0932bec.zip | |
merge from upstream
Diffstat (limited to 'src/chartab.c')
| -rw-r--r-- | src/chartab.c | 76 |
1 files changed, 31 insertions, 45 deletions
diff --git a/src/chartab.c b/src/chartab.c index cd8aa784eb4..ed5b238646e 100644 --- a/src/chartab.c +++ b/src/chartab.c | |||
| @@ -36,7 +36,7 @@ const int chartab_size[4] = | |||
| 36 | 36 | ||
| 37 | /* Number of characters each element of Nth level char-table | 37 | /* Number of characters each element of Nth level char-table |
| 38 | covers. */ | 38 | covers. */ |
| 39 | const int chartab_chars[4] = | 39 | static const int chartab_chars[4] = |
| 40 | { (1 << (CHARTAB_SIZE_BITS_1 + CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3)), | 40 | { (1 << (CHARTAB_SIZE_BITS_1 + CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3)), |
| 41 | (1 << (CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3)), | 41 | (1 << (CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3)), |
| 42 | (1 << CHARTAB_SIZE_BITS_3), | 42 | (1 << CHARTAB_SIZE_BITS_3), |
| @@ -44,7 +44,7 @@ const int chartab_chars[4] = | |||
| 44 | 44 | ||
| 45 | /* Number of characters (in bits) each element of Nth level char-table | 45 | /* Number of characters (in bits) each element of Nth level char-table |
| 46 | covers. */ | 46 | covers. */ |
| 47 | const int chartab_bits[4] = | 47 | static const int chartab_bits[4] = |
| 48 | { (CHARTAB_SIZE_BITS_1 + CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3), | 48 | { (CHARTAB_SIZE_BITS_1 + CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3), |
| 49 | (CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3), | 49 | (CHARTAB_SIZE_BITS_2 + CHARTAB_SIZE_BITS_3), |
| 50 | CHARTAB_SIZE_BITS_3, | 50 | CHARTAB_SIZE_BITS_3, |
| @@ -118,7 +118,7 @@ char_table_ascii (Lisp_Object table) | |||
| 118 | return XSUB_CHAR_TABLE (sub)->contents[0]; | 118 | return XSUB_CHAR_TABLE (sub)->contents[0]; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | Lisp_Object | 121 | static Lisp_Object |
| 122 | copy_sub_char_table (Lisp_Object table) | 122 | copy_sub_char_table (Lisp_Object table) |
| 123 | { | 123 | { |
| 124 | Lisp_Object copy; | 124 | Lisp_Object copy; |
| @@ -146,7 +146,7 @@ Lisp_Object | |||
| 146 | copy_char_table (Lisp_Object table) | 146 | copy_char_table (Lisp_Object table) |
| 147 | { | 147 | { |
| 148 | Lisp_Object copy; | 148 | Lisp_Object copy; |
| 149 | int size = XCHAR_TABLE (table)->size & PSEUDOVECTOR_SIZE_MASK; | 149 | int size = XCHAR_TABLE (table)->header.size & PSEUDOVECTOR_SIZE_MASK; |
| 150 | int i; | 150 | int i; |
| 151 | 151 | ||
| 152 | copy = Fmake_vector (make_number (size), Qnil); | 152 | copy = Fmake_vector (make_number (size), Qnil); |
| @@ -215,17 +215,16 @@ sub_char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to, Lisp | |||
| 215 | struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); | 215 | struct Lisp_Sub_Char_Table *tbl = XSUB_CHAR_TABLE (table); |
| 216 | int depth = XINT (tbl->depth); | 216 | int depth = XINT (tbl->depth); |
| 217 | int min_char = XINT (tbl->min_char); | 217 | int min_char = XINT (tbl->min_char); |
| 218 | int max_char = min_char + chartab_chars[depth - 1] - 1; | 218 | int chartab_idx = CHARTAB_IDX (c, depth, min_char), idx; |
| 219 | int index = CHARTAB_IDX (c, depth, min_char), idx; | ||
| 220 | Lisp_Object val; | 219 | Lisp_Object val; |
| 221 | 220 | ||
| 222 | val = tbl->contents[index]; | 221 | val = tbl->contents[chartab_idx]; |
| 223 | if (SUB_CHAR_TABLE_P (val)) | 222 | if (SUB_CHAR_TABLE_P (val)) |
| 224 | val = sub_char_table_ref_and_range (val, c, from, to, defalt); | 223 | val = sub_char_table_ref_and_range (val, c, from, to, defalt); |
| 225 | else if (NILP (val)) | 224 | else if (NILP (val)) |
| 226 | val = defalt; | 225 | val = defalt; |
| 227 | 226 | ||
| 228 | idx = index; | 227 | idx = chartab_idx; |
| 229 | while (idx > 0 && *from < min_char + idx * chartab_chars[depth]) | 228 | while (idx > 0 && *from < min_char + idx * chartab_chars[depth]) |
| 230 | { | 229 | { |
| 231 | Lisp_Object this_val; | 230 | Lisp_Object this_val; |
| @@ -244,13 +243,14 @@ sub_char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to, Lisp | |||
| 244 | break; | 243 | break; |
| 245 | } | 244 | } |
| 246 | } | 245 | } |
| 247 | while ((c = min_char + (index + 1) * chartab_chars[depth]) <= max_char | 246 | while (((c = (chartab_idx + 1) * chartab_chars[depth]) |
| 248 | && *to >= c) | 247 | < chartab_chars[depth - 1]) |
| 248 | && (c += min_char) <= *to) | ||
| 249 | { | 249 | { |
| 250 | Lisp_Object this_val; | 250 | Lisp_Object this_val; |
| 251 | 251 | ||
| 252 | index++; | 252 | chartab_idx++; |
| 253 | this_val = tbl->contents[index]; | 253 | this_val = tbl->contents[chartab_idx]; |
| 254 | if (SUB_CHAR_TABLE_P (this_val)) | 254 | if (SUB_CHAR_TABLE_P (this_val)) |
| 255 | this_val = sub_char_table_ref_and_range (this_val, c, from, to, defalt); | 255 | this_val = sub_char_table_ref_and_range (this_val, c, from, to, defalt); |
| 256 | else if (NILP (this_val)) | 256 | else if (NILP (this_val)) |
| @@ -275,10 +275,10 @@ Lisp_Object | |||
| 275 | char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to) | 275 | char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to) |
| 276 | { | 276 | { |
| 277 | struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); | 277 | struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); |
| 278 | int index = CHARTAB_IDX (c, 0, 0), idx; | 278 | int chartab_idx = CHARTAB_IDX (c, 0, 0), idx; |
| 279 | Lisp_Object val; | 279 | Lisp_Object val; |
| 280 | 280 | ||
| 281 | val = tbl->contents[index]; | 281 | val = tbl->contents[chartab_idx]; |
| 282 | if (*from < 0) | 282 | if (*from < 0) |
| 283 | *from = 0; | 283 | *from = 0; |
| 284 | if (*to < 0) | 284 | if (*to < 0) |
| @@ -288,7 +288,7 @@ char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to) | |||
| 288 | else if (NILP (val)) | 288 | else if (NILP (val)) |
| 289 | val = tbl->defalt; | 289 | val = tbl->defalt; |
| 290 | 290 | ||
| 291 | idx = index; | 291 | idx = chartab_idx; |
| 292 | while (*from < idx * chartab_chars[0]) | 292 | while (*from < idx * chartab_chars[0]) |
| 293 | { | 293 | { |
| 294 | Lisp_Object this_val; | 294 | Lisp_Object this_val; |
| @@ -308,13 +308,13 @@ char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to) | |||
| 308 | break; | 308 | break; |
| 309 | } | 309 | } |
| 310 | } | 310 | } |
| 311 | while (*to >= (index + 1) * chartab_chars[0]) | 311 | while (*to >= (chartab_idx + 1) * chartab_chars[0]) |
| 312 | { | 312 | { |
| 313 | Lisp_Object this_val; | 313 | Lisp_Object this_val; |
| 314 | 314 | ||
| 315 | index++; | 315 | chartab_idx++; |
| 316 | c = index * chartab_chars[0]; | 316 | c = chartab_idx * chartab_chars[0]; |
| 317 | this_val = tbl->contents[index]; | 317 | this_val = tbl->contents[chartab_idx]; |
| 318 | if (SUB_CHAR_TABLE_P (this_val)) | 318 | if (SUB_CHAR_TABLE_P (this_val)) |
| 319 | this_val = sub_char_table_ref_and_range (this_val, c, from, to, | 319 | this_val = sub_char_table_ref_and_range (this_val, c, from, to, |
| 320 | tbl->defalt); | 320 | tbl->defalt); |
| @@ -331,20 +331,6 @@ char_table_ref_and_range (Lisp_Object table, int c, int *from, int *to) | |||
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | 333 | ||
| 334 | #define ASET_RANGE(ARRAY, FROM, TO, LIMIT, VAL) \ | ||
| 335 | do { \ | ||
| 336 | int limit = (TO) < (LIMIT) ? (TO) : (LIMIT); \ | ||
| 337 | for (; (FROM) < limit; (FROM)++) (ARRAY)->contents[(FROM)] = (VAL); \ | ||
| 338 | } while (0) | ||
| 339 | |||
| 340 | #define GET_SUB_CHAR_TABLE(TABLE, SUBTABLE, IDX, DEPTH, MIN_CHAR) \ | ||
| 341 | do { \ | ||
| 342 | (SUBTABLE) = (TABLE)->contents[(IDX)]; \ | ||
| 343 | if (!SUB_CHAR_TABLE_P (SUBTABLE)) \ | ||
| 344 | (SUBTABLE) = make_sub_char_table ((DEPTH), (MIN_CHAR), (SUBTABLE)); \ | ||
| 345 | } while (0) | ||
| 346 | |||
| 347 | |||
| 348 | static void | 334 | static void |
| 349 | sub_char_table_set (Lisp_Object table, int c, Lisp_Object val) | 335 | sub_char_table_set (Lisp_Object table, int c, Lisp_Object val) |
| 350 | { | 336 | { |
| @@ -406,7 +392,8 @@ sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, | |||
| 406 | *table = val; | 392 | *table = val; |
| 407 | else | 393 | else |
| 408 | { | 394 | { |
| 409 | int i, j; | 395 | int i; |
| 396 | unsigned j; | ||
| 410 | 397 | ||
| 411 | depth++; | 398 | depth++; |
| 412 | if (! SUB_CHAR_TABLE_P (*table)) | 399 | if (! SUB_CHAR_TABLE_P (*table)) |
| @@ -418,7 +405,7 @@ sub_char_table_set_range (Lisp_Object *table, int depth, int min_char, int from, | |||
| 418 | i = CHARTAB_IDX (from, depth, min_char); | 405 | i = CHARTAB_IDX (from, depth, min_char); |
| 419 | j = CHARTAB_IDX (to, depth, min_char); | 406 | j = CHARTAB_IDX (to, depth, min_char); |
| 420 | min_char += chartab_chars[depth] * i; | 407 | min_char += chartab_chars[depth] * i; |
| 421 | for (; i <= j; i++, min_char += chartab_chars[depth]) | 408 | for (j++; i < j; i++, min_char += chartab_chars[depth]) |
| 422 | sub_char_table_set_range (XSUB_CHAR_TABLE (*table)->contents + i, | 409 | sub_char_table_set_range (XSUB_CHAR_TABLE (*table)->contents + i, |
| 423 | depth, min_char, from, to, val); | 410 | depth, min_char, from, to, val); |
| 424 | } | 411 | } |
| @@ -430,16 +417,16 @@ char_table_set_range (Lisp_Object table, int from, int to, Lisp_Object val) | |||
| 430 | { | 417 | { |
| 431 | struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); | 418 | struct Lisp_Char_Table *tbl = XCHAR_TABLE (table); |
| 432 | Lisp_Object *contents = tbl->contents; | 419 | Lisp_Object *contents = tbl->contents; |
| 433 | int i, min_char; | 420 | int i; |
| 434 | 421 | ||
| 435 | if (from == to) | 422 | if (from == to) |
| 436 | char_table_set (table, from, val); | 423 | char_table_set (table, from, val); |
| 437 | else | 424 | else |
| 438 | { | 425 | { |
| 439 | for (i = CHARTAB_IDX (from, 0, 0), min_char = i * chartab_chars[0]; | 426 | unsigned lim = to / chartab_chars[0] + 1; |
| 440 | min_char <= to; | 427 | for (i = CHARTAB_IDX (from, 0, 0); i < lim; i++) |
| 441 | i++, min_char += chartab_chars[0]) | 428 | sub_char_table_set_range (contents + i, 0, i * chartab_chars[0], |
| 442 | sub_char_table_set_range (contents + i, 0, min_char, from, to, val); | 429 | from, to, val); |
| 443 | if (ASCII_CHAR_P (from)) | 430 | if (ASCII_CHAR_P (from)) |
| 444 | tbl->ascii = char_table_ascii (table); | 431 | tbl->ascii = char_table_ascii (table); |
| 445 | } | 432 | } |
| @@ -537,15 +524,15 @@ a cons of character codes (for characters in the range), or a character code. * | |||
| 537 | 524 | ||
| 538 | if (EQ (range, Qnil)) | 525 | if (EQ (range, Qnil)) |
| 539 | val = XCHAR_TABLE (char_table)->defalt; | 526 | val = XCHAR_TABLE (char_table)->defalt; |
| 540 | else if (INTEGERP (range)) | 527 | else if (CHARACTERP (range)) |
| 541 | val = CHAR_TABLE_REF (char_table, XINT (range)); | 528 | val = CHAR_TABLE_REF (char_table, XFASTINT (range)); |
| 542 | else if (CONSP (range)) | 529 | else if (CONSP (range)) |
| 543 | { | 530 | { |
| 544 | int from, to; | 531 | int from, to; |
| 545 | 532 | ||
| 546 | CHECK_CHARACTER_CAR (range); | 533 | CHECK_CHARACTER_CAR (range); |
| 547 | CHECK_CHARACTER_CDR (range); | 534 | CHECK_CHARACTER_CDR (range); |
| 548 | val = char_table_ref_and_range (char_table, XINT (XCAR (range)), | 535 | val = char_table_ref_and_range (char_table, XFASTINT (XCAR (range)), |
| 549 | &from, &to); | 536 | &from, &to); |
| 550 | /* Not yet implemented. */ | 537 | /* Not yet implemented. */ |
| 551 | } | 538 | } |
| @@ -951,7 +938,7 @@ map_sub_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object), | |||
| 951 | map_charset_chars. */ | 938 | map_charset_chars. */ |
| 952 | 939 | ||
| 953 | void | 940 | void |
| 954 | map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object), | 941 | map_char_table_for_charset (void (*c_function) (Lisp_Object, Lisp_Object), |
| 955 | Lisp_Object function, Lisp_Object table, Lisp_Object arg, | 942 | Lisp_Object function, Lisp_Object table, Lisp_Object arg, |
| 956 | struct charset *charset, | 943 | struct charset *charset, |
| 957 | unsigned from, unsigned to) | 944 | unsigned from, unsigned to) |
| @@ -1012,4 +999,3 @@ syms_of_chartab (void) | |||
| 1012 | defsubr (&Soptimize_char_table); | 999 | defsubr (&Soptimize_char_table); |
| 1013 | defsubr (&Smap_char_table); | 1000 | defsubr (&Smap_char_table); |
| 1014 | } | 1001 | } |
| 1015 | |||