Pārlūkot izejas kodu

[text] `TextFormat()` caching (#1015)

pull/1026/head
brankoku pirms 6 gadiem
committed by Ray
vecāks
revīzija
1f66f0d9a2
1 mainītis faili ar 9 papildinājumiem un 1 dzēšanām
  1. +9
    -1
      src/text.c

+ 9
- 1
src/text.c Parādīt failu

@ -1102,9 +1102,16 @@ unsigned int TextLength(const char *text)
}
// Formatting of text with variables to 'embed'
// WARNING: the string returned will expire after this function is called MAX_TEXT_BUFFERS times
const char *TextFormat(const char *text, ...)
{
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
#define MAX_TEXT_BUFFERS 8
// We create an array of buffers so strings don't expire until MAX_TEXT_BUFFERS invocations
static char cache[MAX_TEXT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
static int index = 0;
char *buffer = cache[index];
index += 1;
index %= MAX_TEXT_BUFFERS;
va_list args;
va_start(args, text);
@ -1112,6 +1119,7 @@ const char *TextFormat(const char *text, ...)
va_end(args);
return buffer;
#undef MAX_TEXT_BUFFERS
}
// Get a piece of a text string

Notiek ielāde…
Atcelt
Saglabāt