From e8cb9753195a38ed504f74d0f73ce25458cb331b Mon Sep 17 00:00:00 2001 From: icer Date: Tue, 23 Jul 2024 20:48:56 +0300 Subject: [PATCH] fix TODO - skip spaces without memory alloc --- src/archive/ArchiveAscii.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/archive/ArchiveAscii.cc b/src/archive/ArchiveAscii.cc index 4a093f6a..2fd046f9 100644 --- a/src/archive/ArchiveAscii.cc +++ b/src/archive/ArchiveAscii.cc @@ -71,14 +71,19 @@ namespace zenkit { auto line = read->read_line(true); // Compatibility fix for binary data in ASCII archives. - // TODO: Optimize using `find_if`! - while (std::isspace(static_cast(line[0]))) { - line = line.substr(1); + std::string_view view = line; + size_t spaces_count = 0; + for (; spaces_count < view.size() + && std::isspace(static_cast(view[spaces_count])); + ++spaces_count); + + if (spaces_count > 0) { + view.remove_prefix(spaces_count); } - if (line != "[]") { - read->seek(static_cast(mark), Whence::BEG); - return false; + if (view != "[]") { + read->seek(static_cast(mark), Whence::BEG); + return false; } return true;