From 214a4a62fece96b4aa29a217ce0a9de1e6ef4c82c7b50cf37714faac1c8d64ba Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Mon, 11 Aug 2025 01:54:39 -0400 Subject: [PATCH] Another `SimpleVector` nuked. --- dw/textblock.cc | 21 +++++++++------------ dw/textblock.hh | 2 +- dw/textblock_linebreaking.cc | 4 ++-- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/dw/textblock.cc b/dw/textblock.cc index ea291dc..c4ce215 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -233,7 +233,6 @@ Textblock::Textblock (bool limitTextWidth, bool treatAsInline) lines = new misc::SimpleVector (1); nonTemporaryLines = 0; words = new misc::NotSoSimpleVector (1); - anchors = new misc::SimpleVector (1); wrapRefLines = wrapRefParagraphs = -1; wrapRefLinesFCX = wrapRefLinesFCY = -1; @@ -280,16 +279,15 @@ Textblock::~Textblock () for (int i = 0; i < words->size(); i++) cleanupWord (i); - for (int i = 0; i < anchors->size(); i++) { - Anchor *anchor = anchors->getRef (i); + for( const Anchor &anchor: anchors ) + { /* This also frees the names (see removeAnchor() and related). */ - removeAnchor(anchor->name); + removeAnchor(anchor.name); } delete paragraphs; delete lines; delete words; - delete anchors; /* Make sure we don't own widgets anymore. Necessary before call of parent class destructor. (???) */ @@ -710,8 +708,8 @@ void Textblock::sizeAllocateImpl (core::Allocation *allocation) sizeAllocateEnd (); - for (int i = 0; i < anchors->size(); i++) { - Anchor *anchor = anchors->getRef(i); + for (int i = 0; i < anchors.size(); i++) { + Anchor *anchor = &anchors.at(i); int y; if (anchor->wordIndex >= words->size() || @@ -2583,12 +2581,11 @@ bool Textblock::addAnchor (const char *name, core::style::Style *style) */ result = false; else { - Anchor *anchor; + anchors.emplace_back(); + Anchor &anchor= anchors.back(); - anchors->increase(); - anchor = anchors->getRef(anchors->size() - 1); - anchor->name = copy; - anchor->wordIndex = words->size(); + anchor.name = copy; + anchor.wordIndex = words->size(); result = true; } diff --git a/dw/textblock.hh b/dw/textblock.hh index 2f6c699..328ff0f 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -613,7 +613,7 @@ protected: lout::misc::SimpleVector *paragraphs; int nonTemporaryLines; lout::misc::NotSoSimpleVector *words; - lout::misc::SimpleVector *anchors; + std::vector< Anchor > anchors; struct { int index, nChar; } hlStart[core::HIGHLIGHT_NUM_LAYERS], hlEnd[core::HIGHLIGHT_NUM_LAYERS]; diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 41aa873..8ab5616 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -1440,8 +1440,8 @@ int Textblock::hyphenateWord (int wordIndex, int *addIndex1) moveWordIndices (wordIndex, numBreaks, addIndex1); // Adjust anchor indexes. - for (int i = 0; i < anchors->size (); i++) { - Anchor *anchor = anchors->getRef (i); + for (int i = 0; i < anchors.size (); i++) { + Anchor *anchor = &anchors.at (i); if (anchor->wordIndex > wordIndex) anchor->wordIndex += numBreaks; }