[sanitize] Micro-optimize ChainRule::sanitize

This commit is contained in:
Behdad Esfahbod committed 2023-07-08 12:33:58 -06:00
1 parent c650858c63
commit fb02f4a897
2 files changed
+22 -3

No files matched your search

+4 -3
View File
@@ -3086,11 +3086,12 @@ struct ChainRule
bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
if (!backtrack.len.sanitize (c)) return_trace (false);
/* Hyper-optimized sanitized because this is really hot. */
if (!c->check_point (&StructAfter<char> (backtrack.len))) return_trace (false);
const auto &input = StructAfter<decltype (inputX)> (backtrack);
if (!input.lenP1.sanitize (c)) return_trace (false);
if (!c->check_point (&StructAfter<char> (input.lenP1))) return_trace (false);
const auto &lookahead = StructAfter<decltype (lookaheadX)> (input);
if (!lookahead.len.sanitize (c)) return_trace (false);
if (!c->check_point (&StructAfter<char> (lookahead.len))) return_trace (false);
const auto &lookup = StructAfter<decltype (lookupX)> (lookahead);
return_trace (lookup.sanitize (c));
}
+18
View File
@@ -301,6 +301,24 @@ struct hb_sanitize_context_t :
return likely (ok);
}
#ifndef HB_OPTIMIZE_SIZE
HB_ALWAYS_INLINE
#endif
bool check_point (const void *base) const
{
const char *p = (const char *) base;
bool ok = (uintptr_t) (p - this->start) <= this->length;
DEBUG_MSG_LEVEL (SANITIZE, p, this->debug_depth+1, 0,
"check_point [%p]"
" in [%p..%p] -> %s",
p,
this->start, this->end,
ok ? "OK" : "OUT-OF-RANGE");
return likely (ok);
}
template <typename T>
bool check_range (const T *base,
unsigned int a,