Skip to content

Commit 6d4b23b

Browse files
Performance improvements by avoiding deep copies of the bits list.
1 parent 32b14e1 commit 6d4b23b

File tree

4 files changed

+52
-42
lines changed

4 files changed

+52
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ is a Zilog Z8 ROM from a music synthesize module.
2626

2727
## Release Changelog
2828

29-
`master` -- Nothing yet.
29+
`master` -- Performance improvements by avoiding deep copies in lists.
3030

3131
2024-08-18 -- Gatorom's solver-set option now uses descriptive
3232
fiilenames. GUI can now export a set of solved results with

maskromtool.cpp

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -197,24 +197,23 @@ void MaskRomTool::clear(){
197197
//Select nothing.
198198
scene->selection=QList<QGraphicsItem*>();
199199

200-
foreach (RomBitItem* item, bits)
201-
delete item;
200+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++)
201+
delete *i;
202202
bits.clear();
203203
assert(bits.isEmpty());
204204
bits.empty();
205-
foreach (RomBitFix* item, bitfixes)
206-
delete item;
205+
for(auto i=bitfixes.constBegin(); i!=bitfixes.constEnd(); i++)
206+
delete *i;
207207
bitfixes.clear();
208-
209208
assert(bitfixes.isEmpty());
210209
bitfixes.empty();
211-
foreach (RomLineItem* item, rows)
212-
delete item;
210+
for(auto i = rows.constBegin(); i != rows.constEnd(); i++)
211+
delete *i;
213212
rows.clear();
214213
assert(rows.isEmpty());
215214
rows.empty();
216-
foreach (RomLineItem* item, cols)
217-
delete item;
215+
for(auto i = cols.constBegin(); i != cols.constEnd(); i++)
216+
delete *i;
218217
cols.clear();
219218
assert(cols.isEmpty());
220219
cols.empty();
@@ -549,14 +548,14 @@ void MaskRomTool::setLinesVisible(bool b){
549548
}
550549
void MaskRomTool::setBitsVisible(bool b){
551550
bitsVisible=b; //Default for new bits.
552-
foreach (QGraphicsItem* item, bits)
553-
item->setVisible(b);
554-
foreach (QGraphicsItem* item, bitfixes)
555-
item->setVisible(b);
551+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++)
552+
(*i)->setVisible(b);
553+
for(auto i=bitfixes.constBegin(); i!=bitfixes.constEnd(); i++)
554+
(*i)->setVisible(b);
556555
}
557556
void MaskRomTool::setViolationsVisible(bool b){
558-
foreach (QGraphicsItem* item, violations)
559-
item->setVisible(b);
557+
for(auto i=violations.constBegin(); i!=violations.constEnd(); i++)
558+
(*i)->setVisible(b);
560559
}
561560

562561
//Highlights one item close to the center.
@@ -1047,8 +1046,8 @@ void MaskRomTool::updateThresholdHistogram(bool force){
10471046
reds[i]=greens[i]=blues[i]=0;
10481047

10491048
//Count the bits of each color.
1050-
foreach(RomBitItem* bit, bits){
1051-
long pixel=bit->bitvalue_raw(this, background);
1049+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++){
1050+
long pixel=(*i)->bitvalue_raw(this, background);
10521051
int r=((pixel>>16)&0xFF);
10531052
int g=((pixel>>8)&0xFF);
10541053
int b=((pixel)&0xFF);
@@ -1137,10 +1136,10 @@ void MaskRomTool::setBitSize(qreal size){
11371136
bitSize=size;
11381137

11391138
//We do not remark the bits here, but we do resize them.
1140-
foreach (RomBitItem* bit, bits)
1141-
bit->setBitSize(bitSize);
1142-
foreach (RomBitFix* fix, bitfixes)
1143-
fix->setBitSize(bitSize);
1139+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++)
1140+
(*i)->setBitSize(bitSize);
1141+
for(auto i=bitfixes.constBegin(); i!=bitfixes.constEnd(); i++)
1142+
(*i)->setBitSize(bitSize);
11441143

11451144
//Violations are not dynamically resized.
11461145
RomRuleViolation::bitSize=bitSize;
@@ -1645,6 +1644,7 @@ void MaskRomTool::clearBits(bool full){
16451644
* wipe away bits without hogging the redraw thread. Like markBits(),
16461645
* it might take a few frames to finish on large projects.
16471646
*/
1647+
/* Older method, supported partial erase but performed deep copies.
16481648
foreach(QGraphicsItem* item, bits){
16491649
if(isPointVisible(item->pos())){
16501650
scene->removeItem(item);
@@ -1667,18 +1667,28 @@ void MaskRomTool::clearBits(bool full){
16671667
return;
16681668
}
16691669
}
1670-
16711670
//For a full erase, we eliminate items in bulk.
16721671
if(full)
16731672
bits.clear();
1673+
*/
1674+
1675+
//This avoids a deep copy, but cannot be partial.
1676+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++){
1677+
scene->removeItem(*i);
1678+
delete *i;
1679+
bitcount--;
1680+
}
1681+
bits.clear();
1682+
1683+
16741684
assert(bits.isEmpty());
16751685

16761686

16771687
//Reset the markers so we can start again.
1678-
foreach (RomLineItem* line, rows)
1679-
line->marked=false;
1680-
foreach (RomLineItem* line, cols)
1681-
line->marked=false;
1688+
for(auto i = rows.constBegin(); i != rows.constEnd(); i++)
1689+
(*i)->marked=false;
1690+
for(auto i = cols.constBegin(); i != cols.constEnd(); i++)
1691+
(*i)->marked=false;
16821692

16831693
//Next step is to mark the bits.
16841694
bitcount=0;
@@ -1710,9 +1720,9 @@ void MaskRomTool::markFixes(){
17101720

17111721
//Marks up all of the known bits with new samples.
17121722
void MaskRomTool::remarkBits(){
1713-
foreach (RomBitItem* bit, bits){
1714-
bit->bitvalue_raw(this, background);
1715-
bit->bitvalue_sample(this, background, thresholdR, thresholdG, thresholdB);
1723+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++){
1724+
(*i)->bitvalue_raw(this, background);
1725+
(*i)->bitvalue_sample(this, background, thresholdR, thresholdG, thresholdB);
17161726
}
17171727
//We remark all fixes here, because it's fast.
17181728
markFixes();
@@ -1983,15 +1993,15 @@ void MaskRomTool::highlightAdrRange(uint32_t start, uint32_t end){
19831993
//Update the decoding and mark the bits.
19841994
gatorom();
19851995

1986-
foreach (RomBitItem* b, bits){
1987-
uint32_t a=b->adr;
1996+
for(auto i=bits.constBegin(); i!=bits.constEnd(); i++){
1997+
uint32_t a=(*i)->adr;
19881998

19891999
if(start<=a && a<=end){
1990-
RomRuleViolation* violation=new RomRuleViolation(b->pos(),
2000+
RomRuleViolation* violation=new RomRuleViolation((*i)->pos(),
19912001
QString::asprintf("bit&0x%02x at 0x%04x",
1992-
(unsigned int) b->mask,a),
2002+
(unsigned int) (*i)->mask,a),
19932003
QString::asprintf("bit&0x%02x at 0x%04x",
1994-
(unsigned int) b->mask,a));
2004+
(unsigned int) (*i)->mask,a));
19952005
violation->error=false;
19962006
addViolation(violation);
19972007
}

maskromtool.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ class MaskRomTool : public QMainWindow{
6565
QImage background;
6666
QGraphicsPixmapItem *backgroundpixmap;
6767

68-
QList<RomLineItem*> rows; //Rows produce bits where they intersect with columns.
69-
QList<RomLineItem*> cols; //Columns produce bits on rows.
70-
QList<RomBitItem*> bits; //All of the bits from crosses, left-sorted.
71-
QList<RomBitFix*> bitfixes; //Forced bits, used to keep human agency above the thinking machine.
72-
QList<RomRuleViolation*> violations; //DRC Errors and warnings.
68+
QVector<RomLineItem*> rows; //Rows produce bits where they intersect with columns.
69+
QVector<RomLineItem*> cols; //Columns produce bits on rows.
70+
QVector<RomBitItem*> bits; //All of the bits from crosses, left-sorted.
71+
QVector<RomBitFix*> bitfixes; //Forced bits, used to keep human agency above the thinking machine.
72+
QVector<RomRuleViolation*> violations; //DRC Errors and warnings.
7373
long bitcount=0; //Total count of bits from the latest marking.
7474
long rowcount=0, colcount=0;
7575
void removeItem(QGraphicsItem* item); //Removes an item of any type from the view and its QSet.

romscene.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,12 @@ void RomScene::highlightSelection(){
309309
return;
310310

311311
//reset line focus first, would be nice if we knew the last one that was in focus
312-
for(QList<RomLineItem*>::iterator i = maskRomTool->rows.begin(), end = maskRomTool->rows.end(); i != end; ++i){
312+
for(auto i = maskRomTool->rows.constBegin(); i != maskRomTool->rows.constEnd(); i++){
313313
((QGraphicsLineItem*)*i)->setPen(QPen(maskRomTool->lineColor, 2));
314314
((QGraphicsLineItem*)*i)->hide();
315315
((QGraphicsLineItem*)*i)->show();
316316
}
317-
for(QList<RomLineItem*>::iterator i = maskRomTool->cols.begin(), end = maskRomTool->cols.end(); i != end; ++i){
317+
for(auto i = maskRomTool->cols.constBegin(); i != maskRomTool->cols.constEnd(); i++){
318318
((QGraphicsLineItem*)*i)->setPen(QPen(maskRomTool->lineColor, 2));
319319
((QGraphicsLineItem*)*i)->hide();
320320
((QGraphicsLineItem*)*i)->show();

0 commit comments

Comments
 (0)