unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* make a pure string from a string literal
@ 2009-11-04 16:01 Dan Nicolaescu
  2009-11-04 18:41 ` Juanma Barranquero
  2009-11-04 20:40 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Nicolaescu @ 2009-11-04 16:01 UTC (permalink / raw)
  To: emacs-devel


There are a few build_string("STRING LITERAL") calls in emacs/src/*.c
The result is actually a constant string, so we could do:
Fpurecopy (build_string ("STRING LITERAL"))
but that creates another copy of "STRING LITERAL" in pure memory, we
already a have a perfectly good one in read only memory.

So how about adding:

Lisp_Object
make_pure_string_from_literal (const char *data)
{
  Lisp_Object string;
  struct Lisp_String *s;

  s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
  s->data = data;
  s->size = strlen (data);
  s->size_byte = -1;
  s->intervals = NULL_INTERVAL;
  XSETSTRING (string, s);
  return string;
}

Then we can use make_pure_string_from_literal ("STRING LITERAL"); 

Any objections?
(better suggestions for the function name are welcome)




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

end of thread, other threads:[~2009-11-04 21:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-04 16:01 make a pure string from a string literal Dan Nicolaescu
2009-11-04 18:41 ` Juanma Barranquero
2009-11-04 20:40 ` Stefan Monnier
2009-11-04 21:20   ` Dan Nicolaescu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).