Skip to content

Commit

Permalink
Avoid unnecessary string allocation when check if archive is multivolume
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Nov 20, 2022
1 parent 92c0b56 commit 4acacff
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/bitinputarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,8 @@ IInArchive* BitInputArchive::openArchiveStream( const BitArchiveHandler& handler
return in_archive.Detach();
}

bool endwith(const wstring& in, const wstring& text) {
if (in.size() < text.size()) {
return false;
}
return in.substr(in.size() - text.size()) == text;
bool ends_with(const wstring& str, const wstring& suffix) {
return str.size() >= suffix.size() && str.compare(str.size()-suffix.size(), suffix.size(), suffix) == 0;
}

BitInputArchive::BitInputArchive( const BitArchiveHandler& handler, const wstring& in_file ) {
Expand All @@ -119,7 +116,7 @@ BitInputArchive::BitInputArchive( const BitArchiveHandler& handler, const wstrin
mDetectedFormat = &handler.format();
#endif
CMyComPtr< IInStream > file_stream = nullptr;
if (*mDetectedFormat ==BitFormat::SevenZip && endwith(in_file,L"001")) {
if (*mDetectedFormat ==BitFormat::SevenZip && ends_with(in_file,L"001")) {
auto* file_stream_spec = new CMultiStream;
int nIndex = 1;
wstring curIndexFile = in_file;
Expand Down

0 comments on commit 4acacff

Please sign in to comment.