* 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
* Re: make a pure string from a string literal
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
1 sibling, 0 replies; 4+ messages in thread
From: Juanma Barranquero @ 2009-11-04 18:41 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
On Wed, Nov 4, 2009 at 17:01, Dan Nicolaescu <dann@ics.uci.edu> wrote:
> 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"))
It is unlikely, but a build_string("STRING LITERAL") could have text
properties added later.
Juanma
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: make a pure string from a string literal
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
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2009-11-04 20:40 UTC (permalink / raw)
To: Dan Nicolaescu; +Cc: emacs-devel
> So how about adding:
> Lisp_Object
> make_pure_string_from_literal (const char *data)
My local hacks include the hunk below, so I think it's a good idea, tho
I never got around to installing it.
Stefan
@@ -4821,6 +4887,23 @@
return string;
}
+Lisp_Object
+make_pure_c_string (data)
+ const char *data;
+{
+ Lisp_Object string;
+ struct Lisp_String *s;
+ int nchars = strlen (data);
+
+ s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
+ s->inlined = 0;
+ s->size = nchars;
+ s->size_byte = -1;
+ s->data.ptr = data;
+ s->intervals = NULL_INTERVAL;
+ XSETSTRING (string, s);
+ return string;
+}
/* Return a cons allocated from pure space. Give it pure copies
of CAR as car and CDR as cdr. */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: make a pure string from a string literal
2009-11-04 20:40 ` Stefan Monnier
@ 2009-11-04 21:20 ` Dan Nicolaescu
0 siblings, 0 replies; 4+ messages in thread
From: Dan Nicolaescu @ 2009-11-04 21:20 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > So how about adding:
>
> > Lisp_Object
> > make_pure_string_from_literal (const char *data)
>
> My local hacks include the hunk below, so I think it's a good idea, tho
> I never got around to installing it.
Please do.
I'd be happy to install it for you (and make use of it).
> Stefan
>
>
> @@ -4821,6 +4887,23 @@
> return string;
> }
>
> +Lisp_Object
> +make_pure_c_string (data)
> + const char *data;
> +{
> + Lisp_Object string;
> + struct Lisp_String *s;
> + int nchars = strlen (data);
> +
> + s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
> + s->inlined = 0;
> + s->size = nchars;
> + s->size_byte = -1;
> + s->data.ptr = data;
> + s->intervals = NULL_INTERVAL;
> + XSETSTRING (string, s);
> + return string;
> +}
>
> /* Return a cons allocated from pure space. Give it pure copies
> of CAR as car and CDR as cdr. */
^ 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).