aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorPaul Eggert2018-12-09 00:18:36 -0800
committerPaul Eggert2018-12-09 00:23:55 -0800
commitd79bb75683ceb4eee2f753eb38fa8db99aff4568 (patch)
treeb0b20c25387c2eb11b2c79e87898bec2c39b14ea /src/coding.c
parentc2fdd50c3cb0b03d2414370c58c1aa2a6ec3311d (diff)
downloademacs-d79bb75683ceb4eee2f753eb38fa8db99aff4568.tar.gz
emacs-d79bb75683ceb4eee2f753eb38fa8db99aff4568.zip
Add make_vector and make_nil_vector
This makes the callers a bit easier to read, and doubtless improves efficiency very slightly. It also simplifies possible future changes to allow bignum indexes to buffers. * src/alloc.c (allocate_vectorlike): Prefer ptrdiff_t to size_t when either will do. (make_vector): New function. (Fmake_vector): Use it. * src/buffer.c (syms_of_buffer): * src/bytecode.c (syms_of_bytecode): * src/category.c (Fmake_category_table, init_category_once): * src/ccl.c (syms_of_ccl): * src/character.c (syms_of_character): * src/charset.c (Fdefine_charset_internal) (Ffind_charset_region, Ffind_charset_string): * src/chartab.c (copy_char_table): * src/coding.c (Fdefine_coding_system_internal, syms_of_coding): * src/composite.c (get_composition_id, Fcomposition_get_gstring): * src/composite.h (LGLYPH_NEW): * src/fns.c (concat, Flocale_info, make_hash_table): * src/font.c (font_otf_ValueRecord, font_otf_anchor) (build_style_table, syms_of_font): * src/fontset.c (RFONT_DEF_NEW, fontset_find_font) (dump_fontset, syms_of_fontset): * src/image.c (xpm_make_color_table_v): * src/keyboard.c (modify_event_symbol, menu_bar_items) (parse_menu_item, parse_tool_bar_item, init_tool_bar_items) (syms_of_keyboard): * src/keymap.c (Fdefine_key, describe_map, describe_vector): * src/lread.c (read_vector): * src/macfont.m (macfont_shape): * src/menu.c (init_menu_items): * src/nsfns.m (ns_make_monitor_attribute_list): * src/process.c (conv_sockaddr_to_lisp, network_interface_info): * src/profiler.c (make_log): * src/window.c (Fcurrent_window_configuration): * src/xdisp.c (with_echo_area_buffer_unwind_data) (format_mode_line_unwind_data): * src/xfaces.c (Finternal_make_lisp_face) (Fface_attributes_as_vector): * src/xfns.c (x_make_monitor_attribute_list) (Fx_display_monitor_attributes_list): * src/xfont.c (syms_of_xfont): * src/xselect.c (x_handle_dnd_message): * src/xwidget.c (save_script_callback): Prefer make_nil_vector (N) to Fmake_vector (make_fixnum (N), Qnil). * src/callint.c (Fcall_interactively): * src/charset.c (load_charset_map): * src/chartab.c (Fmake_char_table, uniprop_encode_value_numeric): * src/composite.c (get_composition_id) * src/dispnew.c (Fframe_or_buffer_changed_p) (syms_of_display): * src/fns.c (make_hash_table, maybe_resize_hash_table): * src/font.c (font_style_to_value): * src/fontset.c (FONTSET_ADD, fontset_add): * src/json.c (json_to_lisp): * src/keymap.c (syms_of_keymap): * src/lread.c (init_obarray): * src/profiler.c (make_log, Fprofiler_cpu_log): * src/term.c (term_get_fkeys_1): Prefer make_vector (N, V) to Fmake_vector (make_fixnum (N), V). * src/font.c (build_style_table): * src/macfont.m (macfont_shape): * src/process.c (conv_sockaddr_to_lisp, network_interface_info): Prefer make_uninit_vector if the vector will be initialized soon. * src/lisp.h (make_nil_vector): New function.
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c65
1 files changed, 27 insertions, 38 deletions
diff --git a/src/coding.c b/src/coding.c
index 0f715a2d7cd..398691fc864 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -10062,36 +10062,28 @@ DEFUN ("define-coding-system-internal", Fdefine_coding_system_internal,
10062usage: (define-coding-system-internal ...) */) 10062usage: (define-coding-system-internal ...) */)
10063 (ptrdiff_t nargs, Lisp_Object *args) 10063 (ptrdiff_t nargs, Lisp_Object *args)
10064{ 10064{
10065 Lisp_Object name;
10066 Lisp_Object spec_vec; /* [ ATTRS ALIASE EOL_TYPE ] */
10067 Lisp_Object attrs; /* Vector of attributes. */
10068 Lisp_Object eol_type;
10069 Lisp_Object aliases;
10070 Lisp_Object coding_type, charset_list, safe_charsets;
10071 enum coding_category category; 10065 enum coding_category category;
10072 Lisp_Object tail, val;
10073 int max_charset_id = 0; 10066 int max_charset_id = 0;
10074 int i;
10075 10067
10076 if (nargs < coding_arg_max) 10068 if (nargs < coding_arg_max)
10077 goto short_args; 10069 goto short_args;
10078 10070
10079 attrs = Fmake_vector (make_fixnum (coding_attr_last_index), Qnil); 10071 Lisp_Object attrs = make_nil_vector (coding_attr_last_index);
10080 10072
10081 name = args[coding_arg_name]; 10073 Lisp_Object name = args[coding_arg_name];
10082 CHECK_SYMBOL (name); 10074 CHECK_SYMBOL (name);
10083 ASET (attrs, coding_attr_base_name, name); 10075 ASET (attrs, coding_attr_base_name, name);
10084 10076
10085 val = args[coding_arg_mnemonic]; 10077 Lisp_Object val = args[coding_arg_mnemonic];
10086 if (! STRINGP (val)) 10078 if (! STRINGP (val))
10087 CHECK_CHARACTER (val); 10079 CHECK_CHARACTER (val);
10088 ASET (attrs, coding_attr_mnemonic, val); 10080 ASET (attrs, coding_attr_mnemonic, val);
10089 10081
10090 coding_type = args[coding_arg_coding_type]; 10082 Lisp_Object coding_type = args[coding_arg_coding_type];
10091 CHECK_SYMBOL (coding_type); 10083 CHECK_SYMBOL (coding_type);
10092 ASET (attrs, coding_attr_type, coding_type); 10084 ASET (attrs, coding_attr_type, coding_type);
10093 10085
10094 charset_list = args[coding_arg_charset_list]; 10086 Lisp_Object charset_list = args[coding_arg_charset_list];
10095 if (SYMBOLP (charset_list)) 10087 if (SYMBOLP (charset_list))
10096 { 10088 {
10097 if (EQ (charset_list, Qiso_2022)) 10089 if (EQ (charset_list, Qiso_2022))
@@ -10106,7 +10098,7 @@ usage: (define-coding-system-internal ...) */)
10106 error ("Invalid charset-list"); 10098 error ("Invalid charset-list");
10107 charset_list = Vemacs_mule_charset_list; 10099 charset_list = Vemacs_mule_charset_list;
10108 } 10100 }
10109 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) 10101 for (Lisp_Object tail = charset_list; CONSP (tail); tail = XCDR (tail))
10110 { 10102 {
10111 if (! RANGED_FIXNUMP (0, XCAR (tail), INT_MAX - 1)) 10103 if (! RANGED_FIXNUMP (0, XCAR (tail), INT_MAX - 1))
10112 error ("Invalid charset-list"); 10104 error ("Invalid charset-list");
@@ -10117,7 +10109,7 @@ usage: (define-coding-system-internal ...) */)
10117 else 10109 else
10118 { 10110 {
10119 charset_list = Fcopy_sequence (charset_list); 10111 charset_list = Fcopy_sequence (charset_list);
10120 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) 10112 for (Lisp_Object tail = charset_list; CONSP (tail); tail = XCDR (tail))
10121 { 10113 {
10122 struct charset *charset; 10114 struct charset *charset;
10123 10115
@@ -10138,9 +10130,9 @@ usage: (define-coding-system-internal ...) */)
10138 } 10130 }
10139 ASET (attrs, coding_attr_charset_list, charset_list); 10131 ASET (attrs, coding_attr_charset_list, charset_list);
10140 10132
10141 safe_charsets = make_uninit_string (max_charset_id + 1); 10133 Lisp_Object safe_charsets = make_uninit_string (max_charset_id + 1);
10142 memset (SDATA (safe_charsets), 255, max_charset_id + 1); 10134 memset (SDATA (safe_charsets), 255, max_charset_id + 1);
10143 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) 10135 for (Lisp_Object tail = charset_list; CONSP (tail); tail = XCDR (tail))
10144 SSET (safe_charsets, XFIXNAT (XCAR (tail)), 0); 10136 SSET (safe_charsets, XFIXNAT (XCAR (tail)), 0);
10145 ASET (attrs, coding_attr_safe_charsets, safe_charsets); 10137 ASET (attrs, coding_attr_safe_charsets, safe_charsets);
10146 10138
@@ -10194,9 +10186,9 @@ usage: (define-coding-system-internal ...) */)
10194 If Nth element is a list of charset IDs, N is the first byte 10186 If Nth element is a list of charset IDs, N is the first byte
10195 of one of them. The list is sorted by dimensions of the 10187 of one of them. The list is sorted by dimensions of the
10196 charsets. A charset of smaller dimension comes first. */ 10188 charsets. A charset of smaller dimension comes first. */
10197 val = Fmake_vector (make_fixnum (256), Qnil); 10189 val = make_nil_vector (256);
10198 10190
10199 for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) 10191 for (Lisp_Object tail = charset_list; CONSP (tail); tail = XCDR (tail))
10200 { 10192 {
10201 struct charset *charset = CHARSET_FROM_ID (XFIXNAT (XCAR (tail))); 10193 struct charset *charset = CHARSET_FROM_ID (XFIXNAT (XCAR (tail)));
10202 int dim = CHARSET_DIMENSION (charset); 10194 int dim = CHARSET_DIMENSION (charset);
@@ -10205,7 +10197,7 @@ usage: (define-coding-system-internal ...) */)
10205 if (CHARSET_ASCII_COMPATIBLE_P (charset)) 10197 if (CHARSET_ASCII_COMPATIBLE_P (charset))
10206 ASET (attrs, coding_attr_ascii_compat, Qt); 10198 ASET (attrs, coding_attr_ascii_compat, Qt);
10207 10199
10208 for (i = charset->code_space[idx]; 10200 for (int i = charset->code_space[idx];
10209 i <= charset->code_space[idx + 1]; i++) 10201 i <= charset->code_space[idx + 1]; i++)
10210 { 10202 {
10211 Lisp_Object tmp, tmp2; 10203 Lisp_Object tmp, tmp2;
@@ -10265,7 +10257,7 @@ usage: (define-coding-system-internal ...) */)
10265 10257
10266 val = args[coding_arg_ccl_valids]; 10258 val = args[coding_arg_ccl_valids];
10267 valids = Fmake_string (make_fixnum (256), make_fixnum (0), Qnil); 10259 valids = Fmake_string (make_fixnum (256), make_fixnum (0), Qnil);
10268 for (tail = val; CONSP (tail); tail = XCDR (tail)) 10260 for (Lisp_Object tail = val; CONSP (tail); tail = XCDR (tail))
10269 { 10261 {
10270 int from, to; 10262 int from, to;
10271 10263
@@ -10290,7 +10282,7 @@ usage: (define-coding-system-internal ...) */)
10290 XCAR (val), make_fixnum (255)); 10282 XCAR (val), make_fixnum (255));
10291 to = XFIXNUM (XCDR (val)); 10283 to = XFIXNUM (XCDR (val));
10292 } 10284 }
10293 for (i = from; i <= to; i++) 10285 for (int i = from; i <= to; i++)
10294 SSET (valids, i, 1); 10286 SSET (valids, i, 1);
10295 } 10287 }
10296 ASET (attrs, coding_attr_ccl_valids, valids); 10288 ASET (attrs, coding_attr_ccl_valids, valids);
@@ -10344,7 +10336,7 @@ usage: (define-coding-system-internal ...) */)
10344 10336
10345 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]); 10337 initial = Fcopy_sequence (args[coding_arg_iso2022_initial]);
10346 CHECK_VECTOR (initial); 10338 CHECK_VECTOR (initial);
10347 for (i = 0; i < 4; i++) 10339 for (int i = 0; i < 4; i++)
10348 { 10340 {
10349 val = AREF (initial, i); 10341 val = AREF (initial, i);
10350 if (! NILP (val)) 10342 if (! NILP (val))
@@ -10366,7 +10358,7 @@ usage: (define-coding-system-internal ...) */)
10366 CHECK_FIXNUM_CDR (reg_usage); 10358 CHECK_FIXNUM_CDR (reg_usage);
10367 10359
10368 request = Fcopy_sequence (args[coding_arg_iso2022_request]); 10360 request = Fcopy_sequence (args[coding_arg_iso2022_request]);
10369 for (tail = request; CONSP (tail); tail = XCDR (tail)) 10361 for (Lisp_Object tail = request; CONSP (tail); tail = XCDR (tail))
10370 { 10362 {
10371 int id; 10363 int id;
10372 Lisp_Object tmp1; 10364 Lisp_Object tmp1;
@@ -10377,13 +10369,14 @@ usage: (define-coding-system-internal ...) */)
10377 CHECK_CHARSET_GET_ID (tmp1, id); 10369 CHECK_CHARSET_GET_ID (tmp1, id);
10378 CHECK_FIXNAT_CDR (val); 10370 CHECK_FIXNAT_CDR (val);
10379 if (XFIXNUM (XCDR (val)) >= 4) 10371 if (XFIXNUM (XCDR (val)) >= 4)
10380 error ("Invalid graphic register number: %"pI"d", XFIXNUM (XCDR (val))); 10372 error ("Invalid graphic register number: %"pI"d",
10373 XFIXNUM (XCDR (val)));
10381 XSETCAR (val, make_fixnum (id)); 10374 XSETCAR (val, make_fixnum (id));
10382 } 10375 }
10383 10376
10384 flags = args[coding_arg_iso2022_flags]; 10377 flags = args[coding_arg_iso2022_flags];
10385 CHECK_FIXNAT (flags); 10378 CHECK_FIXNAT (flags);
10386 i = XFIXNUM (flags) & INT_MAX; 10379 int i = XFIXNUM (flags) & INT_MAX;
10387 if (EQ (args[coding_arg_charset_list], Qiso_2022)) 10380 if (EQ (args[coding_arg_charset_list], Qiso_2022))
10388 i |= CODING_ISO_FLAG_FULL_SUPPORT; 10381 i |= CODING_ISO_FLAG_FULL_SUPPORT;
10389 flags = make_fixnum (i); 10382 flags = make_fixnum (i);
@@ -10542,19 +10535,19 @@ usage: (define-coding-system-internal ...) */)
10542 Fcons (CODING_ATTR_ASCII_COMPAT (attrs), 10535 Fcons (CODING_ATTR_ASCII_COMPAT (attrs),
10543 CODING_ATTR_PLIST (attrs)))); 10536 CODING_ATTR_PLIST (attrs))));
10544 10537
10545 eol_type = args[coding_arg_eol_type]; 10538 Lisp_Object eol_type = args[coding_arg_eol_type];
10546 if (! NILP (eol_type) 10539 if (! NILP (eol_type)
10547 && ! EQ (eol_type, Qunix) 10540 && ! EQ (eol_type, Qunix)
10548 && ! EQ (eol_type, Qdos) 10541 && ! EQ (eol_type, Qdos)
10549 && ! EQ (eol_type, Qmac)) 10542 && ! EQ (eol_type, Qmac))
10550 error ("Invalid eol-type"); 10543 error ("Invalid eol-type");
10551 10544
10552 aliases = list1 (name); 10545 Lisp_Object aliases = list1 (name);
10553 10546
10554 if (NILP (eol_type)) 10547 if (NILP (eol_type))
10555 { 10548 {
10556 eol_type = make_subsidiaries (name); 10549 eol_type = make_subsidiaries (name);
10557 for (i = 0; i < 3; i++) 10550 for (int i = 0; i < 3; i++)
10558 { 10551 {
10559 Lisp_Object this_spec, this_name, this_aliases, this_eol_type; 10552 Lisp_Object this_spec, this_name, this_aliases, this_eol_type;
10560 10553
@@ -10575,7 +10568,7 @@ usage: (define-coding-system-internal ...) */)
10575 } 10568 }
10576 } 10569 }
10577 10570
10578 spec_vec = make_uninit_vector (3); 10571 Lisp_Object spec_vec = make_uninit_vector (3);
10579 ASET (spec_vec, 0, attrs); 10572 ASET (spec_vec, 0, attrs);
10580 ASET (spec_vec, 1, aliases); 10573 ASET (spec_vec, 1, aliases);
10581 ASET (spec_vec, 2, eol_type); 10574 ASET (spec_vec, 2, eol_type);
@@ -10587,12 +10580,9 @@ usage: (define-coding-system-internal ...) */)
10587 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil), 10580 Vcoding_system_alist = Fcons (Fcons (Fsymbol_name (name), Qnil),
10588 Vcoding_system_alist); 10581 Vcoding_system_alist);
10589 10582
10590 { 10583 int id = coding_categories[category].id;
10591 int id = coding_categories[category].id; 10584 if (id < 0 || EQ (name, CODING_ID_NAME (id)))
10592
10593 if (id < 0 || EQ (name, CODING_ID_NAME (id)))
10594 setup_coding_system (name, &coding_categories[category]); 10585 setup_coding_system (name, &coding_categories[category]);
10595 }
10596 10586
10597 return Qnil; 10587 return Qnil;
10598 10588
@@ -10915,8 +10905,7 @@ syms_of_coding (void)
10915 DEFSYM (QCpre_write_conversion, ":pre-write-conversion"); 10905 DEFSYM (QCpre_write_conversion, ":pre-write-conversion");
10916 DEFSYM (QCascii_compatible_p, ":ascii-compatible-p"); 10906 DEFSYM (QCascii_compatible_p, ":ascii-compatible-p");
10917 10907
10918 Vcoding_category_table 10908 Vcoding_category_table = make_nil_vector (coding_category_max);
10919 = Fmake_vector (make_fixnum (coding_category_max), Qnil);
10920 staticpro (&Vcoding_category_table); 10909 staticpro (&Vcoding_category_table);
10921 /* Followings are target of code detection. */ 10910 /* Followings are target of code detection. */
10922 ASET (Vcoding_category_table, coding_category_iso_7, 10911 ASET (Vcoding_category_table, coding_category_iso_7,
@@ -11220,7 +11209,7 @@ a coding system of ISO 2022 variant which has a flag
11220`accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file 11209`accept-latin-extra-code' t (e.g. iso-latin-1) on reading a file
11221or reading output of a subprocess. 11210or reading output of a subprocess.
11222Only 128th through 159th elements have a meaning. */); 11211Only 128th through 159th elements have a meaning. */);
11223 Vlatin_extra_code_table = Fmake_vector (make_fixnum (256), Qnil); 11212 Vlatin_extra_code_table = make_nil_vector (256);
11224 11213
11225 DEFVAR_LISP ("select-safe-coding-system-function", 11214 DEFVAR_LISP ("select-safe-coding-system-function",
11226 Vselect_safe_coding_system_function, 11215 Vselect_safe_coding_system_function,