]> git.eshelyaron.com Git - emacs.git/commitdiff
Speed up find_field when called from outside a field
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 20 Dec 2021 09:26:25 +0000 (10:26 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 21 Dec 2021 04:23:11 +0000 (05:23 +0100)
* 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

index 5c9c34dc3522dd6be8fc80f49d37f578a7534289..355a7a3e299833edc338d2e87f4e91be13c17939 100644 (file)
@@ -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),