comparison 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
comparison
equal deleted inserted replaced
4138:42faad1466fa 4139:0b32ee899a3a
347 347
348 static void 348 static void
349 mark_interval_tree (tree) 349 mark_interval_tree (tree)
350 register INTERVAL tree; 350 register INTERVAL tree;
351 { 351 {
352 if (XMARKBIT (tree->plist)) 352 /* No need to test if this tree has been marked already; this
353 return; 353 function is always called through the MARK_INTERVAL_TREE macro,
354 which takes care of that. */
355
356 /* XMARK expands to an assignment; the LHS of an assignment can't be
357 a cast. */
358 XMARK (* (Lisp_Object *) &tree->parent);
354 359
355 traverse_intervals (tree, 1, 0, mark_interval, Qnil); 360 traverse_intervals (tree, 1, 0, mark_interval, Qnil);
356 } 361 }
357 362
358 #define MARK_INTERVAL_TREE(i) \ 363 #define MARK_INTERVAL_TREE(i) \
359 { if (!NULL_INTERVAL_P (i)) mark_interval_tree (i); } 364 do { \
365 if (!NULL_INTERVAL_P (i) \
366 && ! XMARKBIT ((Lisp_Object) i->parent)) \
367 mark_interval_tree (i); \
368 } while (0)
360 369
361 /* The oddity in the call to XUNMARK is necessary because XUNMARK 370 /* The oddity in the call to XUNMARK is necessary because XUNMARK
362 expands to an assignment to its argument, and most C compilers don't 371 expands to an assignment to its argument, and most C compilers don't
363 support casts on the left operand of `='. */ 372 support casts on the left operand of `='. */
364 #define UNMARK_BALANCE_INTERVALS(i) \ 373 #define UNMARK_BALANCE_INTERVALS(i) \
1955 } 1964 }
1956 1965
1957 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */ 1966 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */
1958 { 1967 {
1959 register struct string_block *sb = large_string_blocks, *prev = 0, *next; 1968 register struct string_block *sb = large_string_blocks, *prev = 0, *next;
1969 struct Lisp_String *s;
1960 1970
1961 while (sb) 1971 while (sb)
1962 if (!(((struct Lisp_String *)(&sb->chars[0]))->size & ARRAY_MARK_FLAG)) 1972 {
1963 { 1973 s = (struct Lisp_String *) &sb->chars[0];
1964 if (prev) 1974 if (s->size & ARRAY_MARK_FLAG)
1965 prev->next = sb->next; 1975 {
1966 else 1976 ((struct Lisp_String *)(&sb->chars[0]))->size
1967 large_string_blocks = sb->next; 1977 &= ~ARRAY_MARK_FLAG & ~MARKBIT;
1968 next = sb->next; 1978 UNMARK_BALANCE_INTERVALS (s->intervals);
1969 xfree (sb); 1979 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size;
1970 sb = next; 1980 prev = sb, sb = sb->next;
1971 } 1981 }
1972 else 1982 else
1973 { 1983 {
1974 ((struct Lisp_String *)(&sb->chars[0]))->size 1984 if (prev)
1975 &= ~ARRAY_MARK_FLAG & ~MARKBIT; 1985 prev->next = sb->next;
1976 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size; 1986 else
1977 prev = sb, sb = sb->next; 1987 large_string_blocks = sb->next;
1978 } 1988 next = sb->next;
1989 xfree (sb);
1990 sb = next;
1991 }
1992 }
1979 } 1993 }
1980 } 1994 }
1981 1995
1982 /* Compactify strings, relocate references, and free empty string blocks. */ 1996 /* Compactify strings, relocate references, and free empty string blocks. */
1983 1997
2065 else 2079 else
2066 XSET (*objptr, Lisp_String, newaddr); 2080 XSET (*objptr, Lisp_String, newaddr);
2067 } 2081 }
2068 /* Store the actual size in the size field. */ 2082 /* Store the actual size in the size field. */
2069 newaddr->size = size; 2083 newaddr->size = size;
2084
2085 /* Now that the string has been relocated, rebalance its
2086 interval tree, and update the tree's parent pointer. */
2087 if (! NULL_INTERVAL_P (newaddr->intervals))
2088 {
2089 UNMARK_BALANCE_INTERVALS (newaddr->intervals);
2090 XSET (* (Lisp_Object *) &newaddr->intervals->parent,
2091 Lisp_String,
2092 newaddr);
2093 }
2070 } 2094 }
2071 pos += STRING_FULLSIZE (size); 2095 pos += STRING_FULLSIZE (size);
2072 } 2096 }
2073 } 2097 }
2074 2098