From 4acacff75a148f62d113d309e48e162c4d20dd77 Mon Sep 17 00:00:00 2001 From: Oz Date: Sun, 20 Nov 2022 11:42:46 +0100 Subject: [PATCH] Avoid unnecessary string allocation when check if archive is multivolume --- src/bitinputarchive.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/bitinputarchive.cpp b/src/bitinputarchive.cpp index 2fcee0f7..b2d9fe9b 100644 --- a/src/bitinputarchive.cpp +++ b/src/bitinputarchive.cpp @@ -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 ) { @@ -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;