Refactor: BLF Offset from Cursor Position Early Exits #120673

Merged
Harley Acheson merged 1 commits from Harley/blender:BlfEarlyExits into main 2024-04-15 20:50:34 +02:00
1 changed files with 8 additions and 0 deletions

View File

@ -1024,10 +1024,18 @@ size_t blf_str_offset_from_cursor_position(FontBLF *font,
size_t str_len,
int location_x)
{
if (!str || !str[0] || !str_len) {
return 0;
}
CursorPositionForeachGlyph_Data data{};
data.location_x = location_x;
data.r_offset = size_t(-1);
/* For negative position, don't early exit with 0 but instead test as
* if it were zero. First glyph might not be from first character. */
location_x = std::max(location_x, 0);
Review

This does nothing, as the value has been assigned to data.location_x and is no longer used.

This does nothing, as the value has been assigned to `data.location_x` and is no longer used.
blf_font_boundbox_foreach_glyph(font, str, str_len, blf_cursor_position_foreach_glyph, &data);
if (data.r_offset == size_t(-1)) {