From: Lars Ingebrigtsen Date: Mon, 20 Dec 2021 09:26:25 +0000 (+0100) Subject: Speed up find_field when called from outside a field X-Git-Tag: emacs-29.0.90~3538 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4d8af56c76ee20bc8e1ebdeef5c4100cea005974;p=emacs.git Speed up find_field when called from outside a field * src/editfns.c (find_field): Speed up the field functions when called from outside a field (bug#52593). (In some cursory tests, this makes the called-from-outside-a-field case about 3x faster.) --- diff --git a/src/editfns.c b/src/editfns.c index 5c9c34dc352..355a7a3e299 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -437,6 +437,27 @@ find_field (Lisp_Object pos, Lisp_Object merge_at_boundary, after_field = get_char_property_and_overlay (pos, Qfield, Qnil, NULL); + + /* We're not in a field, so find the prev/next area with a field + property. */ + if (NILP (after_field)) + { + if (beg) + { + Lisp_Object p = Fprevious_single_char_property_change (pos, Qfield, + Qnil, + beg_limit); + *beg = NILP (p) ? BEGV : XFIXNAT (p); + } + if (end) + { + Lisp_Object p = Fnext_single_char_property_change (pos, Qfield, Qnil, + end_limit); + *end = NILP (p) ? ZV : XFIXNAT (p); + } + return; + } + before_field = (XFIXNAT (pos) > BEGV ? get_char_property_and_overlay (make_fixnum (XFIXNUM (pos) - 1),