From 4d8af56c76ee20bc8e1ebdeef5c4100cea005974 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 20 Dec 2021 10:26:25 +0100 Subject: 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.) --- src/editfns.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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), -- cgit v1.2.3