Skip to content

Commit

Permalink
Simplify sorting new elements
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Apr 9, 2024
1 parent 49da29d commit 89ef242
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions core/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void DirectorySearch(const std::filesystem::path &path, const std::string_view e
{
namespace fs = std::filesystem;

const auto base = static_cast<std::make_signed_t<size_t>>(results->size());
const auto base = results->size();

try {
auto fpath = path.lexically_normal();
Expand All @@ -60,18 +60,10 @@ void DirectorySearch(const std::filesystem::path &path, const std::string_view e
ERR("Exception enumerating files: %s\n", e.what());
}

/* HACK: Without the size check this trips up range-checked iterators, as
* al::span uses al::to_address to get the first iterator's data pointer,
* which relies on operator->(), which can assert on end iterators. The
* check shouldn't be needed with C++20's std::span.
*/
if(static_cast<size_t>(base) < results->size())
{
const al::span newlist{results->begin()+base, results->end()};
std::sort(newlist.begin(), newlist.end());
for(const auto &name : newlist)
TRACE(" got %s\n", name.c_str());
}
const auto newlist = al::span{*results}.subspan(base);
std::sort(newlist.begin(), newlist.end());
for(const auto &name : newlist)
TRACE(" got %s\n", name.c_str());
}

} // namespace
Expand Down

0 comments on commit 89ef242

Please sign in to comment.