emacs-devel
[Top][All Lists]
Advanced

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

Using empty_string as the only "" string


From: Dmitry Antipov
Subject: Using empty_string as the only "" string
Date: Tue, 24 Apr 2007 20:32:12 +0400
User-agent: Thunderbird 1.5.0.7 (X11/20061008)

Hello all,

probably I've missed something, but what's the reason(s) to have a
lot of "" (zero-length) strings ? Why not uniq them into the only
one ? Here is a way I'm doing this...

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     24 Apr 2007 15:38:29 -0000
@@ -1947,7 +1947,7 @@
    S->data.  Set S->size to NCHARS and S->size_byte to NBYTES.  Free
    S->data if it was initially non-null.  */
 
-void
+struct Lisp_String *
 allocate_string_data (s, nchars, nbytes)
      struct Lisp_String *s;
      int nchars, nbytes;
@@ -2049,6 +2049,7 @@
     }
 
   consing_since_gc += needed;
+  return s;
 }
 
 
@@ -2493,14 +2494,14 @@
      int nchars, nbytes;
 {
   Lisp_Object string;
-  struct Lisp_String *s;
 
   if (nchars < 0)
     abort ();
+  if (!nbytes)
+    return empty_string;
 
-  s = allocate_string ();
-  allocate_string_data (s, nchars, nbytes);
-  XSETSTRING (string, s);
+  XSETSTRING (string, allocate_string_data (allocate_string (), 
+                                           nchars, nbytes));
   string_chars_consed += nbytes;
   return string;
 }
@@ -6469,6 +6470,12 @@
   Qpost_gc_hook = intern ("post-gc-hook");
   staticpro (&Qpost_gc_hook);
 
+  /* Must be initialized before any other possible string
+     allocation can be made, and before syms_of_lread ().  */
+  XSETSTRING (empty_string, allocate_string_data (allocate_string (), 0, 0));
+  STRING_SET_UNIBYTE (empty_string);
+  staticpro (&empty_string);
+
   DEFVAR_LISP ("memory-signal-data", &Vmemory_signal_data,
               doc: /* Precomputed `signal' argument for memory-full error.  
*/);
   /* We build this in advance because if we wait until we need it, we might
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     24 Apr 2007 15:38:38 -0000
@@ -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      24 Apr 2007 15:38:42 -0000
@@ -2545,7 +2545,8 @@
 
 /* Defined in alloc.c */
 extern void check_pure_size P_ ((void));
-extern void allocate_string_data P_ ((struct Lisp_String *, int, int));
+extern struct Lisp_String * allocate_string_data P_ ((struct Lisp_String *,
+                                                     int, int));
 extern void reset_malloc_hooks P_ ((void));
 extern void uninterrupt_malloc P_ ((void));
 extern void malloc_warning P_ ((char *));
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     24 Apr 2007 15:38:47 -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]