diff src/alloc.c @ 4139:0b32ee899a3a

Consistently use the mark bit of the root interval's parent field to say whether or not the interval tree has been visited (and skip it when revisited), and the mark bit of the plist field to say whether or not that interval has been visited (and abort if revisited); don't try to use the plist mark bit for both meanings. * alloc.c (mark_interval_tree): Don't test if the interval tree has already been visited here; let the MARK_INTERVAL_TREE macro do that; avoid function call overhead. Mark the interval tree as having been visited by setting TREE->parent's mark bit. (MARK_INTERVAL_TREE): If the tree has been visited (according to I->parent's mark bit), don't call mark_interval_tree. (gc_sweep): Rebalance the interval trees of those large strings which are still alive. This also clears the mark bits of those trees' root intervals' parent fields. (compact_strings): Rebalance the interval tree of each small strings which is still alive. This also clears the mark bits of that tree's root interval's parent field. Since the string has moved, update the root interval's parent pointer to contain the new address. * lisp.h (struct interval): Doc fix; explain the roles of the mark bits of the parent and plist members.
author Jim Blandy <jimb@redhat.com>
date Sun, 18 Jul 1993 06:26:10 +0000
parents bdecedbd64db
children a696547fb51e
line wrap: on
line diff
--- a/src/alloc.c	Sun Jul 18 06:25:40 1993 +0000
+++ b/src/alloc.c	Sun Jul 18 06:26:10 1993 +0000
@@ -349,14 +349,23 @@
 mark_interval_tree (tree)
      register INTERVAL tree;
 {
-  if (XMARKBIT (tree->plist))
-    return;
+  /* No need to test if this tree has been marked already; this
+     function is always called through the MARK_INTERVAL_TREE macro,
+     which takes care of that.  */
+
+  /* XMARK expands to an assignment; the LHS of an assignment can't be
+     a cast.  */
+  XMARK (* (Lisp_Object *) &tree->parent);
 
   traverse_intervals (tree, 1, 0, mark_interval, Qnil);
 }
 
-#define MARK_INTERVAL_TREE(i) \
-  { if (!NULL_INTERVAL_P (i)) mark_interval_tree (i); }
+#define MARK_INTERVAL_TREE(i)				\
+  do {							\
+    if (!NULL_INTERVAL_P (i)				\
+	&& ! XMARKBIT ((Lisp_Object) i->parent))	\
+      mark_interval_tree (i);				\
+  } while (0)
 
 /* The oddity in the call to XUNMARK is necessary because XUNMARK
    expands to an assignment to its argument, and most C compilers don't
@@ -1957,25 +1966,30 @@
   /* Free all "large strings" not marked with ARRAY_MARK_FLAG.  */
   {
     register struct string_block *sb = large_string_blocks, *prev = 0, *next;
+    struct Lisp_String *s;
 
     while (sb)
-      if (!(((struct Lisp_String *)(&sb->chars[0]))->size & ARRAY_MARK_FLAG))
-	{
-	  if (prev)
-	    prev->next = sb->next;
-	  else
-	    large_string_blocks = sb->next;
-	  next = sb->next;
-	  xfree (sb);
-	  sb = next;
-	}
-      else
-	{
-	  ((struct Lisp_String *)(&sb->chars[0]))->size
-	    &= ~ARRAY_MARK_FLAG & ~MARKBIT;
-	  total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size;
-	  prev = sb, sb = sb->next;
-	}
+      {
+	s = (struct Lisp_String *) &sb->chars[0];
+	if (s->size & ARRAY_MARK_FLAG)
+	  {
+	    ((struct Lisp_String *)(&sb->chars[0]))->size
+	      &= ~ARRAY_MARK_FLAG & ~MARKBIT;
+	    UNMARK_BALANCE_INTERVALS (s->intervals);
+	    total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size;
+	    prev = sb, sb = sb->next;
+	  }
+	else
+	  {
+	    if (prev)
+	      prev->next = sb->next;
+	    else
+	      large_string_blocks = sb->next;
+	    next = sb->next;
+	    xfree (sb);
+	    sb = next;
+	  }
+      }
   }
 }
 
@@ -2067,6 +2081,16 @@
 		}
 	      /* Store the actual size in the size field.  */
 	      newaddr->size = size;
+
+	      /* Now that the string has been relocated, rebalance its
+                 interval tree, and update the tree's parent pointer. */
+	      if (! NULL_INTERVAL_P (newaddr->intervals))
+		{
+		  UNMARK_BALANCE_INTERVALS (newaddr->intervals);
+		  XSET (* (Lisp_Object *) &newaddr->intervals->parent,
+			Lisp_String,
+			newaddr);
+		}
 	    }
 	  pos += STRING_FULLSIZE (size);
 	}