GNU bug report logs -
#17814
24.3.91; better string manipulation in subr-x
Previous Next
Reported by: Shigeru Fukaya <shigeru.fukaya <at> gmail.com>
Date: Thu, 19 Jun 2014 19:12:01 UTC
Severity: wishlist
Found in version 24.3.91
Done: Noam Postavsky <npostavs <at> gmail.com>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 17814 <at> debbugs.gnu.org (full text, mbox):
>> I change the string-trim defined using defun from defsubst, as its
>> string literal is somewhat big (Actually I suspect most of other
>> functions would also be better if defined by defun).
>
>The use of `defsubst' is so that subr-x.el is not needed at run-time.
I see. I didn't know that, and it's very good.
Then, the code is
(defsubst string-trim (string)
"Remove leading and trailing whitespace from STRING."
(string-trim-right (string-trim-left string)))
or
(defsubst string-trim (string)
"Remove leading and trailing whitespace from STRING."
(string-match "\\`[\s\t\n\r]*\\(.*?\\)[\s\t\n\r]*\\'" string)
(if (or (< 0 (match-beginning 1)) (< (match-end 1) (match-end 0)))
(match-string 1 string)
string))
The latter is shorter in byte-compiled code, and call string-match
only once. Literal string is seemingly larger, but the overhead of
a string object will cover it, I think.
Regards,
Shigeru
This bug report was last modified 6 years and 253 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.