Skip to content

Commit c61d9fd

Browse files
committed
Add headerSize/bodySize/tailSize/fullSize functions to TreeModel, and use them instead of copying
1 parent 9a092dd commit c61d9fd

File tree

14 files changed

+109
-65
lines changed

14 files changed

+109
-65
lines changed

UEFIFind/uefifind.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ USTATUS UEFIFind::findFileRecursive(const UModelIndex index, const UString & hex
9292

9393
// For patterns that cross header|body boundary, skip patterns entirely located in body, since
9494
// children search above has already found them.
95-
if (hasChildren && mode == SEARCH_MODE_ALL && offset >= model->header(index).size()) {
95+
if (hasChildren && mode == SEARCH_MODE_ALL && offset >= model->headerSize(index)) {
9696
offset = -1;
9797
}
9898

UEFITool/ffsfinder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ USTATUS FfsFinder::findHexPattern(const UModelIndex & index, const UByteArray &
7979
if (offset % 2 == 0) {
8080
// For patterns that cross header|body boundary, skip patterns entirely located in body, since
8181
// children search above has already found them.
82-
if (!(hasChildren && mode == SEARCH_MODE_ALL && offset/2 >= model->header(index).size())) {
82+
if (!(hasChildren && mode == SEARCH_MODE_ALL && offset/2 >= model->headerSize(index))) {
8383
UModelIndex parentFileIndex = model->findParentOfType(index, Types::File);
8484
UString name = model->name(index);
8585
if (model->parent(index) == parentFileIndex) {

UEFITool/hexviewdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void HexViewDialog::setItem(const UModelIndex & index, HexViewType type)
4949
switch (type) {
5050
case fullHexView:
5151
dialogTitle = UString("Hex view: ");
52-
hexdata = model->entire(index);
52+
hexdata = model->full(index);
5353
break;
5454
case bodyHexView:
5555
dialogTitle = UString("Body hex view: ");

UEFITool/uefitool.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void UEFITool::updateUiForNewColorScheme(Qt::ColorScheme scheme)
274274
QApplication::setPalette(QApplication::style()->standardPalette());
275275

276276
QModelIndex current = ui->structureTreeView->selectionModel()->currentIndex();
277-
selectedHexView.setBackground(0, model->header(current).size(),
277+
selectedHexView.setBackground(0, model->headerSize(current),
278278
model->markingDarkMode() ? Qt::darkGreen : Qt::green);
279279
}
280280
#endif
@@ -351,9 +351,9 @@ void UEFITool::populateUi(const QModelIndex &current)
351351

352352
// Set Hex view
353353
selectedHexView.clearMetadata();
354-
selectedHexView.setBackground(0, model->header(current).size(),
354+
selectedHexView.setBackground(0, model->headerSize(current),
355355
model->markingDarkMode() ? Qt::darkGreen : Qt::green);
356-
selectedHexView.setData(model->entire(current));
356+
selectedHexView.setData(model->full(current));
357357
enableDock(ui->hexViewDock, true);
358358

359359
// Enable menus
@@ -1562,7 +1562,7 @@ void UEFITool::hashCrc32()
15621562
if (!index.isValid())
15631563
return;
15641564

1565-
QByteArray data = model->entire(index);
1565+
QByteArray data = model->full(index);
15661566
doCrc32(data);
15671567
}
15681568

@@ -1572,7 +1572,7 @@ void UEFITool::hashSha1()
15721572
if (!index.isValid())
15731573
return;
15741574

1575-
QByteArray data = model->entire(index);
1575+
QByteArray data = model->full(index);
15761576
doSha1(data);
15771577
}
15781578

@@ -1582,7 +1582,7 @@ void UEFITool::hashSha256()
15821582
if (!index.isValid())
15831583
return;
15841584

1585-
QByteArray data = model->entire(index);
1585+
QByteArray data = model->full(index);
15861586
doSha256(data);
15871587
}
15881588

@@ -1592,7 +1592,7 @@ void UEFITool::hashSha384()
15921592
if (!index.isValid())
15931593
return;
15941594

1595-
QByteArray data = model->entire(index);
1595+
QByteArray data = model->full(index);
15961596
doSha384(data);
15971597
}
15981598

@@ -1602,7 +1602,7 @@ void UEFITool::hashSha512()
16021602
if (!index.isValid())
16031603
return;
16041604

1605-
QByteArray data = model->entire(index);
1605+
QByteArray data = model->full(index);
16061606
doSha512(data);
16071607
}
16081608

@@ -1612,7 +1612,7 @@ void UEFITool::hashSm3()
16121612
if (!index.isValid())
16131613
return;
16141614

1615-
QByteArray data = model->entire(index);
1615+
QByteArray data = model->full(index);
16161616
doSm3(data);
16171617
}
16181618

UEFITool/uefitool.ui

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,9 @@
10981098
<property name="text">
10991099
<string>&amp;Reset docks layout</string>
11001100
</property>
1101+
<property name="shortcut">
1102+
<string>Ctrl+Shift+D</string>
1103+
</property>
11011104
</action>
11021105
</widget>
11031106
<layoutdefault spacing="6" margin="11"/>

common/ffsbuilder.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ USTATUS FfsBuilder::erase(const UModelIndex & index, UByteArray & erased)
3939
}
4040
}
4141

42-
erased = UByteArray(model->entire(index).size(), emptyByte);
42+
erased = UByteArray(model->fullSize(index), emptyByte);
4343

4444
return U_SUCCESS;
4545
}
@@ -74,7 +74,7 @@ USTATUS FfsBuilder::buildCapsule(const UModelIndex & index, UByteArray & capsule
7474
// No action
7575
if (model->action(index) == Actions::NoAction) {
7676
// Use original item data
77-
capsule = model->entire(index);
77+
capsule = model->full(index);
7878
return U_SUCCESS;
7979
}
8080

@@ -124,7 +124,7 @@ USTATUS FfsBuilder::buildCapsule(const UModelIndex & index, UByteArray & capsule
124124

125125
// Check size of reconstructed capsule body, it must remain the same
126126
UINT32 newSize = (UINT32)capsule.size();
127-
UINT32 oldSize = (UINT32)model->body(index).size();
127+
UINT32 oldSize = model->bodySize(index);
128128
if (newSize > oldSize) {
129129
msg(usprintf("buildCapsule: new capsule size %Xh (%u) is bigger than the original %Xh (%u)", newSize, newSize, oldSize, oldSize), index);
130130
return U_INVALID_CAPSULE;
@@ -154,7 +154,7 @@ USTATUS FfsBuilder::buildIntelImage(const UModelIndex & index, UByteArray & inte
154154

155155
// No action
156156
if (model->action(index) == Actions::NoAction) {
157-
intelImage = model->entire(index);
157+
intelImage = model->full(index);
158158
return U_SUCCESS;
159159
}
160160
// Remove
@@ -165,7 +165,7 @@ USTATUS FfsBuilder::buildIntelImage(const UModelIndex & index, UByteArray & inte
165165
// Rebuild
166166
else if (model->action(index) == Actions::Rebuild) {
167167
// First child will always be descriptor for this type of image, and it's read only for now
168-
intelImage = model->entire(index.model()->index(0, 0, index));
168+
intelImage = model->full(index.model()->index(0, 0, index));
169169

170170
// Process other regions
171171
for (int i = 1; i < model->rowCount(index); i++) {
@@ -179,7 +179,7 @@ USTATUS FfsBuilder::buildIntelImage(const UModelIndex & index, UByteArray & inte
179179
UINT8 type = model->type(currentRegion);
180180
if (type == Types::Padding) {
181181
// Add padding as is
182-
intelImage += model->entire(currentRegion);
182+
intelImage += model->full(currentRegion);
183183
continue;
184184
}
185185

@@ -223,7 +223,7 @@ USTATUS FfsBuilder::buildIntelImage(const UModelIndex & index, UByteArray & inte
223223

224224
// Check size of new image, it must be same as old one
225225
UINT32 newSize = (UINT32)intelImage.size();
226-
UINT32 oldSize = (UINT32)model->body(index).size();
226+
UINT32 oldSize = model->bodySize(index);
227227
if (newSize > oldSize) {
228228
msg(usprintf("buildIntelImage: new image size %Xh (%u) is bigger than the original %Xh (%u)", newSize, newSize, oldSize, oldSize), index);
229229
return U_INVALID_IMAGE;
@@ -250,7 +250,7 @@ USTATUS FfsBuilder::buildRawArea(const UModelIndex & index, UByteArray & rawArea
250250

251251
// No action required
252252
if (model->action(index) == Actions::NoAction) {
253-
rawArea = model->entire(index);
253+
rawArea = model->full(index);
254254
return U_SUCCESS;
255255
}
256256
// Remove
@@ -294,7 +294,7 @@ USTATUS FfsBuilder::buildRawArea(const UModelIndex & index, UByteArray & rawArea
294294

295295
// Check size of new raw area, it must be same as original one
296296
UINT32 newSize = (UINT32)rawArea.size();
297-
UINT32 oldSize = (UINT32)model->body(index).size();
297+
UINT32 oldSize = model->bodySize(index);
298298
if (newSize > oldSize) {
299299
msg(usprintf("buildRawArea: new area size %Xh (%u) is bigger than the original %Xh (%u)", newSize, newSize, oldSize, oldSize), index);
300300
return U_INVALID_RAW_AREA;
@@ -326,7 +326,7 @@ USTATUS FfsBuilder::buildPadding(const UModelIndex & index, UByteArray & padding
326326

327327
// No action required
328328
if (model->action(index) == Actions::NoAction) {
329-
padding = model->entire(index);
329+
padding = model->full(index);
330330
return U_SUCCESS;
331331
}
332332
// Remove
@@ -351,7 +351,7 @@ USTATUS FfsBuilder::buildNonUefiData(const UModelIndex & index, UByteArray & dat
351351

352352
// No action required
353353
if (model->action(index) == Actions::NoAction) {
354-
data = model->entire(index);
354+
data = model->full(index);
355355
return U_SUCCESS;
356356
}
357357
// Remove
@@ -377,7 +377,7 @@ USTATUS FfsBuilder::buildFreeSpace(const UModelIndex & index, UByteArray & freeS
377377
return U_INVALID_PARAMETER;
378378

379379
// No actions possible for free space
380-
freeSpace = model->entire(index);
380+
freeSpace = model->full(index);
381381
return U_SUCCESS;
382382
}
383383

common/ffsops.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ USTATUS FfsOperations::extract(const UModelIndex & index, UString & name, UByteA
2828
if (mode == EXTRACT_MODE_AS_IS) {
2929
// Extract as is, with header body and tail
3030
extracted.clear();
31-
extracted += model->entire(index);
31+
extracted += model->full(index);
3232
}
3333
else if (mode == EXTRACT_MODE_BODY) {
3434
name += UString("_body");

0 commit comments

Comments
 (0)