unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Improvements on constructing a string
@ 2022-11-10  5:38 Heime
  2022-11-10 14:09 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-11-10 14:28 ` Jean Louis
  0 siblings, 2 replies; 3+ messages in thread
From: Heime @ 2022-11-10  5:38 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor


Can one improve on this implementation that makes a string "st".

(defun chart-row (list)
  "Make row for Engine Parameters as string."
  
  (let ( (st "") )

    (while list
      (setq st (concat st (chart-cell (pop list)))))
    (setq st (concat st "\n"))

    st))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Improvements on constructing a string
  2022-11-10  5:38 Improvements on constructing a string Heime
@ 2022-11-10 14:09 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2022-11-10 14:28 ` Jean Louis
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2022-11-10 14:09 UTC (permalink / raw)
  To: help-gnu-emacs

>   (let ( (st "") )
>     (while list
>       (setq st (concat st (chart-cell (pop list)))))

This has O(N²) complexity.  Use `mapconcat` to avoid that.

>     (setq st (concat st "\n"))
>     st))

Aka

      (concat st "\n"))


-- Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Improvements on constructing a string
  2022-11-10  5:38 Improvements on constructing a string Heime
  2022-11-10 14:09 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2022-11-10 14:28 ` Jean Louis
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Louis @ 2022-11-10 14:28 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

* Heime <heimeborgia@protonmail.com> [2022-11-10 08:40]:
> 
> Can one improve on this implementation that makes a string "st".
> 
> (defun chart-row (list)
>   "Make row for Engine Parameters as string."
>   
>   (let ( (st "") )
> 
>     (while list
>       (setq st (concat st (chart-cell (pop list)))))
>     (setq st (concat st "\n"))
> 
>     st))

Is your function `chart-cell' anyhow related to package chart? If it
is not related, I suggest renaming the function, use your own
prefixes.

And what in general are you trying to do?

M-x chart-emacs-storage

                                               Emacs Runtime Storage Usage




 221M|----------|
     |          |
     |          |
     |          |
     |          |
B147M|          |                                                                           |-----------|
y    |          |                                                                           |           |
t    |          |                                                                           |           |
e    |          |                                                                           |           |
s    |          |                                                                           |           |
  73M|          |                                                  |-----------|            |           |
     |          |                                                  |           |            |           |
     |          |             |----------|                         |           |            |           |
     |          |             |          ||-----------|            |           |            |           |
     |          |             |          ||           ||----------||           |            |           |
    0----------------------------------------------------------------------------------------------------------------
                    symbols               string-bytes             vector-slots               intervals
       conses                   strings                  vectors                  floats                   buffers
                                                      Storage Items


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-10 14:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10  5:38 Improvements on constructing a string Heime
2022-11-10 14:09 ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-11-10 14:28 ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).