mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Actually implement String_UNSAFE_SubstringAt as a function instead of a macro on top of String_UNSAFE_Substring
This saves around 1ms when loading 431 fonts on my PC
This commit is contained in:
parent
9813402aee
commit
15079ee79f
@ -303,7 +303,7 @@ static void Commands_Execute(const String* input) {
|
||||
offset = 1;
|
||||
}
|
||||
|
||||
text = String_UNSAFE_Substring(&text, offset, text.length - offset);
|
||||
text = String_UNSAFE_SubstringAt(&text, offset);
|
||||
/* Check for only / or /client */
|
||||
if (!text.length) { Commands_PrintDefault(); return; }
|
||||
|
||||
|
10
src/String.c
10
src/String.c
@ -61,6 +61,16 @@ String String_UNSAFE_Substring(STRING_REF const String* str, int offset, int len
|
||||
return String_Init(str->buffer + offset, length, length);
|
||||
}
|
||||
|
||||
String String_UNSAFE_SubstringAt(STRING_REF const String* str, int offset) {
|
||||
String sub;
|
||||
if (offset < 0 || offset > str->length) Logger_Abort("Sub offset out of range");
|
||||
|
||||
sub.buffer = str->buffer + offset;
|
||||
sub.length = str->length - offset;
|
||||
sub.capacity = str->length - offset; /* str->length to match String_UNSAFE_Substring */
|
||||
return sub;
|
||||
}
|
||||
|
||||
int String_UNSAFE_Split(STRING_REF const String* str, char c, String* subs, int maxSubs) {
|
||||
int beg = 0, end, count, i;
|
||||
|
||||
|
@ -67,7 +67,8 @@ CC_API void String_CopyToRaw(char* dst, int capacity, const String* src);
|
||||
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
||||
CC_API String String_UNSAFE_Substring(STRING_REF const String* str, int offset, int length);
|
||||
/* UNSAFE: Returns a substring of the given string. (sub.buffer is within str.buffer + str.length) */
|
||||
#define String_UNSAFE_SubstringAt(str, offset) (String_UNSAFE_Substring(str, offset, (str)->length - (offset)))
|
||||
/* The substring returned is { str.buffer + offset, str.length - offset } */
|
||||
CC_API String String_UNSAFE_SubstringAt(STRING_REF const String* str, int offset);
|
||||
/* UNSAFE: Splits a string of the form [str1][c][str2][c][str3].. into substrings. */
|
||||
/* e.g., "abc:id:xyz" becomes "abc","id","xyz" */
|
||||
CC_API int String_UNSAFE_Split(STRING_REF const String* str, char c, String* subs, int maxSubs);
|
||||
|
Loading…
x
Reference in New Issue
Block a user