Skip to content

Commit

Permalink
Engine: even faster String.Chars[] variant for ASCII mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-mogilko committed Oct 30, 2023
1 parent 1ae98d9 commit 6cce9f8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Engine/ac/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,20 @@ int String_GetChars(const char *thisString, int index) {
auto &header = ScriptString::GetHeader((void*)thisString);
if ((index < 0) || (static_cast<uint32_t>(index) >= header.ULength))
return 0;
int off = (header.LastCharIdx <= index) ?
(uoffset(thisString + header.LastCharOff, index - header.LastCharIdx) + header.LastCharOff) :
uoffset(thisString, index);
int off;
if (get_uformat() == U_ASCII)
{
return thisString[index];
}
else if (header.LastCharIdx <= index)
{
off = uoffset(thisString + header.LastCharOff, index - header.LastCharIdx) + header.LastCharOff;
}
// TODO: support faster reverse iteration too? that would require reverse-dir uoffset
else
{
off = uoffset(thisString, index);
}
// NOTE: works up to 64k chars/bytes, then stops; this is intentional to save a bit of mem
if (off <= UINT16_MAX)
{
Expand Down

0 comments on commit 6cce9f8

Please sign in to comment.