diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2019-01-09 09:52:38 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2019-01-09 09:59:10 -0800 |
commit | a84650334e30b2451bf4a8957bf2d57ade296d4e (patch) | |
tree | b5642bb98eb89733def116fb6d864f74855023e2 | |
parent | f9d0fd6c1953138f7473a22917a1508740b2ce40 (diff) | |
download | emacs-a84650334e30b2451bf4a8957bf2d57ade296d4e.tar.gz |
Use shortcuts for Flength
When calculating the length of a Lisp object whose type is
known, use a specialized length operation on it to save a bit
of runtime overhead.
* src/callint.c (Fcall_interactively):
* src/minibuf.c (read_minibuf_unwind):
Use ASIZE rather than Flength on values that must be vectors.
* src/charset.c (Fsort_charsets):
* src/coding.c (detect_coding_sjis):
(Fdefine_coding_system_internal):
* src/data.c (wrong_choice):
* src/eval.c (Flet, eval_sub, Fapply, apply_lambda):
* src/fns.c (sort_list):
* src/font.c (font_vconcat_entity_vectors)
(font_find_for_lface):
* src/frame.c (Fmodify_frame_parameters):
* src/fringe.c (get_logical_fringe_bitmap):
* src/ftfont.c (ftfont_get_open_type_spec):
* src/gtkutil.c (xg_print_frames_dialog):
* src/lread.c (read1, read_vector):
* src/keymap.c (Fkey_description):
* src/kqueue.c (Fkqueue_add_watch):
* src/macfont.m (macfont_get_open_type_spec):
* src/menu.c (parse_single_submenu, x_popup_menu_1):
* src/minibuf.c (Finternal_complete_buffer):
* src/nsfont.m (ns_findfonts, nsfont_list_family):
* src/process.c (Fmake_process):
* src/search.c (Fset_match_data):
* src/xfaces.c (Fx_family_fonts):
Use list_length rather than Flength on values that must be lists.
* src/fns.c (list_length): New function.
(Flength): Use it.
* src/nsfont.m (ns_findfonts):
Use !NILP (x) rather than XFIXNUM (Flength (x)) != 0.
* src/xdisp.c (store_mode_line_string):
Use SCHARS rather than Flength on values that must be strings.
-rw-r--r-- | src/callint.c | 2 | ||||
-rw-r--r-- | src/charset.c | 3 | ||||
-rw-r--r-- | src/coding.c | 14 | ||||
-rw-r--r-- | src/data.c | 8 | ||||
-rw-r--r-- | src/eval.c | 48 | ||||
-rw-r--r-- | src/fns.c | 61 | ||||
-rw-r--r-- | src/font.c | 7 | ||||
-rw-r--r-- | src/frame.c | 2 | ||||
-rw-r--r-- | src/fringe.c | 6 | ||||
-rw-r--r-- | src/ftfont.c | 8 | ||||
-rw-r--r-- | src/gtkutil.c | 2 | ||||
-rw-r--r-- | src/keymap.c | 2 | ||||
-rw-r--r-- | src/kqueue.c | 5 | ||||
-rw-r--r-- | src/lisp.h | 1 | ||||
-rw-r--r-- | src/lread.c | 5 | ||||
-rw-r--r-- | src/macfont.m | 8 | ||||
-rw-r--r-- | src/menu.c | 12 | ||||
-rw-r--r-- | src/minibuf.c | 5 | ||||
-rw-r--r-- | src/nsfont.m | 10 | ||||
-rw-r--r-- | src/process.c | 4 | ||||
-rw-r--r-- | src/search.c | 4 | ||||
-rw-r--r-- | src/xdisp.c | 2 | ||||
-rw-r--r-- | src/xfaces.c | 3 |
23 files changed, 98 insertions, 124 deletions
diff --git a/src/callint.c b/src/callint.c index dac905e16f4..0911c49ae59 100644 --- a/src/callint.c +++ b/src/callint.c @@ -572,7 +572,7 @@ invoke it. If KEYS is omitted or nil, the return value of /* If the key sequence ends with a down-event, discard the following up-event. */ Lisp_Object teml - = Faref (args[i], make_fixnum (XFIXNUM (Flength (args[i])) - 1)); + = Faref (args[i], make_fixnum (ASIZE (args[i]) - 1)); if (CONSP (teml)) teml = XCAR (teml); if (SYMBOLP (teml)) diff --git a/src/charset.c b/src/charset.c index 427349b298a..724b35536ed 100644 --- a/src/charset.c +++ b/src/charset.c @@ -2242,8 +2242,7 @@ Return the sorted list. CHARSETS is modified by side effects. See also `charset-priority-list' and `set-charset-priority'. */) (Lisp_Object charsets) { - Lisp_Object len = Flength (charsets); - ptrdiff_t n = XFIXNAT (len), i, j; + ptrdiff_t n = list_length (charsets), i, j; int done; Lisp_Object tail, elt, attrs; struct charset_sort_data *sort_data; diff --git a/src/coding.c b/src/coding.c index 0297c8a100d..1c1462198ca 100644 --- a/src/coding.c +++ b/src/coding.c @@ -4591,8 +4591,7 @@ detect_coding_sjis (struct coding_system *coding, int max_first_byte_of_2_byte_code; CODING_GET_INFO (coding, attrs, charset_list); - max_first_byte_of_2_byte_code - = (XFIXNUM (Flength (charset_list)) > 3 ? 0xFC : 0xEF); + max_first_byte_of_2_byte_code = list_length (charset_list) <= 3 ? 0xEF : 0xFC; detect_info->checked |= CATEGORY_MASK_SJIS; /* A coding system of this category is always ASCII compatible. */ @@ -10387,14 +10386,11 @@ usage: (define-coding-system-internal ...) */) } else if (EQ (coding_type, Qshift_jis)) { - - struct charset *charset; - - if (XFIXNUM (Flength (charset_list)) != 3 - && XFIXNUM (Flength (charset_list)) != 4) + ptrdiff_t charset_list_len = list_length (charset_list); + if (charset_list_len != 3 && charset_list_len != 4) error ("There should be three or four charsets"); - charset = CHARSET_FROM_ID (XFIXNUM (XCAR (charset_list))); + struct charset *charset = CHARSET_FROM_ID (XFIXNUM (XCAR (charset_list))); if (CHARSET_DIMENSION (charset) != 1) error ("Dimension of charset %s is not one", SDATA (SYMBOL_NAME (CHARSET_NAME (charset)))); @@ -10429,7 +10425,7 @@ usage: (define-coding-system-internal ...) */) { struct charset *charset; - if (XFIXNUM (Flength (charset_list)) != 2) + if (list_length (charset_list) != 2) error ("There should be just two charsets"); charset = CHARSET_FROM_ID (XFIXNUM (XCAR (charset_list))); diff --git a/src/data.c b/src/data.c index 1c124740815..a9908a34f4f 100644 --- a/src/data.c +++ b/src/data.c @@ -980,14 +980,12 @@ chain of aliases, signal a `cyclic-variable-indirection' error. */) swap_in_symval_forwarding for that. */ Lisp_Object -do_symval_forwarding (register union Lisp_Fwd *valcontents) +do_symval_forwarding (union Lisp_Fwd *valcontents) { - register Lisp_Object val; switch (XFWDTYPE (valcontents)) { case Lisp_Fwd_Int: - XSETINT (val, *XFIXNUMFWD (valcontents)->intvar); - return val; + return make_fixnum (*XFIXNUMFWD (valcontents)->intvar); case Lisp_Fwd_Bool: return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); @@ -1023,7 +1021,7 @@ do_symval_forwarding (register union Lisp_Fwd *valcontents) void wrong_choice (Lisp_Object choice, Lisp_Object wrong) { - ptrdiff_t i = 0, len = XFIXNUM (Flength (choice)); + ptrdiff_t i = 0, len = list_length (choice); Lisp_Object obj, *args; AUTO_STRING (one_of, "One of "); AUTO_STRING (comma, ", "); diff --git a/src/eval.c b/src/eval.c index c64a40b955d..28478956e35 100644 --- a/src/eval.c +++ b/src/eval.c @@ -951,16 +951,15 @@ usage: (let VARLIST BODY...) */) (Lisp_Object args) { Lisp_Object *temps, tem, lexenv; - Lisp_Object elt, varlist; + Lisp_Object elt; ptrdiff_t count = SPECPDL_INDEX (); ptrdiff_t argnum; USE_SAFE_ALLOCA; - varlist = XCAR (args); - CHECK_LIST (varlist); + Lisp_Object varlist = XCAR (args); /* Make space to hold the values to give the bound variables. */ - EMACS_INT varlist_len = XFIXNAT (Flength (varlist)); + EMACS_INT varlist_len = list_length (varlist); SAFE_ALLOCA_LISP (temps, varlist_len); ptrdiff_t nvars = varlist_len; @@ -2263,14 +2262,15 @@ eval_sub (Lisp_Object form) if (SUBRP (fun)) { Lisp_Object args_left = original_args; - Lisp_Object numargs = Flength (args_left); + ptrdiff_t numargs = list_length (args_left); check_cons_list (); - if (XFIXNUM (numargs) < XSUBR (fun)->min_args + if (numargs < XSUBR (fun)->min_args || (XSUBR (fun)->max_args >= 0 - && XSUBR (fun)->max_args < XFIXNUM (numargs))) - xsignal2 (Qwrong_number_of_arguments, original_fun, numargs); + && XSUBR (fun)->max_args < numargs)) + xsignal2 (Qwrong_number_of_arguments, original_fun, + make_fixnum (numargs)); else if (XSUBR (fun)->max_args == UNEVALLED) val = (XSUBR (fun)->function.aUNEVALLED) (args_left); @@ -2281,9 +2281,9 @@ eval_sub (Lisp_Object form) ptrdiff_t argnum = 0; USE_SAFE_ALLOCA; - SAFE_ALLOCA_LISP (vals, XFIXNUM (numargs)); + SAFE_ALLOCA_LISP (vals, numargs); - while (CONSP (args_left) && argnum < XFIXNUM (numargs)) + while (CONSP (args_left) && argnum < numargs) { Lisp_Object arg = XCAR (args_left); args_left = XCDR (args_left); @@ -2313,7 +2313,7 @@ eval_sub (Lisp_Object form) args_left = Fcdr (args_left); } - set_backtrace_args (specpdl + count, argvals, XFIXNUM (numargs)); + set_backtrace_args (specpdl + count, argvals, numargs); switch (i) { @@ -2417,16 +2417,13 @@ Thus, (apply \\='+ 1 2 \\='(3 4)) returns 10. usage: (apply FUNCTION &rest ARGUMENTS) */) (ptrdiff_t nargs, Lisp_Object *args) { - ptrdiff_t i, numargs, funcall_nargs; - register Lisp_Object *funcall_args = NULL; - register Lisp_Object spread_arg = args[nargs - 1]; + ptrdiff_t i, funcall_nargs; + Lisp_Object *funcall_args = NULL; + Lisp_Object spread_arg = args[nargs - 1]; Lisp_Object fun = args[0]; - Lisp_Object retval; USE_SAFE_ALLOCA; - CHECK_LIST (spread_arg); - - numargs = XFIXNUM (Flength (spread_arg)); + ptrdiff_t numargs = list_length (spread_arg); if (numargs == 0) return Ffuncall (nargs - 1, args); @@ -2476,7 +2473,7 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) spread_arg = XCDR (spread_arg); } - retval = Ffuncall (funcall_nargs, funcall_args); + Lisp_Object retval = Ffuncall (funcall_nargs, funcall_args); SAFE_FREE (); return retval; @@ -2974,25 +2971,22 @@ funcall_subr (struct Lisp_Subr *subr, ptrdiff_t numargs, Lisp_Object *args) static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args, ptrdiff_t count) { - Lisp_Object args_left; - ptrdiff_t i; - EMACS_INT numargs; Lisp_Object *arg_vector; Lisp_Object tem; USE_SAFE_ALLOCA; - numargs = XFIXNAT (Flength (args)); + ptrdiff_t numargs = list_length (args); SAFE_ALLOCA_LISP (arg_vector, numargs); - args_left = args; + Lisp_Object args_left = args; - for (i = 0; i < numargs; ) + for (ptrdiff_t i = 0; i < numargs; i++) { tem = Fcar (args_left), args_left = Fcdr (args_left); tem = eval_sub (tem); - arg_vector[i++] = tem; + arg_vector[i] = tem; } - set_backtrace_args (specpdl + count, arg_vector, i); + set_backtrace_args (specpdl + count, arg_vector, numargs); tem = funcall_lambda (fun, numargs, arg_vector); check_cons_list (); diff --git a/src/fns.c b/src/fns.c index 7791310a313..0fad6f47447 100644 --- a/src/fns.c +++ b/src/fns.c @@ -91,42 +91,50 @@ See Info node `(elisp)Random Numbers' for more details. */) /* Random data-structure functions. */ +/* Return the length of LIST. Signal an error if LIST is not a proper + list or if the length does not fit into a fixnum or into ptrdiff_t. */ + +ptrdiff_t +list_length (Lisp_Object list) +{ + intptr_t i = 0; + FOR_EACH_TAIL (list) + i++; + CHECK_LIST_END (list, list); + if (i <= min (PTRDIFF_MAX, MOST_POSITIVE_FIXNUM)) + return i; + overflow_error (); +} + + DEFUN ("length", Flength, Slength, 1, 1, 0, doc: /* Return the length of vector, list or string SEQUENCE. A byte-code function object is also allowed. If the string contains multibyte characters, this is not necessarily the number of bytes in the string; it is the number of characters. To get the number of bytes, use `string-bytes'. */) - (register Lisp_Object sequence) + (Lisp_Object sequence) { - register Lisp_Object val; + EMACS_INT val; if (STRINGP (sequence)) - XSETFASTINT (val, SCHARS (sequence)); + val = SCHARS (sequence); else if (VECTORP (sequence)) - XSETFASTINT (val, ASIZE (sequence)); + val = ASIZE (sequence); else if (CHAR_TABLE_P (sequence)) - XSETFASTINT (val, MAX_CHAR); + val = MAX_CHAR; else if (BOOL_VECTOR_P (sequence)) - XSETFASTINT (val, bool_vector_size (sequence)); + val = bool_vector_size (sequence); else if (COMPILEDP (sequence) || RECORDP (sequence)) - XSETFASTINT (val, PVSIZE (sequence)); + val = PVSIZE (sequence); else if (CONSP (sequence)) - { - intptr_t i = 0; - FOR_EACH_TAIL (sequence) - i++; - CHECK_LIST_END (sequence, sequence); - if (MOST_POSITIVE_FIXNUM < i) - overflow_error (); - val = make_fixnum (i); - } + val = list_length (sequence); else if (NILP (sequence)) - XSETFASTINT (val, 0); + val = 0; else wrong_type_argument (Qsequencep, sequence); - return val; + return make_fixnum (val); } DEFUN ("safe-length", Fsafe_length, Ssafe_length, 1, 1, 0, @@ -1957,24 +1965,15 @@ See also the function `nreverse', which is used more often. */) static Lisp_Object sort_list (Lisp_Object list, Lisp_Object predicate) { - Lisp_Object front, back; - Lisp_Object len, tem; - EMACS_INT length; - - front = list; - len = Flength (list); - length = XFIXNUM (len); + ptrdiff_t length = list_length (list); if (length < 2) return list; - XSETINT (len, (length / 2) - 1); - tem = Fnthcdr (len, list); - back = Fcdr (tem); + Lisp_Object tem = Fnthcdr (make_fixnum (length / 2 - 1), list); + Lisp_Object back = Fcdr (tem); Fsetcdr (tem, Qnil); - front = Fsort (front, predicate); - back = Fsort (back, predicate); - return merge (front, back, predicate); + return merge (Fsort (list, predicate), Fsort (back, predicate), predicate); } /* Using PRED to compare, return whether A and B are in order. diff --git a/src/font.c b/src/font.c index cf68160e59c..3fc77a1d76a 100644 --- a/src/font.c +++ b/src/font.c @@ -2174,13 +2174,12 @@ font_score (Lisp_Object entity, Lisp_Object *spec_prop) static Lisp_Object font_vconcat_entity_vectors (Lisp_Object list) { - EMACS_INT nargs = XFIXNAT (Flength (list)); + ptrdiff_t nargs = list_length (list); Lisp_Object *args; USE_SAFE_ALLOCA; SAFE_ALLOCA_LISP (args, nargs); - ptrdiff_t i; - for (i = 0; i < nargs; i++, list = XCDR (list)) + for (ptrdiff_t i = 0; i < nargs; i++, list = XCDR (list)) args[i] = XCAR (list); Lisp_Object result = Fvconcat (nargs, args); SAFE_FREE (); @@ -3241,7 +3240,7 @@ font_find_for_lface (struct frame *f, Lisp_Object *attrs, Lisp_Object spec, int if (! NILP (alters)) { - EMACS_INT alterslen = XFIXNAT (Flength (alters)); + EMACS_INT alterslen = list_length (alters); SAFE_ALLOCA_LISP (family, alterslen + 2); for (i = 0; CONSP (alters); i++, alters = XCDR (alters)) family[i] = XCAR (alters); diff --git a/src/frame.c b/src/frame.c index 6efc2a61095..ca6704a44c0 100644 --- a/src/frame.c +++ b/src/frame.c @@ -3190,7 +3190,7 @@ list, but are otherwise ignored. */) #endif { - EMACS_INT length = XFIXNAT (Flength (alist)); + EMACS_INT length = list_length (alist); ptrdiff_t i; Lisp_Object *parms; Lisp_Object *values; diff --git a/src/fringe.c b/src/fringe.c index a7e8dad482e..74f41f00873 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -719,7 +719,7 @@ static int get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p) { Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm; - EMACS_INT ln1 = 0, ln2 = 0; + ptrdiff_t ln1 = 0, ln2 = 0; int ix1 = right_p; int ix2 = ix1 + (partial_p ? 2 : 0); @@ -743,7 +743,7 @@ get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, in return NO_FRINGE_BITMAP; if (CONSP (bm1)) { - ln1 = XFIXNUM (Flength (bm1)); + ln1 = list_length (bm1); if (partial_p) { if (ln1 > ix2) @@ -778,7 +778,7 @@ get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, in { if (CONSP (bm2)) { - ln2 = XFIXNUM (Flength (bm2)); + ln2 = list_length (bm2); if (partial_p) { if (ln2 > ix2) diff --git a/src/ftfont.c b/src/ftfont.c index 6899a5763a8..f5a225be056 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -594,16 +594,14 @@ ftfont_get_open_type_spec (Lisp_Object otf_spec) spec->nfeatures[0] = spec->nfeatures[1] = 0; for (i = 0; i < 2 && ! NILP (otf_spec); i++, otf_spec = XCDR (otf_spec)) { - Lisp_Object len; - val = XCAR (otf_spec); if (NILP (val)) continue; - len = Flength (val); + ptrdiff_t len = list_length (val); spec->features[i] = - (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XFIXNUM (len) + (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < len ? 0 - : malloc (XFIXNUM (len) * sizeof *spec->features[i])); + : malloc (len * sizeof *spec->features[i])); if (! spec->features[i]) { if (i > 0 && spec->features[0]) diff --git a/src/gtkutil.c b/src/gtkutil.c index 2eac28798bc..92199bb0af2 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -4299,7 +4299,7 @@ xg_print_frames_dialog (Lisp_Object frames) gtk_print_operation_set_print_settings (print, print_settings); if (page_setup != NULL) gtk_print_operation_set_default_page_setup (print, page_setup); - gtk_print_operation_set_n_pages (print, XFIXNUM (Flength (frames))); + gtk_print_operation_set_n_pages (print, list_length (frames)); g_signal_connect (print, "draw-page", G_CALLBACK (draw_page), &frames); res = gtk_print_operation_run (print, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); diff --git a/src/keymap.c b/src/keymap.c index 21d37328ade..dda552ba471 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -2042,7 +2042,7 @@ For an approximate inverse of this, see `kbd'. */) else if (VECTORP (list)) size = ASIZE (list); else if (CONSP (list)) - size = XFIXNUM (Flength (list)); + size = list_length (list); else wrong_type_argument (Qarrayp, list); diff --git a/src/kqueue.c b/src/kqueue.c index 655bfd58d3b..43e75cac310 100644 --- a/src/kqueue.c +++ b/src/kqueue.c @@ -395,11 +395,12 @@ only when the upper directory of the renamed file is watched. */) maxfd = 256; /* We assume 50 file descriptors are sufficient for the rest of Emacs. */ - if ((maxfd - 50) < XFIXNUM (Flength (watch_list))) + ptrdiff_t watch_list_len = list_length (watch_list); + if (maxfd - 50 < watch_list_len) xsignal2 (Qfile_notify_error, build_string ("File watching not possible, no file descriptor left"), - Flength (watch_list)); + make_fixnum (watch_list_len)); if (kqueuefd < 0) { diff --git a/src/lisp.h b/src/lisp.h index dce61c165cf..faf5a4ad407 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3413,6 +3413,7 @@ extern void syms_of_syntax (void); /* Defined in fns.c. */ enum { NEXT_ALMOST_PRIME_LIMIT = 11 }; +extern ptrdiff_t list_length (Lisp_Object); extern EMACS_INT next_almost_prime (EMACS_INT) ATTRIBUTE_CONST; extern Lisp_Object larger_vector (Lisp_Object, ptrdiff_t, ptrdiff_t); extern void sweep_weak_hash_tables (void); diff --git a/src/lread.c b/src/lread.c index 02f7caadeda..5a595f2119b 100644 --- a/src/lread.c +++ b/src/lread.c @@ -2879,7 +2879,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list) /* Sub char-table can't be read as a regular vector because of a two C integer fields. */ Lisp_Object tbl, tmp = read_list (1, readcharfun); - ptrdiff_t size = XFIXNUM (Flength (tmp)); + ptrdiff_t size = list_length (tmp); int i, depth, min_char; struct Lisp_Cons *cell; @@ -3846,8 +3846,7 @@ static Lisp_Object read_vector (Lisp_Object readcharfun, bool bytecodeflag) { Lisp_Object tem = read_list (1, readcharfun); - Lisp_Object len = Flength (tem); - ptrdiff_t size = XFIXNAT (len); + ptrdiff_t size = list_length (tem); if (bytecodeflag && size <= COMPILED_STACK_DEPTH) error ("Invalid byte code"); Lisp_Object vector = make_nil_vector (size); diff --git a/src/macfont.m b/src/macfont.m index 0e90eb44eeb..09c4ff31c88 100644 --- a/src/macfont.m +++ b/src/macfont.m @@ -1791,16 +1791,14 @@ macfont_get_open_type_spec (Lisp_Object otf_spec) spec->nfeatures[0] = spec->nfeatures[1] = 0; for (i = 0; i < 2 && ! NILP (otf_spec); i++, otf_spec = XCDR (otf_spec)) { - Lisp_Object len; - val = XCAR (otf_spec); if (NILP (val)) continue; - len = Flength (val); + ptrdiff_t len = list_length (val); spec->features[i] = - (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < XFIXNUM (len) + (min (PTRDIFF_MAX, SIZE_MAX) / sizeof (int) < len ? 0 - : malloc (XFIXNUM (len) * sizeof *spec->features[i])); + : malloc (len * sizeof *spec->features[i])); if (! spec->features[i]) { if (i > 0 && spec->features[0]) diff --git a/src/menu.c b/src/menu.c index c35d711b314..c0e5bd9caf6 100644 --- a/src/menu.c +++ b/src/menu.c @@ -524,19 +524,15 @@ bool parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, Lisp_Object maps) { - Lisp_Object length; - EMACS_INT len; Lisp_Object *mapvec; - ptrdiff_t i; bool top_level_items = 0; USE_SAFE_ALLOCA; - length = Flength (maps); - len = XFIXNUM (length); + ptrdiff_t len = list_length (maps); /* Convert the list MAPS into a vector MAPVEC. */ SAFE_ALLOCA_LISP (mapvec, len); - for (i = 0; i < len; i++) + for (ptrdiff_t i = 0; i < len; i++) { mapvec[i] = Fcar (maps); maps = Fcdr (maps); @@ -544,7 +540,7 @@ parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name, /* Loop over the given keymaps, making a pane for each map. But don't make a pane that is empty--ignore that map instead. */ - for (i = 0; i < len; i++) + for (ptrdiff_t i = 0; i < len; i++) { if (!KEYMAPP (mapvec[i])) { @@ -1309,7 +1305,7 @@ x_popup_menu_1 (Lisp_Object position, Lisp_Object menu) else if (CONSP (menu) && KEYMAPP (XCAR (menu))) { /* We were given a list of keymaps. */ - EMACS_INT nmaps = XFIXNAT (Flength (menu)); + ptrdiff_t nmaps = list_length (menu); Lisp_Object *maps; ptrdiff_t i; USE_SAFE_ALLOCA; diff --git a/src/minibuf.c b/src/minibuf.c index 8017da194b0..c1fbfb40857 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -780,8 +780,7 @@ read_minibuf_unwind (void) /* Restore prompt, etc, from outer minibuffer level. */ Lisp_Object key_vec = Fcar (minibuf_save_list); - eassert (VECTORP (key_vec)); - this_command_key_count = XFIXNAT (Flength (key_vec)); + this_command_key_count = ASIZE (key_vec); this_command_keys = key_vec; minibuf_save_list = Fcdr (minibuf_save_list); minibuf_prompt = Fcar (minibuf_save_list); @@ -1783,7 +1782,7 @@ If FLAG is nil, invoke `try-completion'; if it is t, invoke while (CONSP (bufs) && SREF (XCAR (bufs), 0) == ' ') bufs = XCDR (bufs); if (NILP (bufs)) - return (EQ (Flength (res), Flength (Vbuffer_alist)) + return (list_length (res) == list_length (Vbuffer_alist) /* If all bufs are internal don't strip them out. */ ? res : bufs); res = bufs; diff --git a/src/nsfont.m b/src/nsfont.m index d4639dcca8c..b59f87f4682 100644 --- a/src/nsfont.m +++ b/src/nsfont.m @@ -576,7 +576,7 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch) /* Add synthItal member if needed. */ family = [fdesc objectForKey: NSFontFamilyAttribute]; - if (family != nil && !foundItal && XFIXNUM (Flength (list)) > 0) + if (family != nil && !foundItal && !NILP (list)) { NSFontDescriptor *s1 = [NSFontDescriptor new]; NSFontDescriptor *sDesc @@ -595,8 +595,8 @@ ns_findfonts (Lisp_Object font_spec, BOOL isMatch) return ns_fallback_entity (); if (NSFONT_TRACE) - fprintf (stderr, " Returning %"pI"d entities.\n", - XFIXNUM (Flength (list))); + fprintf (stderr, " Returning %"pD"d entities.\n", + list_length (list)); return list; } @@ -667,8 +667,8 @@ nsfont_list_family (struct frame *f) /* FIXME: escape the name? */ if (NSFONT_TRACE) - fprintf (stderr, "nsfont: list families returning %"pI"d entries\n", - XFIXNUM (Flength (list))); + fprintf (stderr, "nsfont: list families returning %"pD"d entries\n", + list_length (list)); unblock_input (); return list; diff --git a/src/process.c b/src/process.c index b2a7f38317a..edf633e512e 100644 --- a/src/process.c +++ b/src/process.c @@ -1804,7 +1804,7 @@ usage: (make-process &rest ARGS) */) val = Vcoding_system_for_read; if (NILP (val)) { - ptrdiff_t nargs2 = 3 + XFIXNUM (Flength (command)); + ptrdiff_t nargs2 = 3 + list_length (command); Lisp_Object tem2; SAFE_ALLOCA_LISP (args2, nargs2); ptrdiff_t i = 0; @@ -1834,7 +1834,7 @@ usage: (make-process &rest ARGS) */) { if (EQ (coding_systems, Qt)) { - ptrdiff_t nargs2 = 3 + XFIXNUM (Flength (command)); + ptrdiff_t nargs2 = 3 + list_length (command); Lisp_Object tem2; SAFE_ALLOCA_LISP (args2, nargs2); ptrdiff_t i = 0; diff --git a/src/search.c b/src/search.c index 702e6e3d8e7..f97dbe73341 100644 --- a/src/search.c +++ b/src/search.c @@ -2992,13 +2992,11 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) /* Allocate registers if they don't already exist. */ { - EMACS_INT length = XFIXNAT (Flength (list)) / 2; + ptrdiff_t length = list_length (list) / 2; if (length > search_regs.num_regs) { ptrdiff_t num_regs = search_regs.num_regs; - if (PTRDIFF_MAX < length) - memory_full (SIZE_MAX); search_regs.start = xpalloc (search_regs.start, &num_regs, length - num_regs, min (PTRDIFF_MAX, UINT_MAX), sizeof *search_regs.start); diff --git a/src/xdisp.c b/src/xdisp.c index 8b091c81bef..7725570ced3 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -24137,7 +24137,7 @@ store_mode_line_string (const char *string, Lisp_Object lisp_string, } else { - len = XFIXNAT (Flength (lisp_string)); + len = SCHARS (lisp_string); if (precision > 0 && len > precision) { len = precision; diff --git a/src/xfaces.c b/src/xfaces.c index 8fe99e7655d..cffa89e1f39 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -1424,7 +1424,6 @@ the face font sort order. */) Lisp_Object font_spec, list, *drivers, vec; struct frame *f = decode_live_frame (frame); ptrdiff_t i, nfonts; - EMACS_INT ndrivers; Lisp_Object result; USE_SAFE_ALLOCA; @@ -1457,7 +1456,7 @@ the face font sort order. */) font_props_for_sorting[i++] = FONT_ADSTYLE_INDEX; font_props_for_sorting[i++] = FONT_REGISTRY_INDEX; - ndrivers = XFIXNUM (Flength (list)); + ptrdiff_t ndrivers = list_length (list); SAFE_ALLOCA_LISP (drivers, ndrivers); for (i = 0; i < ndrivers; i++, list = XCDR (list)) drivers[i] = XCAR (list); |