aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Brooksby2013-05-23 19:05:25 +0100
committerRichard Brooksby2013-05-23 19:05:25 +0100
commit5d5e2cac0590328a2344563ff577655c8f523dad (patch)
tree5dd2dd9f007ef0c9509a2676bbc2d37a5a7cb435 /mps/code
parentaf707b5d97cf96e7fe847790fa408ff9af889587 (diff)
downloademacs-5d5e2cac0590328a2344563ff577655c8f523dad.tar.gz
emacs-5d5e2cac0590328a2344563ff577655c8f523dad.zip
Deleting some obsolete comment text about callbacks.
Renaming cbsBlockShrink to cbsBlockShrunk and cbsBlockGrow to cbsBlockGrew, since they don't *do* those things, just record that they were done. Tidying up Find functions, where deletion of emergency code had left some strange double nestings. Copied from Perforce Change: 182120 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/cbs.c140
1 files changed, 59 insertions, 81 deletions
diff --git a/mps/code/cbs.c b/mps/code/cbs.c
index 601963ddba2..1a1222e6ab0 100644
--- a/mps/code/cbs.c
+++ b/mps/code/cbs.c
@@ -275,9 +275,8 @@ void CBSFinish(CBS cbs)
275/* Node change operators 275/* Node change operators
276 * 276 *
277 * These four functions are called whenever blocks are created, 277 * These four functions are called whenever blocks are created,
278 * destroyed, grow, or shrink. They report to the client, and 278 * destroyed, grow, or shrink. They maintain the maxSize if fastFind is
279 * perform the necessary memory management. They are responsible 279 * enabled.
280 * for the client interaction logic.
281 */ 280 */
282 281
283static void cbsBlockDelete(CBS cbs, CBSBlock block) 282static void cbsBlockDelete(CBS cbs, CBSBlock block)
@@ -301,7 +300,7 @@ static void cbsBlockDelete(CBS cbs, CBSBlock block)
301 return; 300 return;
302} 301}
303 302
304static void cbsBlockShrink(CBS cbs, CBSBlock block, Size oldSize) 303static void cbsBlockShrunk(CBS cbs, CBSBlock block, Size oldSize)
305{ 304{
306 Size newSize; 305 Size newSize;
307 306
@@ -318,7 +317,7 @@ static void cbsBlockShrink(CBS cbs, CBSBlock block, Size oldSize)
318 } 317 }
319} 318}
320 319
321static void cbsBlockGrow(CBS cbs, CBSBlock block, Size oldSize) 320static void cbsBlockGrew(CBS cbs, CBSBlock block, Size oldSize)
322{ 321{
323 Size newSize; 322 Size newSize;
324 323
@@ -431,23 +430,23 @@ static Res cbsInsertIntoTree(Addr *baseReturn, Addr *limitReturn,
431 Addr rightLimit = rightCBS->limit; 430 Addr rightLimit = rightCBS->limit;
432 cbsBlockDelete(cbs, rightCBS); 431 cbsBlockDelete(cbs, rightCBS);
433 leftCBS->limit = rightLimit; 432 leftCBS->limit = rightLimit;
434 cbsBlockGrow(cbs, leftCBS, oldLeftSize); 433 cbsBlockGrew(cbs, leftCBS, oldLeftSize);
435 } else { /* left block is smaller */ 434 } else { /* left block is smaller */
436 Addr leftBase = leftCBS->base; 435 Addr leftBase = leftCBS->base;
437 cbsBlockDelete(cbs, leftCBS); 436 cbsBlockDelete(cbs, leftCBS);
438 rightCBS->base = leftBase; 437 rightCBS->base = leftBase;
439 cbsBlockGrow(cbs, rightCBS, oldRightSize); 438 cbsBlockGrew(cbs, rightCBS, oldRightSize);
440 } 439 }
441 } else { /* leftMerge, !rightMerge */ 440 } else { /* leftMerge, !rightMerge */
442 oldSize = CBSBlockSize(leftCBS); 441 oldSize = CBSBlockSize(leftCBS);
443 leftCBS->limit = limit; 442 leftCBS->limit = limit;
444 cbsBlockGrow(cbs, leftCBS, oldSize); 443 cbsBlockGrew(cbs, leftCBS, oldSize);
445 } 444 }
446 } else { /* !leftMerge */ 445 } else { /* !leftMerge */
447 if (rightMerge) { 446 if (rightMerge) {
448 oldSize = CBSBlockSize(rightCBS); 447 oldSize = CBSBlockSize(rightCBS);
449 rightCBS->base = base; 448 rightCBS->base = base;
450 cbsBlockGrow(cbs, rightCBS, oldSize); 449 cbsBlockGrew(cbs, rightCBS, oldSize);
451 } else { /* !leftMerge, !rightMerge */ 450 } else { /* !leftMerge, !rightMerge */
452 res = cbsBlockNew(cbs, base, limit); 451 res = cbsBlockNew(cbs, base, limit);
453 if (res != ResOK) 452 if (res != ResOK)
@@ -535,14 +534,14 @@ static Res cbsDeleteFromTree(Addr *baseReturn, Addr *limitReturn,
535 AVER(limit < cbsBlock->limit); 534 AVER(limit < cbsBlock->limit);
536 oldSize = CBSBlockSize(cbsBlock); 535 oldSize = CBSBlockSize(cbsBlock);
537 cbsBlock->base = limit; 536 cbsBlock->base = limit;
538 cbsBlockShrink(cbs, cbsBlock, oldSize); 537 cbsBlockShrunk(cbs, cbsBlock, oldSize);
539 } 538 }
540 } else { 539 } else {
541 AVER(base > cbsBlock->base); 540 AVER(base > cbsBlock->base);
542 if (limit == cbsBlock->limit) { /* remaining fragment at left */ 541 if (limit == cbsBlock->limit) { /* remaining fragment at left */
543 oldSize = CBSBlockSize(cbsBlock); 542 oldSize = CBSBlockSize(cbsBlock);
544 cbsBlock->limit = base; 543 cbsBlock->limit = base;
545 cbsBlockShrink(cbs, cbsBlock, oldSize); 544 cbsBlockShrunk(cbs, cbsBlock, oldSize);
546 } else { /* two remaining fragments */ 545 } else { /* two remaining fragments */
547 Size leftNewSize = AddrOffset(cbsBlock->base, base); 546 Size leftNewSize = AddrOffset(cbsBlock->base, base);
548 Size rightNewSize = AddrOffset(limit, cbsBlock->limit); 547 Size rightNewSize = AddrOffset(limit, cbsBlock->limit);
@@ -553,7 +552,7 @@ static Res cbsDeleteFromTree(Addr *baseReturn, Addr *limitReturn,
553 AVER(limit < cbsBlock->limit); 552 AVER(limit < cbsBlock->limit);
554 oldSize = CBSBlockSize(cbsBlock); 553 oldSize = CBSBlockSize(cbsBlock);
555 cbsBlock->limit = base; 554 cbsBlock->limit = base;
556 cbsBlockShrink(cbs, cbsBlock, oldSize); 555 cbsBlockShrunk(cbs, cbsBlock, oldSize);
557 res = cbsBlockNew(cbs, limit, oldLimit); 556 res = cbsBlockNew(cbs, limit, oldLimit);
558 if (res != ResOK) { 557 if (res != ResOK) {
559 AVER(ResIsAllocFailure(res)); 558 AVER(ResIsAllocFailure(res));
@@ -564,7 +563,7 @@ static Res cbsDeleteFromTree(Addr *baseReturn, Addr *limitReturn,
564 AVER(base > cbsBlock->base); 563 AVER(base > cbsBlock->base);
565 oldSize = CBSBlockSize(cbsBlock); 564 oldSize = CBSBlockSize(cbsBlock);
566 cbsBlock->base = limit; 565 cbsBlock->base = limit;
567 cbsBlockShrink(cbs, cbsBlock, oldSize); 566 cbsBlockShrunk(cbs, cbsBlock, oldSize);
568 res = cbsBlockNew(cbs, oldBase, base); 567 res = cbsBlockNew(cbs, oldBase, base);
569 if (res != ResOK) { 568 if (res != ResOK) {
570 AVER(ResIsAllocFailure(res)); 569 AVER(ResIsAllocFailure(res));
@@ -713,25 +712,25 @@ static void cbsFindDeleteRange(Addr *baseReturn, Addr *limitReturn,
713 712
714 switch(findDelete) { 713 switch(findDelete) {
715 714
716 case CBSFindDeleteNONE: { 715 case CBSFindDeleteNONE:
717 callDelete = FALSE; 716 callDelete = FALSE;
718 } break; 717 break;
719 718
720 case CBSFindDeleteLOW: { 719 case CBSFindDeleteLOW:
721 limit = AddrAdd(base, size); 720 limit = AddrAdd(base, size);
722 } break; 721 break;
723 722
724 case CBSFindDeleteHIGH: { 723 case CBSFindDeleteHIGH:
725 base = AddrSub(limit, size); 724 base = AddrSub(limit, size);
726 } break; 725 break;
727 726
728 case CBSFindDeleteENTIRE: { 727 case CBSFindDeleteENTIRE:
729 /* do nothing */ 728 /* do nothing */
730 } break; 729 break;
731 730
732 default: { 731 default:
733 NOTREACHED; 732 NOTREACHED;
734 } break; 733 break;
735 } 734 }
736 735
737 if (callDelete) { 736 if (callDelete) {
@@ -752,7 +751,7 @@ Bool CBSFindFirst(Addr *baseReturn, Addr *limitReturn,
752 CBS cbs, Size size, CBSFindDelete findDelete) 751 CBS cbs, Size size, CBSFindDelete findDelete)
753{ 752{
754 Bool found; 753 Bool found;
755 Addr base = (Addr)0, limit = (Addr)0; /* only defined when found is TRUE */ 754 SplayNode node;
756 755
757 AVERT(CBS, cbs); 756 AVERT(CBS, cbs);
758 CBSEnter(cbs); 757 CBSEnter(cbs);
@@ -764,24 +763,16 @@ Bool CBSFindFirst(Addr *baseReturn, Addr *limitReturn,
764 AVER(cbs->fastFind); 763 AVER(cbs->fastFind);
765 AVERT(CBSFindDelete, findDelete); 764 AVERT(CBSFindDelete, findDelete);
766 765
767 { 766 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
768 SplayNode node; 767 found = SplayFindFirst(&node, splayTreeOfCBS(cbs), &cbsTestNode,
769 768 &cbsTestTree, NULL, size);
770 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
771 found = SplayFindFirst(&node, splayTreeOfCBS(cbs), &cbsTestNode,
772 &cbsTestTree, NULL, size);
773
774 if (found) {
775 CBSBlock block;
776
777 block = cbsBlockOfSplayNode(node);
778 AVER(CBSBlockSize(block) >= size);
779 base = CBSBlockBase(block);
780 limit = CBSBlockLimit(block);
781 }
782 }
783
784 if (found) { 769 if (found) {
770 CBSBlock block;
771 Addr base, limit;
772 block = cbsBlockOfSplayNode(node);
773 AVER(CBSBlockSize(block) >= size);
774 base = CBSBlockBase(block);
775 limit = CBSBlockLimit(block);
785 AVER(AddrOffset(base, limit) >= size); 776 AVER(AddrOffset(base, limit) >= size);
786 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn, 777 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn,
787 cbs, base, limit, size, findDelete); 778 cbs, base, limit, size, findDelete);
@@ -799,7 +790,7 @@ Bool CBSFindLast(Addr *baseReturn, Addr *limitReturn,
799 CBS cbs, Size size, CBSFindDelete findDelete) 790 CBS cbs, Size size, CBSFindDelete findDelete)
800{ 791{
801 Bool found; 792 Bool found;
802 Addr base = (Addr)0, limit = (Addr)0; /* only defined in found is TRUE */ 793 SplayNode node;
803 794
804 AVERT(CBS, cbs); 795 AVERT(CBS, cbs);
805 CBSEnter(cbs); 796 CBSEnter(cbs);
@@ -811,23 +802,16 @@ Bool CBSFindLast(Addr *baseReturn, Addr *limitReturn,
811 AVER(cbs->fastFind); 802 AVER(cbs->fastFind);
812 AVERT(CBSFindDelete, findDelete); 803 AVERT(CBSFindDelete, findDelete);
813 804
814 { 805 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
815 SplayNode node; 806 found = SplayFindLast(&node, splayTreeOfCBS(cbs), &cbsTestNode,
816 807 &cbsTestTree, NULL, size);
817 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
818 found = SplayFindLast(&node, splayTreeOfCBS(cbs), &cbsTestNode,
819 &cbsTestTree, NULL, size);
820 if (found) {
821 CBSBlock block;
822
823 block = cbsBlockOfSplayNode(node);
824 AVER(CBSBlockSize(block) >= size);
825 base = CBSBlockBase(block);
826 limit = CBSBlockLimit(block);
827 }
828 }
829
830 if (found) { 808 if (found) {
809 CBSBlock block;
810 Addr base, limit;
811 block = cbsBlockOfSplayNode(node);
812 AVER(CBSBlockSize(block) >= size);
813 base = CBSBlockBase(block);
814 limit = CBSBlockLimit(block);
831 AVER(AddrOffset(base, limit) >= size); 815 AVER(AddrOffset(base, limit) >= size);
832 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn, 816 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn,
833 cbs, base, limit, size, findDelete); 817 cbs, base, limit, size, findDelete);
@@ -845,8 +829,8 @@ Bool CBSFindLargest(Addr *baseReturn, Addr *limitReturn,
845 CBS cbs, CBSFindDelete findDelete) 829 CBS cbs, CBSFindDelete findDelete)
846{ 830{
847 Bool found = FALSE; 831 Bool found = FALSE;
848 Addr base = (Addr)0, limit = (Addr)0; /* only defined when found is TRUE */ 832 SplayNode root;
849 Size size = 0; /* suppress bogus warning from MSVC */ 833 Bool notEmpty;
850 834
851 AVERT(CBS, cbs); 835 AVERT(CBS, cbs);
852 CBSEnter(cbs); 836 CBSEnter(cbs);
@@ -856,28 +840,22 @@ Bool CBSFindLargest(Addr *baseReturn, Addr *limitReturn,
856 AVER(cbs->fastFind); 840 AVER(cbs->fastFind);
857 AVERT(CBSFindDelete, findDelete); 841 AVERT(CBSFindDelete, findDelete);
858 842
859 { 843 notEmpty = SplayRoot(&root, splayTreeOfCBS(cbs));
860 SplayNode root; 844 if (notEmpty) {
861 Bool notEmpty; 845 CBSBlock block;
862 846 SplayNode node = NULL; /* suppress "may be used uninitialized" */
863 notEmpty = SplayRoot(&root, splayTreeOfCBS(cbs)); 847 Addr base, limit;
864 if (notEmpty) { 848 Size size;
865 CBSBlock block;
866 SplayNode node = NULL; /* suppress "may be used uninitialized" */
867
868 size = cbsBlockOfSplayNode(root)->maxSize;
869 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
870 found = SplayFindFirst(&node, splayTreeOfCBS(cbs), &cbsTestNode,
871 &cbsTestTree, NULL, size);
872 AVER(found); /* maxSize is exact, so we will find it. */
873 block = cbsBlockOfSplayNode(node);
874 AVER(CBSBlockSize(block) >= size);
875 base = CBSBlockBase(block);
876 limit = CBSBlockLimit(block);
877 }
878 }
879 849
880 if (found) { 850 size = cbsBlockOfSplayNode(root)->maxSize;
851 METER_ACC(cbs->splaySearch, cbs->splayTreeSize);
852 found = SplayFindFirst(&node, splayTreeOfCBS(cbs), &cbsTestNode,
853 &cbsTestTree, NULL, size);
854 AVER(found); /* maxSize is exact, so we will find it. */
855 block = cbsBlockOfSplayNode(node);
856 AVER(CBSBlockSize(block) >= size);
857 base = CBSBlockBase(block);
858 limit = CBSBlockLimit(block);
881 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn, 859 cbsFindDeleteRange(baseReturn, limitReturn, oldBaseReturn, oldLimitReturn,
882 cbs, base, limit, size, findDelete); 860 cbs, base, limit, size, findDelete);
883 } 861 }