help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Performance of String Operations


From: Pascal J. Bourguignon
Subject: Re: Performance of String Operations
Date: Sun, 11 Oct 2009 19:29:35 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.3 (darwin)

Nordlöw <per.nordlow@gmail.com> writes:

> Does Emacs contain append/prepend/concat functions for strings that
> modify one of its (first) arguments (for side effects only)?
>
> If so, why not?

Because.


> Isn't such a function crucial to the performance of a
> language, regarding that strings is such a common object type?

No, mutation is not crucial to performance.  On the contrary, it can
be detriemental.  Functional programming languages are often faster
than programming languages having mutation.


> Or does the Emacs compiler optimize such things?  

AFAIK, no.


> Can I somehow investigate how Emacs has optimized my lisp code?

Of course.  You've got the sources.



Notice however that emacs provides a data structure for efficient
modification, notably for big strings.  It is called a buffer.


For example:

(with-temp-buffer 
   (insert "hello world")
   (delete-region 1 2)
   (goto-char 1) (insert "H")
   (delete-region 7 8)
   (goto-char 7) (insert "W")
   (end-of-line)
   (insert "!")
   (buffer-substring (point-min) (point-max)))

--> "Hello World!"


-- 
__Pascal Bourguignon__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]