CalcTextSize*() more optimisation, fast-path for ascii.

This commit is contained in:
ocornut 2015-02-11 12:31:04 +00:00
parent ea94835834
commit 183a27fd70

View File

@ -7530,8 +7530,12 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
const char* s = text; const char* s = text;
while (s < text_end) while (s < text_end)
{ {
unsigned int c; unsigned int c = (unsigned int)*s;
const char* next_s = s + ImTextCharFromUtf8(&c, s, text_end); const char* next_s;
if (c < 0x80)
next_s = s + 1;
else
next_s = s + ImTextCharFromUtf8(&c, s, text_end);
if (c == '\n') if (c == '\n')
{ {
@ -7631,7 +7635,10 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
} }
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
unsigned int c; unsigned int c = (unsigned int)*s;
if (c < 0x80)
s += 1;
else
s += ImTextCharFromUtf8(&c, s, text_end); s += ImTextCharFromUtf8(&c, s, text_end);
if (c == '\n') if (c == '\n')
@ -7760,7 +7767,10 @@ void ImFont::RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_re
} }
// Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte) // Decode and advance source (handle unlikely UTF-8 decoding failure by skipping to the next byte)
unsigned int c; unsigned int c = (unsigned int)*s;
if (c < 0x80)
s += 1;
else
s += ImTextCharFromUtf8(&c, s, text_end); s += ImTextCharFromUtf8(&c, s, text_end);
if (c == '\n') if (c == '\n')