From b7cf9dbbecc83a02603bcdd6f0c0f5da62f66508 Mon Sep 17 00:00:00 2001 From: Jeff Baker Date: Sun, 25 May 2025 14:51:55 -0700 Subject: [PATCH] Hot path for ascii output --- src/utf8.c | 2 +- src/utf8.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/utf8.c b/src/utf8.c index da90b95a7..2daa010aa 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -328,7 +328,7 @@ int TY_(DecodeUTF8BytesToChar)( uint* c, uint firstByte, ctmbstr successorBytes, return 0; } -int TY_(EncodeCharToUTF8Bytes)( uint c, tmbstr encodebuf, +int TY_(EncodeCharToUTF8BytesSlow)( uint c, tmbstr encodebuf, TidyOutputSink* outp, int* count ) { byte tempbuf[10] = {0}; diff --git a/src/utf8.h b/src/utf8.h index 50664a5e0..c120397c8 100644 --- a/src/utf8.h +++ b/src/utf8.h @@ -18,9 +18,22 @@ TY_PRIVATE int TY_(DecodeUTF8BytesToChar)( uint* c, uint firstByte, ctmbstr successorBytes, TidyInputSource* inp, int* count ); -TY_PRIVATE int TY_(EncodeCharToUTF8Bytes)( uint c, tmbstr encodebuf, +TY_PRIVATE int TY_(EncodeCharToUTF8BytesSlow)( uint c, tmbstr encodebuf, TidyOutputSink* outp, int* count ); +static inline int TY_(EncodeCharToUTF8Bytes)(uint c, tmbstr encodebuf, + TidyOutputSink *outp, int *count) { + if (c <= 0x7F) { + if (encodebuf) + encodebuf[0] = c; + if (outp) + outp->putByte(outp->sinkData, c); + *count = 1; + return 0; + } + + TY_(EncodeCharToUTF8BytesSlow)(c, encodebuf, outp, count); +} TY_PRIVATE uint TY_(GetUTF8)( ctmbstr str, uint *ch ); TY_PRIVATE tmbstr TY_(PutUTF8)( tmbstr buf, uint c );