guile-devel
[Top][All Lists]
Advanced

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

Re: freeing srcprops ?


From: Han-Wen Nienhuys
Subject: Re: freeing srcprops ?
Date: Fri, 19 Jan 2007 12:52:32 +0100
User-agent: Thunderbird 1.5.0.9 (X11/20061219)

Kevin Ryde escreveu:
> Han-Wen Nienhuys <address@hidden> writes:
>>  SCM
>>  scm_make_srcprops (long line, int col, SCM filename, SCM copy, SCM plist)
>>  {
>> +  if (!SCM_UNBNDP (filename))
>> +    plist = scm_acons (scm_sym_filename, filename, plist);
> 
> Can those two cells be shared among all source props for the same
> file, to save space?

see below.

Hmmm, on 2nd thought, there is a race condition in this code.  Lemme see.

>> +  SCM_RETURN_NEWSMOB3 (scm_tc16_srcprops,
>> +                   SRCPROPMAKPOS (line, col),
> 
> If col is a freaky big value then perhaps put it in the plist.  Could

col is 0x0FFF max, which 4096. Seems plenty for me. 

We could of course increase this limit, but then the max number of
lines goes down from its current value of 1M.


commit 1e8cecc70617d69bd93e8c4761aedf1008f454f6
Author: Han-Wen Nienhuys <address@hidden>
Date:   Fri Jan 19 12:46:57 2007 +0100

    Reuse last filename acons if possible.
    
    This saves on memory use, since plist usually is SCM_EOL.

diff --git a/libguile/srcprop.c b/libguile/srcprop.c
index b44b503..8d61272 100644
--- a/libguile/srcprop.c
+++ b/libguile/srcprop.c
@@ -88,7 +88,6 @@ SCM_GLOBAL_SYMBOL (scm_sym_breakpoint, "breakpoint");
 
 scm_t_bits scm_tc16_srcprops;
 
-
 static SCM
 srcprops_mark (SCM obj)
 {
@@ -117,12 +116,33 @@ scm_c_source_property_breakpoint_p (SCM form)
 }
 
 
+/*
+  A protected cells whose cdr contains the last plist
+  used if plist contains only the filename.
+
+  This works because scm_set_source_property_x does
+  not use assoc-set! for modifying the plist.
+ */
+static SCM scm_last_plist_filename;
 
 SCM
 scm_make_srcprops (long line, int col, SCM filename, SCM copy, SCM plist)
 {
   if (!SCM_UNBNDP (filename))
-    plist = scm_acons (scm_sym_filename, filename, plist);
+    {
+      SCM old_plist = plist;
+      if (old_plist == SCM_EOL
+         && SCM_CDADR (scm_last_plist_filename) == filename)
+       {
+         plist = SCM_CDR (scm_last_plist_filename);
+       }
+      else
+       {
+         plist = scm_acons (scm_sym_filename, filename, plist);
+         if (old_plist == SCM_EOL)
+           SCM_SETCDR (scm_last_plist_filename, plist);
+       }
+    }
   
   SCM_RETURN_NEWSMOB3 (scm_tc16_srcprops,
                       SRCPROPMAKPOS (line, col),
@@ -300,6 +320,10 @@ scm_init_srcprop ()
   scm_source_whash = scm_make_weak_key_hash_table (scm_from_int (2047));
   scm_c_define ("source-whash", scm_source_whash);
 
+  scm_last_plist_filename
+    = scm_permanent_object (scm_cons (SCM_EOL,
+                                     scm_acons (SCM_EOL, SCM_EOL, SCM_EOL)));
+
 #include "libguile/srcprop.x"
 }
 


-- 
 Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen





reply via email to

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