Commit 8a28f7b0 authored by Max Kellermann's avatar Max Kellermann

tag/FixString: add optimistic quick check

Optimizes a few nanoseconds from the common code path.
parent cc72ceb3
......@@ -24,6 +24,7 @@
#include "util/StringView.hxx"
#include "util/UTF8.hxx"
#include <algorithm>
#include <cassert>
#include <stdlib.h>
......@@ -115,9 +116,23 @@ clear_non_printable(StringView src)
return { dest, src.size };
}
gcc_pure
static bool
IsSafe(StringView s) noexcept
{
return std::all_of(s.begin(), s.end(),
[](char ch){
return IsASCII(ch) && IsPrintableASCII(ch);
});
}
WritableBuffer<char>
FixTagString(StringView p)
{
if (IsSafe(p))
/* optimistic optimization for the common case */
return nullptr;
auto utf8 = fix_utf8(p);
if (!utf8.IsNull())
p = {utf8.data, utf8.size};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment