diff options
| author | Paul Eggert | 2013-11-04 23:11:24 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-11-04 23:11:24 -0800 |
| commit | df5b49306e8e82e2f18ed3243700c11ca7835750 (patch) | |
| tree | d98fffc7d11d4565b6132e83f54ca3f3c547b1d4 /src/category.c | |
| parent | 693698093480628b7438ca0fd1614b00acfd1137 (diff) | |
| download | emacs-df5b49306e8e82e2f18ed3243700c11ca7835750.tar.gz emacs-df5b49306e8e82e2f18ed3243700c11ca7835750.zip | |
Simplify and port recent bool vector changes.
* configure.ac (BITSIZEOF_SIZE_T, SIZEOF_SIZE_T):
New symbols to configure.
* src/alloc.c (ROUNDUP): Move here from lisp.h, since it's now used
only in this file. Use a more-efficient implementation if the
second argument is a power of 2.
(ALIGN): Rewrite in terms of ROUNDUP. Make it a function.
Remove no-longer-necessary compile-time checks.
(bool_vector_exact_payload_bytes): New function.
(bool_vector_payload_bytes): Remove 2nd arg; callers that need
exact payload changed to call the new function. Do not assume
that the arg or result fits in ptrdiff_t.
(bool_vector_fill): New function.
(Fmake_bool_vector): Use it. Don't assume bit counts fit
in ptrdiff_t.
(vroundup_ct): Don't assume arg fits in size_t.
* src/category.c (SET_CATEGORY_SET): Remove. All callers now just
invoke set_category_set.
(set_category_set): 2nd arg is now EMACS_INT and 3rd is now bool.
All callers changed. Use bool_vector_set.
* src/category.h (XCATEGORY_SET): Remove; no longer needed.
(CATEGORY_MEMBER): Now a function. Rewrite in terms of
bool_vector_bitref.
* src/data.c (Faref): Use bool_vector_ref.
(Faset): Use bool_vector_set.
(bits_word_to_host_endian): Don't assume you can shift by CHAR_BIT.
(Fbool_vector_not, Fbool_vector_count_matches)
(Fbool_vector_count_matches_at): Don't assume CHAR_BIT == 8.
* src/fns.c (concat): Use bool_vector_ref.
(Ffillarray): Use bool_vector_fill.
(mapcar1): Use bool_vector_ref.
(sxhash_bool_vector): Hash words, not bytes.
* src/lisp.h (BOOL_VECTOR_BITS_PER_CHAR): Now a macro as well as
a constant, since it's now used in #if.
(bits_word, BITS_WORD_MAX, BITS_PER_BITS_WORD): Fall back on
unsigned char on unusual architectures, so that we no longer
assume that the number of bits per bits_word is a power of two or
is a multiple of 8 or of CHAR_BIT.
(Qt): Add forward decl.
(struct Lisp_Bool_Vector): Don't assume EMACS_INT is aligned
at least as strictly as bits_word.
(bool_vector_data, bool_vector_uchar_data): New accessors.
All data structure accesses changed to use them.
(bool_vector_words, bool_vector_bitref, bool_vector_ref)
(bool_vector_set): New functions.
(bool_vector_fill): New decl.
(ROUNDUP): Move to alloc.c as described above.
Diffstat (limited to 'src/category.c')
| -rw-r--r-- | src/category.c | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/src/category.c b/src/category.c index da5e81e4709..80d8b1ca1a2 100644 --- a/src/category.c +++ b/src/category.c | |||
| @@ -55,17 +55,9 @@ bset_category_table (struct buffer *b, Lisp_Object val) | |||
| 55 | static int category_table_version; | 55 | static int category_table_version; |
| 56 | 56 | ||
| 57 | static Lisp_Object Qcategory_table, Qcategoryp, Qcategorysetp, Qcategory_table_p; | 57 | static Lisp_Object Qcategory_table, Qcategoryp, Qcategorysetp, Qcategory_table_p; |
| 58 | |||
| 59 | /* Make CATEGORY_SET includes (if VAL is t) or excludes (if VAL is | ||
| 60 | nil) CATEGORY. */ | ||
| 61 | #define SET_CATEGORY_SET(category_set, category, val) \ | ||
| 62 | set_category_set (category_set, category, val) | ||
| 63 | static void set_category_set (Lisp_Object, Lisp_Object, Lisp_Object); | ||
| 64 | 58 | ||
| 65 | /* Category set staff. */ | 59 | /* Category set staff. */ |
| 66 | 60 | ||
| 67 | static Lisp_Object hash_get_category_set (Lisp_Object, Lisp_Object); | ||
| 68 | |||
| 69 | static Lisp_Object | 61 | static Lisp_Object |
| 70 | hash_get_category_set (Lisp_Object table, Lisp_Object category_set) | 62 | hash_get_category_set (Lisp_Object table, Lisp_Object category_set) |
| 71 | { | 63 | { |
| @@ -88,6 +80,13 @@ hash_get_category_set (Lisp_Object table, Lisp_Object category_set) | |||
| 88 | return category_set; | 80 | return category_set; |
| 89 | } | 81 | } |
| 90 | 82 | ||
| 83 | /* Make CATEGORY_SET include (if VAL) or exclude (if !VAL) CATEGORY. */ | ||
| 84 | |||
| 85 | static void | ||
| 86 | set_category_set (Lisp_Object category_set, EMACS_INT category, bool val) | ||
| 87 | { | ||
| 88 | bool_vector_set (category_set, category, val); | ||
| 89 | } | ||
| 91 | 90 | ||
| 92 | DEFUN ("make-category-set", Fmake_category_set, Smake_category_set, 1, 1, 0, | 91 | DEFUN ("make-category-set", Fmake_category_set, Smake_category_set, 1, 1, 0, |
| 93 | doc: /* Return a newly created category-set which contains CATEGORIES. | 92 | doc: /* Return a newly created category-set which contains CATEGORIES. |
| @@ -108,11 +107,11 @@ those categories. */) | |||
| 108 | len = SCHARS (categories); | 107 | len = SCHARS (categories); |
| 109 | while (--len >= 0) | 108 | while (--len >= 0) |
| 110 | { | 109 | { |
| 111 | Lisp_Object category; | 110 | unsigned char cat = SREF (categories, len); |
| 111 | Lisp_Object category = make_number (cat); | ||
| 112 | 112 | ||
| 113 | XSETFASTINT (category, SREF (categories, len)); | ||
| 114 | CHECK_CATEGORY (category); | 113 | CHECK_CATEGORY (category); |
| 115 | SET_CATEGORY_SET (val, category, Qt); | 114 | set_category_set (val, cat, 1); |
| 116 | } | 115 | } |
| 117 | return val; | 116 | return val; |
| 118 | } | 117 | } |
| @@ -334,20 +333,6 @@ The return value is a string containing those same categories. */) | |||
| 334 | return build_string (str); | 333 | return build_string (str); |
| 335 | } | 334 | } |
| 336 | 335 | ||
| 337 | static void | ||
| 338 | set_category_set (Lisp_Object category_set, Lisp_Object category, Lisp_Object val) | ||
| 339 | { | ||
| 340 | do { | ||
| 341 | int idx = XINT (category) / 8; | ||
| 342 | unsigned char bits = 1 << (XINT (category) % 8); | ||
| 343 | |||
| 344 | if (NILP (val)) | ||
| 345 | XCATEGORY_SET (category_set)->data[idx] &= ~bits; | ||
| 346 | else | ||
| 347 | XCATEGORY_SET (category_set)->data[idx] |= bits; | ||
| 348 | } while (0); | ||
| 349 | } | ||
| 350 | |||
| 351 | DEFUN ("modify-category-entry", Fmodify_category_entry, | 336 | DEFUN ("modify-category-entry", Fmodify_category_entry, |
| 352 | Smodify_category_entry, 2, 4, 0, | 337 | Smodify_category_entry, 2, 4, 0, |
| 353 | doc: /* Modify the category set of CHARACTER by adding CATEGORY to it. | 338 | doc: /* Modify the category set of CHARACTER by adding CATEGORY to it. |
| @@ -359,7 +344,7 @@ If optional fourth argument RESET is non-nil, | |||
| 359 | then delete CATEGORY from the category set instead of adding it. */) | 344 | then delete CATEGORY from the category set instead of adding it. */) |
| 360 | (Lisp_Object character, Lisp_Object category, Lisp_Object table, Lisp_Object reset) | 345 | (Lisp_Object character, Lisp_Object category, Lisp_Object table, Lisp_Object reset) |
| 361 | { | 346 | { |
| 362 | Lisp_Object set_value; /* Actual value to be set in category sets. */ | 347 | bool set_value; /* Actual value to be set in category sets. */ |
| 363 | Lisp_Object category_set; | 348 | Lisp_Object category_set; |
| 364 | int start, end; | 349 | int start, end; |
| 365 | int from, to; | 350 | int from, to; |
| @@ -384,7 +369,7 @@ then delete CATEGORY from the category set instead of adding it. */) | |||
| 384 | if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) | 369 | if (NILP (CATEGORY_DOCSTRING (table, XFASTINT (category)))) |
| 385 | error ("Undefined category: %c", (int) XFASTINT (category)); | 370 | error ("Undefined category: %c", (int) XFASTINT (category)); |
| 386 | 371 | ||
| 387 | set_value = NILP (reset) ? Qt : Qnil; | 372 | set_value = NILP (reset); |
| 388 | 373 | ||
| 389 | while (start <= end) | 374 | while (start <= end) |
| 390 | { | 375 | { |
| @@ -393,7 +378,7 @@ then delete CATEGORY from the category set instead of adding it. */) | |||
| 393 | if (CATEGORY_MEMBER (XFASTINT (category), category_set) != NILP (reset)) | 378 | if (CATEGORY_MEMBER (XFASTINT (category), category_set) != NILP (reset)) |
| 394 | { | 379 | { |
| 395 | category_set = Fcopy_sequence (category_set); | 380 | category_set = Fcopy_sequence (category_set); |
| 396 | SET_CATEGORY_SET (category_set, category, set_value); | 381 | set_category_set (category_set, XFASTINT (category), set_value); |
| 397 | category_set = hash_get_category_set (table, category_set); | 382 | category_set = hash_get_category_set (table, category_set); |
| 398 | char_table_set_range (table, start, to, category_set); | 383 | char_table_set_range (table, start, to, category_set); |
| 399 | } | 384 | } |