aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/strings.texi
diff options
context:
space:
mode:
authorPaul Eggert2017-10-04 14:29:58 -0700
committerPaul Eggert2017-10-04 14:45:08 -0700
commit3db388b0bf83d3138562f09ce25fab8ba89bcc81 (patch)
treeff86fa2e529cdd9187a12e88d193b4416d60c26e /doc/lispref/strings.texi
parent4e0b67ed27114fa2cbebca32567089fd8fa78425 (diff)
downloademacs-3db388b0bf83d3138562f09ce25fab8ba89bcc81.tar.gz
emacs-3db388b0bf83d3138562f09ce25fab8ba89bcc81.zip
Speed up (format "%s" STRING) and the like
Although the Lisp manual said that ‘format’ returns a newly-allocated string, this was not true for a few cases like (format "%s" ""), and fixing the documentation to allow reuse of arguments lets us improve performance in common cases like (format "foo") and (format "%s" "foo") (Bug#28625). * doc/lispref/strings.texi (Formatting Strings): * etc/NEWS: Say that the result of ‘format’ might not be newly allocated. * src/callint.c (Fcall_interactively): * src/dbusbind.c (XD_OBJECT_TO_STRING): * src/editfns.c (Fmessage, Fmessage_box): * src/xdisp.c (vadd_to_log, Ftrace_to_stderr): Just use Fformat or Fformat_message, as that’s simpler and no longer makes unnecessary copies. * src/editfns.c (styled_format): Remove last argument, as it is no longer needed: all callers now want it to behave as if it were true. All remaining callers changed. Make this function static again. Simplify the function now that we no longer need to worry about whether the optimization is allowed.
Diffstat (limited to 'doc/lispref/strings.texi')
-rw-r--r--doc/lispref/strings.texi10
1 files changed, 7 insertions, 3 deletions
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi
index dd004927caf..09c3bdf71f6 100644
--- a/doc/lispref/strings.texi
+++ b/doc/lispref/strings.texi
@@ -812,15 +812,19 @@ formatting feature described here; they differ from @code{format-message} only
812in how they use the result of formatting. 812in how they use the result of formatting.
813 813
814@defun format string &rest objects 814@defun format string &rest objects
815This function returns a new string that is made by copying 815This function returns a string equal to @var{string}, replacing any format
816@var{string} and then replacing any format specification 816specifications with encodings of the corresponding @var{objects}. The
817in the copy with encodings of the corresponding @var{objects}. The
818arguments @var{objects} are the computed values to be formatted. 817arguments @var{objects} are the computed values to be formatted.
819 818
820The characters in @var{string}, other than the format specifications, 819The characters in @var{string}, other than the format specifications,
821are copied directly into the output, including their text properties, 820are copied directly into the output, including their text properties,
822if any. Any text properties of the format specifications are copied 821if any. Any text properties of the format specifications are copied
823to the produced string representations of the argument @var{objects}. 822to the produced string representations of the argument @var{objects}.
823
824The output string need not be newly-allocated. For example, if
825@code{x} is the string @code{"foo"}, the expressions @code{(eq x
826(format x))} and @code{(eq x (format "%s" x))} might both yield
827@code{t}.
824@end defun 828@end defun
825 829
826@defun format-message string &rest objects 830@defun format-message string &rest objects