Skip to content

Commit e8779a6

Browse files
committed
Font: direct AddText()/RenderText() calls don't need to call strlen() if below clipping region.
Unlikely to meaningful affect anyone but still..
1 parent 4c2e7bb commit e8779a6

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

imgui_draw.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,7 @@ void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32
16691669
// Accept null ranges
16701670
if (text_begin == text_end || text_begin[0] == 0)
16711671
return;
1672-
if (text_end == NULL)
1673-
text_end = text_begin + strlen(text_begin);
1672+
// No need to strlen() here: font->RenderText() will do it and may early out.
16741673

16751674
// Pull default font/size from the shared ImDrawListSharedData instance
16761675
if (font == NULL)
@@ -1693,7 +1692,7 @@ void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32
16931692

16941693
void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end)
16951694
{
1696-
AddText(NULL, 0.0f, pos, col, text_begin, text_end);
1695+
AddText(_Data->Font, _Data->FontSize, pos, col, text_begin, text_end);
16971696
}
16981697

16991698
void ImDrawList::AddImage(ImTextureID user_texture_id, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col)
@@ -4125,15 +4124,15 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, Im
41254124
// Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound.
41264125
void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip)
41274126
{
4128-
if (!text_end)
4129-
text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
4130-
41314127
// Align to be pixel perfect
41324128
float x = IM_TRUNC(pos.x);
41334129
float y = IM_TRUNC(pos.y);
41344130
if (y > clip_rect.w)
41354131
return;
41364132

4133+
if (!text_end)
4134+
text_end = text_begin + strlen(text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls.
4135+
41374136
const float scale = size / FontSize;
41384137
const float line_height = FontSize * scale;
41394138
const float origin_x = x;

0 commit comments

Comments
 (0)