[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5d15818b94c 1/2: Minor optimisation of string-trim-left and strin
From: |
Mattias Engdegård |
Subject: |
master 5d15818b94c 1/2: Minor optimisation of string-trim-left and string-trim-right |
Date: |
Sat, 20 May 2023 12:59:01 -0400 (EDT) |
branch: master
commit 5d15818b94c1f6fd46f30154240942b3991492a4
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Minor optimisation of string-trim-left and string-trim-right
* lisp/subr.el (string-trim-left, string-trim-right):
Use a constant string when no REGEXP argument is given.
---
lisp/subr.el | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 5a641965659..8759c095f1a 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -6940,7 +6940,10 @@ returned list are in the same order as in TREE.
"Trim STRING of leading string matching REGEXP.
REGEXP defaults to \"[ \\t\\n\\r]+\"."
- (if (string-match (concat "\\`\\(?:" (or regexp "[ \t\n\r]+") "\\)") string)
+ (if (string-match (if regexp
+ (concat "\\`\\(?:" regexp "\\)")
+ "\\`[ \t\n\r]+")
+ string)
(substring string (match-end 0))
string))
@@ -6949,7 +6952,9 @@ REGEXP defaults to \"[ \\t\\n\\r]+\"."
REGEXP defaults to \"[ \\t\\n\\r]+\"."
(declare (side-effect-free t))
- (let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
+ (let ((i (string-match-p (if regexp
+ (concat "\\(?:" regexp "\\)\\'")
+ "[ \t\n\r]+\\'")
string)))
(if i (substring string 0 i) string)))