emacs-devel
[Top][All Lists]
Advanced

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

Re: using empty_string as the only "" string


From: Dmitry Antipov
Subject: Re: using empty_string as the only "" string
Date: Sat, 28 Apr 2007 12:54:31 +0400
User-agent: Thunderbird 1.5.0.7 (X11/20061008)

Richard Stallman wrote:

Text properties are attached to characters.  A null string has no characters
so it cannot have properties.

Ok, so here is a version with two canonical strings allocated from pure space.
Both canonical strings shares XSTRING(s)->data, but it should be valid since
it can't be modified anyway.

Dmitry

Index: alloc.c
===================================================================
RCS file: /sources/emacs/emacs/src/alloc.c,v
retrieving revision 1.409
diff -u -r1.409 alloc.c
--- alloc.c     16 Apr 2007 03:09:33 -0000      1.409
+++ alloc.c     26 Apr 2007 13:22:16 -0000
@@ -1756,6 +1756,8 @@
   string_blocks = NULL;
   n_string_blocks = 0;
   string_free_list = NULL;
+  empty_string = make_pure_string ("", 0, 0, 0);
+  empty_multibyte_string = make_pure_string ("", 0, 0, 1);
 }
 
 
@@ -2479,6 +2481,9 @@
      int length;
 {
   Lisp_Object val;
+
+  if (!length)
+    return empty_string;
   val = make_uninit_multibyte_string (length, length);
   STRING_SET_UNIBYTE (val);
   return val;
@@ -2497,6 +2502,8 @@
 
   if (nchars < 0)
     abort ();
+  if (!nbytes)
+    return empty_multibyte_string;
 
   s = allocate_string ();
   allocate_string_data (s, nchars, nbytes);
Index: emacs.c
===================================================================
RCS file: /sources/emacs/emacs/src/emacs.c,v
retrieving revision 1.401
diff -u -r1.401 emacs.c
--- emacs.c     3 Apr 2007 15:25:28 -0000       1.401
+++ emacs.c     26 Apr 2007 13:22:19 -0000
@@ -133,8 +133,8 @@
 /* Hook run by `kill-emacs' before it does really anything.  */
 Lisp_Object Vkill_emacs_hook;
 
-/* An empty lisp string.  To avoid having to build any other.  */
-Lisp_Object empty_string;
+/* An empty lisp strings.  To avoid having to build any others.  */
+Lisp_Object empty_string, empty_multibyte_string;
 
 /* Search path separator.  */
 Lisp_Object Vpath_separator;
@@ -2468,9 +2468,6 @@
 The hook is not run in batch mode, i.e., if `noninteractive' is non-nil.  */);
   Vkill_emacs_hook = Qnil;
 
-  empty_string = build_string ("");
-  staticpro (&empty_string);
-
   DEFVAR_INT ("emacs-priority", &emacs_priority,
              doc: /* Priority for Emacs to run at.
 This value is effective only if set before Emacs is dumped,
Index: lisp.h
===================================================================
RCS file: /sources/emacs/emacs/src/lisp.h,v
retrieving revision 1.574
diff -u -r1.574 lisp.h
--- lisp.h      17 Mar 2007 18:27:10 -0000      1.574
+++ lisp.h      27 Apr 2007 15:23:33 -0000
@@ -701,7 +701,10 @@
 #endif /* not GC_CHECK_STRING_BYTES */
 
 /* Mark STR as a unibyte string.  */
-#define STRING_SET_UNIBYTE(STR)      (XSTRING (STR)->size_byte = -1)
+#define STRING_SET_UNIBYTE(STR)  \
+  do { if (EQ (STR, empty_multibyte_string))  \
+      (STR) = empty_string;  \
+    else XSTRING (STR)->size_byte = -1; } while (0)
 
 /* Get text properties.  */
 #define STRING_INTERVALS(STR)  (XSTRING (STR)->intervals + 0)
@@ -3060,7 +3063,8 @@
 /* defined in emacs.c */
 extern Lisp_Object decode_env_path P_ ((char *, char *));
 extern Lisp_Object Vinvocation_name, Vinvocation_directory;
-extern Lisp_Object Vinstallation_directory, empty_string;
+extern Lisp_Object Vinstallation_directory;
+extern Lisp_Object empty_string, empty_multibyte_string;
 EXFUN (Fkill_emacs, 1);
 #if HAVE_SETLOCALE
 void fixup_locale P_ ((void));
Index: lread.c
===================================================================
RCS file: /sources/emacs/emacs/src/lread.c,v
retrieving revision 1.369
diff -u -r1.369 lread.c
--- lread.c     28 Mar 2007 08:16:19 -0000      1.369
+++ lread.c     26 Apr 2007 13:22:35 -0000
@@ -4070,8 +4070,7 @@
 in order to do so.  However, if you want to customize which suffixes
 the loading functions recognize as compression suffixes, you should
 customize `jka-compr-load-suffixes' rather than the present variable.  */);
-  /* We don't use empty_string because it's not initialized yet.  */
-  Vload_file_rep_suffixes = Fcons (build_string (""), Qnil);
+  Vload_file_rep_suffixes = Fcons (empty_string, Qnil);
 
   DEFVAR_BOOL ("load-in-progress", &load_in_progress,
               doc: /* Non-nil iff inside of `load'.  */);

reply via email to

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