Skip to content

Commit

Permalink
[#94] fix(ArchiveAscii): skip spaces without memory alloc
Browse files Browse the repository at this point in the history
* fix TODO - skip spaces without memory alloc

* fixup formatting

---------

Co-authored-by: Luis Michaelis <[email protected]>
  • Loading branch information
Domarion and lmichaelis authored Aug 2, 2024
1 parent f942cf2 commit 7121a33
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/archive/ArchiveAscii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ 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 != "[]") {
if (view != "[]") {
read->seek(static_cast<ssize_t>(mark), Whence::BEG);
return false;
}
Expand Down

0 comments on commit 7121a33

Please sign in to comment.