Skip to content

Commit

Permalink
[libromdata] Remove PartitionFile in a few cases where it isn't needed.
Browse files Browse the repository at this point in the history
In these cases, a PartitionFile was created that started at offset 0
and had the size of the entire IDiscReader.

This was used solely to allow using an IDiscReader as an IRpFile.
Since IDiscReader is now derived from IRpFile, this isn't necessary.
Removing PartitionFile in these cases reduces code size a bit, as
well as reducing runtime overhead.

Code size difference: (64-bit Gentoo Linux, gcc-13.2.0, release build, no LTO)

   text    data     bss     dec     hex filename
2049515   70792     704 2121011  205d33 libromdata.so.4 [before]
2048911   70760     704 2120375  205ab7 libromdata.so.4 [after]
   -604     -32       0    -636    -27c Difference
  • Loading branch information
GerbilSoft committed Nov 12, 2023
1 parent 80f142c commit dc5cd78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
6 changes: 1 addition & 5 deletions src/libromdata/Console/Dreamcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,7 @@ int Dreamcast::loadFieldData(void)
isoData = d->gdiReader->openIsoRomData(3);
} else {
// ISO object for ISO-9660 PVD
PartitionFilePtr isoFile = std::make_shared<PartitionFile>(
d->discReader.get(), 0, d->discReader->size());
if (isoFile->isOpen()) {
isoData = std::make_shared<ISO>(isoFile);
}
isoData = std::make_shared<ISO>(d->discReader);
}

if (isoData && isoData->isOpen()) {
Expand Down
17 changes: 10 additions & 7 deletions src/libromdata/Console/Xbox360_XEX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,18 +1188,21 @@ const EXE *Xbox360_XEX_Private::initEXE(void)
// PE section, so we don't have to look anything up.

// Attempt to open the EXE section.
// Assuming a maximum of 8 KB for the PE headers.
IRpFilePtr peFile_tmp;
#ifdef ENABLE_LIBMSPACK
if (!lzx_peHeader.empty()) {
peFile_tmp = std::make_shared<MemFile>(lzx_peHeader.data(), lzx_peHeader.size());
IRpFilePtr peFile_tmp = std::make_shared<MemFile>(lzx_peHeader.data(), lzx_peHeader.size());
if (peFile_tmp->isOpen()) {
EXE *const pe_exe_tmp = new EXE(peFile_tmp);
if (pe_exe_tmp->isOpen()) {
pe_exe = pe_exe_tmp;
} else {
delete pe_exe_tmp;
}
}
} else
#endif /* ENABLE_LIBMSPACK */
{
peFile_tmp = std::make_shared<PartitionFile>(peReader.get(), 0, PE_HEADER_SIZE);
}
if (peFile_tmp->isOpen()) {
EXE *const pe_exe_tmp = new EXE(peFile_tmp);
EXE *const pe_exe_tmp = new EXE(peReader);
if (pe_exe_tmp->isOpen()) {
pe_exe = pe_exe_tmp;
} else {
Expand Down
13 changes: 2 additions & 11 deletions src/libromdata/Handheld/Nintendo3DS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ int Nintendo3DSPrivate::openSRL(void)
}

// Attempt to open the SRL as if it's a new file.
// TODO: IRpFile implementation with offset/length, so we don't
// have to use both DiscReader and PartitionFile.

// Check if this content is encrypted.
// If it is, we'll need to create a CIAReader.
Expand All @@ -615,15 +613,8 @@ int Nintendo3DSPrivate::openSRL(void)
return -EIO;
}

// TODO: Make IDiscReader derive from IRpFile.
// May need to add reference counting to IRpFile...
RomDataPtr srlData;
PartitionFilePtr srlFile = std::make_shared<PartitionFile>(srlReader.get(), 0, length);
if (srlFile->isOpen()) {
// Create the NintendoDS object.
srlData = std::make_shared<NintendoDS>(srlFile, true);
}

// Create the NintendoDS object.
RomDataPtr srlData = std::make_shared<NintendoDS>(srlReader, true);
if (srlData && srlData->isOpen() && srlData->isValid()) {
// SRL opened successfully.
this->mainContent = std::move(srlData);
Expand Down
4 changes: 1 addition & 3 deletions src/libromdata/Handheld/PSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,7 @@ int PSP::loadFieldData(void)
// TODO: Parse firmware update PARAM.SFO and EBOOT.BIN?

// ISO object for ISO-9660 PVD
// TODO: DiscReader overload for ISO.
const PartitionFilePtr ptFile = std::make_shared<PartitionFile>(d->discReader.get(), 0, d->discReader->size());
ISO *const isoData = new ISO(ptFile);
ISO *const isoData = new ISO(d->discReader);
if (isoData->isOpen()) {
// Add the fields.
const RomFields *const isoFields = isoData->fields();
Expand Down

0 comments on commit dc5cd78

Please sign in to comment.