[*] Micro path resolve optimizations
This commit is contained in:
parent
42325b08b8
commit
7c44d3a02c
@ -17,7 +17,7 @@ namespace Aurora::IO::FS
|
|||||||
return (c == '.') || (c == '!') || (c == '~') || (c == '?');
|
return (c == '.') || (c == '!') || (c == '~') || (c == '?');
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ResolveAbsolutePath(const AuString &path, AuString &result)
|
static void ResolveAbsolutePath(bool requireMountExpand, bool requireSanitization, const AuString &path, AuString &result)
|
||||||
{
|
{
|
||||||
AuString buffer;
|
AuString buffer;
|
||||||
bool isResource {};
|
bool isResource {};
|
||||||
@ -27,7 +27,7 @@ namespace Aurora::IO::FS
|
|||||||
/**
|
/**
|
||||||
Resolve special character prefixes
|
Resolve special character prefixes
|
||||||
*/
|
*/
|
||||||
if (path.size() > 2)
|
if ((path.size() > 2) && (requireMountExpand))
|
||||||
{
|
{
|
||||||
if (path[1] == kPathSplitter)
|
if (path[1] == kPathSplitter)
|
||||||
{
|
{
|
||||||
@ -68,59 +68,66 @@ namespace Aurora::IO::FS
|
|||||||
{
|
{
|
||||||
buffer += path;
|
buffer += path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
Quickly handle the edge case in some modern UNIX derived systems, and in
|
|
||||||
Windows UNC paths, where paths may start with '//' or '\\' respectively
|
|
||||||
*/
|
|
||||||
if (StartsWith(buffer, kDoublePathSplitter))
|
|
||||||
{
|
|
||||||
result += kDoublePathSplitter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (requireSanitization)
|
||||||
Technically, UTF-8 strings may contain the "NUL" byte.
|
{
|
||||||
|
/**
|
||||||
|
Quickly handle the edge case in some modern UNIX derived systems, and in
|
||||||
|
Windows UNC paths, where paths may start with '//' or '\\' respectively
|
||||||
|
*/
|
||||||
|
if (StartsWith(buffer, kDoublePathSplitter))
|
||||||
|
{
|
||||||
|
result += kDoublePathSplitter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Technically, UTF-8 strings may contain the "NUL" byte.
|
||||||
|
|
||||||
o Character numbers from U+0000 to U+007F (US-ASCII repertoire)
|
o Character numbers from U+0000 to U+007F (US-ASCII repertoire)
|
||||||
correspond to octets 00 to 7F (7 bit US-ASCII paths). A direct
|
correspond to octets 00 to 7F (7 bit US-ASCII paths). A direct
|
||||||
consequence is that a plain ASCII string is also a valid UTF-8
|
consequence is that a plain ASCII string is also a valid UTF-8
|
||||||
string.
|
string.
|
||||||
|
|
||||||
You know what would suck? If we were targeting an esoteric platform,
|
You know what would suck? If we were targeting an esoteric platform,
|
||||||
say a kernel, and we we're trying to avoid string exploits by potential
|
say a kernel, and we we're trying to avoid string exploits by potential
|
||||||
attackers. I'm sure that would never happen to poor anticheat devs.
|
attackers. I'm sure that would never happen to poor anticheat devs.
|
||||||
*/
|
*/
|
||||||
const auto parts = SplitString(buffer, AuString(1, kPathSplitter)); /// zzzz im going to FUCKING SLEEP
|
const auto parts = SplitString(buffer, AuString(1, kPathSplitter), true /*ignore empty tokens*/); /// zzzz im going to SLEEP
|
||||||
for (const auto &ch : parts) // can you tell why FIO shouldn't be in hot paths yet?
|
for (const auto &ch : parts) // can you tell why FIO shouldn't be in hot paths yet?
|
||||||
{
|
|
||||||
if (ch == "..")
|
|
||||||
{
|
{
|
||||||
auto i = result.size() - 1;
|
if (ch == "..")
|
||||||
while (i >= 0 && result[i] != kPathSplitter)
|
|
||||||
{
|
{
|
||||||
--i;
|
auto i = result.size() - 1;
|
||||||
}
|
while (i >= 0 && result[i] != kPathSplitter)
|
||||||
|
{
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
result.resize(i);
|
result.resize(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ch.size() == 1) && (IsMagicCharacter(ch[0])))
|
if ((ch.size() == 1) && (IsMagicCharacter(ch[0])))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += ch;
|
||||||
|
result += kPathSplitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
result += ch;
|
auto i = result.size() - 1;
|
||||||
result += kPathSplitter;
|
if (result[i] == kPathSplitter)
|
||||||
|
{
|
||||||
|
result.resize(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else // !requireSanitization
|
||||||
auto i = result.size() - 1;
|
|
||||||
if (result[i] == kPathSplitter)
|
|
||||||
{
|
{
|
||||||
result.resize(i);
|
result = buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isResource)
|
if (isResource)
|
||||||
@ -140,6 +147,7 @@ namespace Aurora::IO::FS
|
|||||||
void /* internal, local export */ _NormalizePath(AuString &str)
|
void /* internal, local export */ _NormalizePath(AuString &str)
|
||||||
{
|
{
|
||||||
bool requiresExpanding = false;
|
bool requiresExpanding = false;
|
||||||
|
bool requiresMountUpdate = false;
|
||||||
|
|
||||||
requiresExpanding = str.size() && IsMagicCharacter(str[0]);
|
requiresExpanding = str.size() && IsMagicCharacter(str[0]);
|
||||||
|
|
||||||
@ -179,16 +187,16 @@ namespace Aurora::IO::FS
|
|||||||
auto c = str[0];
|
auto c = str[0];
|
||||||
if ((c == '.') || (c == '~') || (c == '!') || (c == '?'))
|
if ((c == '.') || (c == '~') || (c == '!') || (c == '?'))
|
||||||
{
|
{
|
||||||
requiresExpanding = true;
|
requiresMountUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// worst case -> yea have fun
|
// worst case -> yea have fun
|
||||||
if (requiresExpanding)
|
if (requiresExpanding || requiresMountUpdate)
|
||||||
{
|
{
|
||||||
AuString temp;
|
AuString temp;
|
||||||
ResolveAbsolutePath(str, temp);
|
ResolveAbsolutePath(requiresMountUpdate, requiresExpanding, str, temp);
|
||||||
str = temp;
|
str = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ namespace Aurora::RNG
|
|||||||
AUKN_SYM void ReadFastRNG(void *in, AuUInt length)
|
AUKN_SYM void ReadFastRNG(void *in, AuUInt length)
|
||||||
{
|
{
|
||||||
// TODO: implement me
|
// TODO: implement me
|
||||||
return ReadSecureRNG(in, length);
|
ReadSecureRNG(in, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
|
Loading…
Reference in New Issue
Block a user