unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dan Nicolaescu <dann@ics.uci.edu>
To: emacs-devel@gnu.org
Subject: make a pure string from a string literal
Date: Wed, 4 Nov 2009 08:01:18 -0800 (PST)	[thread overview]
Message-ID: <200911041601.nA4G1Ijj003807@godzilla.ics.uci.edu> (raw)


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)




             reply	other threads:[~2009-11-04 16:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-04 16:01 Dan Nicolaescu [this message]
2009-11-04 18:41 ` make a pure string from a string literal Juanma Barranquero
2009-11-04 20:40 ` Stefan Monnier
2009-11-04 21:20   ` Dan Nicolaescu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200911041601.nA4G1Ijj003807@godzilla.ics.uci.edu \
    --to=dann@ics.uci.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).