|
@@ -133,8 +133,9 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
|
{
|
|
{
|
|
// Long text!
|
|
// Long text!
|
|
// Perform manual coarse clipping to optimize for long multi-line text
|
|
// Perform manual coarse clipping to optimize for long multi-line text
|
|
- // From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
|
|
|
- // We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
|
|
|
|
|
|
+ // - From this point we will only compute the width of lines that are visible. Optimization only available when word-wrapping is disabled.
|
|
|
|
+ // - We also don't vertically center the text within the line full height, which is unlikely to matter because we are likely the biggest and only item on the line.
|
|
|
|
+ // - We use memchr(), pay attention that well optimized versions of those str/mem functions are much faster than a casually written loop.
|
|
const char* line = text;
|
|
const char* line = text;
|
|
const float line_height = GetTextLineHeight();
|
|
const float line_height = GetTextLineHeight();
|
|
const ImRect clip_rect = window->ClipRect;
|
|
const ImRect clip_rect = window->ClipRect;
|
|
@@ -153,7 +154,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
|
int lines_skipped = 0;
|
|
int lines_skipped = 0;
|
|
while (line < text_end && lines_skipped < lines_skippable)
|
|
while (line < text_end && lines_skipped < lines_skippable)
|
|
{
|
|
{
|
|
- const char* line_end = strchr(line, '\n');
|
|
|
|
|
|
+ const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
|
if (!line_end)
|
|
if (!line_end)
|
|
line_end = text_end;
|
|
line_end = text_end;
|
|
line = line_end + 1;
|
|
line = line_end + 1;
|
|
@@ -169,15 +170,15 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
|
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
|
ImRect line_rect(pos, pos + ImVec2(FLT_MAX, line_height));
|
|
while (line < text_end)
|
|
while (line < text_end)
|
|
{
|
|
{
|
|
- const char* line_end = strchr(line, '\n');
|
|
|
|
if (IsClippedEx(line_rect, 0, false))
|
|
if (IsClippedEx(line_rect, 0, false))
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
+ const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
|
|
|
+ if (!line_end)
|
|
|
|
+ line_end = text_end;
|
|
const ImVec2 line_size = CalcTextSize(line, line_end, false);
|
|
const ImVec2 line_size = CalcTextSize(line, line_end, false);
|
|
text_size.x = ImMax(text_size.x, line_size.x);
|
|
text_size.x = ImMax(text_size.x, line_size.x);
|
|
RenderText(pos, line, line_end, false);
|
|
RenderText(pos, line, line_end, false);
|
|
- if (!line_end)
|
|
|
|
- line_end = text_end;
|
|
|
|
line = line_end + 1;
|
|
line = line_end + 1;
|
|
line_rect.Min.y += line_height;
|
|
line_rect.Min.y += line_height;
|
|
line_rect.Max.y += line_height;
|
|
line_rect.Max.y += line_height;
|
|
@@ -188,7 +189,7 @@ void ImGui::TextUnformatted(const char* text, const char* text_end)
|
|
int lines_skipped = 0;
|
|
int lines_skipped = 0;
|
|
while (line < text_end)
|
|
while (line < text_end)
|
|
{
|
|
{
|
|
- const char* line_end = strchr(line, '\n');
|
|
|
|
|
|
+ const char* line_end = (const char*)memchr(line, '\n', text_end - line);
|
|
if (!line_end)
|
|
if (!line_end)
|
|
line_end = text_end;
|
|
line_end = text_end;
|
|
line = line_end + 1;
|
|
line = line_end + 1;
|