comparison src/alloc.c @ 1295:a9241dc503ab

(mark_object): Avoid car recursion on cons with nil in cdr. Avoid recursion on constants-vector of a compiled function.
author Richard M. Stallman <rms@gnu.org>
date Thu, 01 Oct 1992 23:07:09 +0000
parents 2b07af77d7ec
children b13b79e28eb5
comparison
equal deleted inserted replaced
1294:81c5d1c4a7ed 1295:a9241dc503ab
1330 1330
1331 case Lisp_Vector: 1331 case Lisp_Vector:
1332 case Lisp_Window: 1332 case Lisp_Window:
1333 case Lisp_Process: 1333 case Lisp_Process:
1334 case Lisp_Window_Configuration: 1334 case Lisp_Window_Configuration:
1335 case Lisp_Compiled:
1336 { 1335 {
1337 register struct Lisp_Vector *ptr = XVECTOR (obj); 1336 register struct Lisp_Vector *ptr = XVECTOR (obj);
1338 register int size = ptr->size; 1337 register int size = ptr->size;
1339 struct Lisp_Vector *volatile ptr1 = ptr; 1338 struct Lisp_Vector *volatile ptr1 = ptr;
1340 register int i; 1339 register int i;
1348 mark_object (&ptr->contents[i]); 1347 mark_object (&ptr->contents[i]);
1349 } 1348 }
1350 } 1349 }
1351 break; 1350 break;
1352 1351
1352 case Lisp_Compiled:
1353 /* We could treat this just like a vector, but it is better
1354 to save the COMPILED_CONSTANTS element for last and avoid recursion
1355 there. */
1356 {
1357 register struct Lisp_Vector *ptr = XVECTOR (obj);
1358 register int size = ptr->size;
1359 struct Lisp_Vector *volatile ptr1 = ptr;
1360 register int i;
1361
1362 if (size & ARRAY_MARK_FLAG) break; /* Already marked */
1363 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */
1364 for (i = 0; i < size; i++) /* and then mark its elements */
1365 {
1366 if (ptr != ptr1)
1367 abort ();
1368 if (i != COMPILED_CONSTANTS)
1369 mark_object (&ptr->contents[i]);
1370 }
1371 objptr = &ptr->contents[COMPILED_CONSTANTS];
1372 obj = *objptr;
1373 goto loop;
1374 }
1375
1353 #ifdef MULTI_FRAME 1376 #ifdef MULTI_FRAME
1354 case Lisp_Frame: 1377 case Lisp_Frame:
1355 { 1378 {
1356 register struct frame *ptr = XFRAME (obj); 1379 register struct frame *ptr = XFRAME (obj);
1357 register int size = ptr->size; 1380 register int size = ptr->size;
1368 mark_object (&ptr->minibuffer_window); 1391 mark_object (&ptr->minibuffer_window);
1369 mark_object (&ptr->param_alist); 1392 mark_object (&ptr->param_alist);
1370 } 1393 }
1371 break; 1394 break;
1372 #endif /* not MULTI_FRAME */ 1395 #endif /* not MULTI_FRAME */
1373
1374 #if 0
1375 case Lisp_Temp_Vector:
1376 {
1377 register struct Lisp_Vector *ptr = XVECTOR (obj);
1378 register int size = ptr->size;
1379 register int i;
1380
1381 for (i = 0; i < size; i++) /* and then mark its elements */
1382 mark_object (&ptr->contents[i]);
1383 }
1384 break;
1385 #endif /* 0 */
1386 1396
1387 case Lisp_Symbol: 1397 case Lisp_Symbol:
1388 { 1398 {
1389 register struct Lisp_Symbol *ptr = XSYMBOL (obj); 1399 register struct Lisp_Symbol *ptr = XSYMBOL (obj);
1390 struct Lisp_Symbol *ptrx; 1400 struct Lisp_Symbol *ptrx;
1408 1418
1409 case Lisp_Marker: 1419 case Lisp_Marker:
1410 XMARK (XMARKER (obj)->chain); 1420 XMARK (XMARKER (obj)->chain);
1411 /* DO NOT mark thru the marker's chain. 1421 /* DO NOT mark thru the marker's chain.
1412 The buffer's markers chain does not preserve markers from gc; 1422 The buffer's markers chain does not preserve markers from gc;
1413 instead, markers are removed from the chain when they are freed by gc. */ 1423 instead, markers are removed from the chain when freed by gc. */
1414 break; 1424 break;
1415 1425
1416 case Lisp_Cons: 1426 case Lisp_Cons:
1417 case Lisp_Buffer_Local_Value: 1427 case Lisp_Buffer_Local_Value:
1418 case Lisp_Some_Buffer_Local_Value: 1428 case Lisp_Some_Buffer_Local_Value:
1419 { 1429 {
1420 register struct Lisp_Cons *ptr = XCONS (obj); 1430 register struct Lisp_Cons *ptr = XCONS (obj);
1421 if (XMARKBIT (ptr->car)) break; 1431 if (XMARKBIT (ptr->car)) break;
1422 XMARK (ptr->car); 1432 XMARK (ptr->car);
1433 /* If the cdr is nil, avoid recursion for the car. */
1434 if (EQ (ptr->cdr, Qnil))
1435 {
1436 objptr = &ptr->car;
1437 obj = ptr->car;
1438 XUNMARK (obj);
1439 goto loop;
1440 }
1423 mark_object (&ptr->car); 1441 mark_object (&ptr->car);
1424 objptr = &ptr->cdr; 1442 objptr = &ptr->cdr;
1425 obj = ptr->cdr; 1443 obj = ptr->cdr;
1426 goto loop; 1444 goto loop;
1427 } 1445 }