Skip to content

Commit

Permalink
fix TODO - skip spaces without memory alloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Domarion committed Jul 23, 2024
1 parent f942cf2 commit e8cb975
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/archive/ArchiveAscii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char>(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<unsigned char>(view[spaces_count]));
++spaces_count);

if (spaces_count > 0) {
view.remove_prefix(spaces_count);
}

if (line != "[]") {
read->seek(static_cast<ssize_t>(mark), Whence::BEG);
return false;
if (view != "[]") {
read->seek(static_cast<ssize_t>(mark), Whence::BEG);
return false;
}

return true;
Expand Down

0 comments on commit e8cb975

Please sign in to comment.