branch: externals/compat
commit a6a33ee2fae38857624fc43143a73bcddc9814b7
Author: Daniel Mendler <[email protected]>
Commit: Philip Kaludercic <[email protected]>

    string-width: Optimize computation of whole string width
    
    This optimization is important since the allocation is avoided in
    particular if no FROM and TO arguments are passed.
---
 compat-28.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/compat-28.el b/compat-28.el
index 862dd08b71..e94ac9750e 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -145,7 +145,12 @@ continuing as if the error did not occur."
 Optional arguments FROM and TO specify the substring of STRING to
 consider, and are interpreted as in `substring'."
   :prefix t
-  (string-width (substring string (or from 0) to)))
+  (let* ((len (length string))
+         (from (or from 0))
+         (to (or to len)))
+    (if (and (= from 0) (= to len))
+        (string-width string)
+      (string-width (substring string from to)))))
 
 ;;;; Defined in dired.c
 

Reply via email to