aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2022-07-10 09:37:40 +0300
committerEli Zaretskii2022-07-10 09:37:40 +0300
commit8dc4c19be8b1540834336a41cd85eb3d78f2076d (patch)
treefe766dbab8566d0f1b45e125c795857844df7ab9
parent143548fdd6c732ce6bf628d239137297bc373616 (diff)
downloademacs-8dc4c19be8b1540834336a41cd85eb3d78f2076d.tar.gz
emacs-8dc4c19be8b1540834336a41cd85eb3d78f2076d.zip
Speed up 'find_automatic_composition'
* src/composite.c (find_automatic_composition): Limit search backward in buffers to the first newline. Fix commentary.
-rw-r--r--src/composite.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/composite.c b/src/composite.c
index 552214ae848..5ad846e40b0 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1513,10 +1513,11 @@ struct position_record
1513/* Similar to find_composition, but find an automatic composition instead. 1513/* Similar to find_composition, but find an automatic composition instead.
1514 1514
1515 This function looks for automatic composition at or near position 1515 This function looks for automatic composition at or near position
1516 POS of OBJECT (a buffer or a string). OBJECT defaults to the 1516 POS of STRING object, either a buffer or a Lisp string. If STRING
1517 current buffer. It must be assured that POS is not within a static 1517 is nil, it defaults to the current buffer. It must be assured that
1518 composition. Also, the current buffer must be displayed in some 1518 POS is not within a static composition. Also, the current buffer
1519 window, otherwise the function will return FALSE. 1519 must be displayed in some window, otherwise the function will
1520 return FALSE.
1520 1521
1521 If LIMIT is negative, and there's no composition that includes POS 1522 If LIMIT is negative, and there's no composition that includes POS
1522 (i.e. starts at or before POS and ends at or after POS), return 1523 (i.e. starts at or before POS and ends at or after POS), return
@@ -1525,8 +1526,8 @@ struct position_record
1525 MAX_AUTO_COMPOSITION_LOOKBACK, the maximum number of look-back for 1526 MAX_AUTO_COMPOSITION_LOOKBACK, the maximum number of look-back for
1526 automatic compositions (3) -- this is a limitation imposed by 1527 automatic compositions (3) -- this is a limitation imposed by
1527 composition rules in composition-function-table, which see. If 1528 composition rules in composition-function-table, which see. If
1528 BACKLIM is negative, it stands for the beginning of OBJECT: BEGV 1529 BACKLIM is negative, it stands for the beginning of STRING object:
1529 for a buffer or position zero for a string. 1530 BEGV for a buffer or position zero for a string.
1530 1531
1531 If LIMIT is positive, search for a composition forward (LIMIT > 1532 If LIMIT is positive, search for a composition forward (LIMIT >
1532 POS) or backward (LIMIT < POS). In this case, LIMIT bounds the 1533 POS) or backward (LIMIT < POS). In this case, LIMIT bounds the
@@ -1535,18 +1536,21 @@ struct position_record
1535 function can find a composition that starts after POS. 1536 function can find a composition that starts after POS.
1536 1537
1537 BACKLIM limits how far back is the function allowed to look in 1538 BACKLIM limits how far back is the function allowed to look in
1538 OBJECT while trying to find a position where it is safe to start 1539 STRING object while trying to find a position where it is safe to
1539 searching forward for compositions. Such a safe place is generally 1540 start searching forward for compositions. Such a safe place is
1540 the position after a character that can never be composed. 1541 generally the position after a character that can never be
1542 composed.
1541 1543
1542 If BACKLIM is negative, that means the first character position of 1544 If BACKLIM is negative, that means the first character position of
1543 OBJECT; this is useful when calling the function for the first time 1545 STRING object; this is useful when calling the function for the
1544 for a given buffer or string, since it is possible that a 1546 first time for a given buffer or string, since it is possible that
1545 composition begins before POS. However, if POS is very far from 1547 a composition begins before POS. However, if POS is very far from
1546 the beginning of OBJECT, a negative value of BACKLIM could make the 1548 the beginning of STRING object, a negative value of BACKLIM could
1547 function slow. Also, in this case the function may return START 1549 make the function slow. For that reason, when STRING is a buffer
1548 and END that do not include POS, something that is not necessarily 1550 or nil, we restrict the search back to the first newline before
1549 wanted, and needs to be explicitly checked by the caller. 1551 POS. Also, in this case the function may return START and END that
1552 do not include POS, something that is not necessarily wanted, and
1553 needs to be explicitly checked by the caller.
1550 1554
1551 When calling the function in a loop for the same buffer/string, the 1555 When calling the function in a loop for the same buffer/string, the
1552 caller should generally set BACKLIM equal to POS, to avoid costly 1556 caller should generally set BACKLIM equal to POS, to avoid costly
@@ -1585,7 +1589,15 @@ find_automatic_composition (ptrdiff_t pos, ptrdiff_t limit, ptrdiff_t backlim,
1585 cur.pos = pos; 1589 cur.pos = pos;
1586 if (NILP (string)) 1590 if (NILP (string))
1587 { 1591 {
1588 head = backlim < 0 ? BEGV : backlim, tail = ZV, stop = GPT; 1592 if (backlim < 0)
1593 {
1594 /* This assumes a newline can never be composed. */
1595 head = find_newline (pos, -1, 0, -1, -1, NULL, NULL, false) + 1;
1596 }
1597 else
1598 head = backlim;
1599 tail = ZV;
1600 stop = GPT;
1589 cur.pos_byte = CHAR_TO_BYTE (cur.pos); 1601 cur.pos_byte = CHAR_TO_BYTE (cur.pos);
1590 cur.p = BYTE_POS_ADDR (cur.pos_byte); 1602 cur.p = BYTE_POS_ADDR (cur.pos_byte);
1591 } 1603 }