Skip to content

Commit

Permalink
Added a quick speedup to TTF_GetTextSubString() for ASCII text
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 3, 2024
1 parent e26295b commit b626c1f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/SDL_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4206,11 +4206,17 @@ bool SDLCALL TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *sub
return true;
}

// Do a binary search to find the cluster
// Make a quick guess that works for ASCII text with no line breaks
int num_clusters = text->internal->num_clusters;
const TTF_SubString *clusters = text->internal->clusters;
const TTF_SubString *closest = NULL;
const TTF_SubString *cluster = NULL;
if (offset < num_clusters && clusters[offset].offset == offset) {
SDL_copyp(substring, &clusters[offset]);
return true;
}

// Do a binary search to find the cluster
const TTF_SubString *closest = NULL;
int low = 0;
int high = num_clusters - 1;
while (low <= high) {
Expand Down

0 comments on commit b626c1f

Please sign in to comment.