tag/FixString: add optimistic quick check
Optimizes a few nanoseconds from the common code path.
This commit is contained in:
parent
cc72ceb368
commit
8a28f7b0a1
@ -24,6 +24,7 @@
|
|||||||
#include "util/StringView.hxx"
|
#include "util/StringView.hxx"
|
||||||
#include "util/UTF8.hxx"
|
#include "util/UTF8.hxx"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -115,9 +116,23 @@ clear_non_printable(StringView src)
|
|||||||
return { dest, src.size };
|
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>
|
WritableBuffer<char>
|
||||||
FixTagString(StringView p)
|
FixTagString(StringView p)
|
||||||
{
|
{
|
||||||
|
if (IsSafe(p))
|
||||||
|
/* optimistic optimization for the common case */
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
auto utf8 = fix_utf8(p);
|
auto utf8 = fix_utf8(p);
|
||||||
if (!utf8.IsNull())
|
if (!utf8.IsNull())
|
||||||
p = {utf8.data, utf8.size};
|
p = {utf8.data, utf8.size};
|
||||||
|
Loading…
Reference in New Issue
Block a user