Optimize calls of utf8 in a few spots to avoid calling it more than once.

This commit is contained in:
Lukas Tenbrink
2025-01-07 17:24:21 +01:00
parent aa65940a85
commit 0fddf6a824
4 changed files with 13 additions and 12 deletions

View File

@ -311,18 +311,16 @@ bool FileAccessUnix::store_buffer(const uint8_t *p_src, uint64_t p_length) {
}
bool FileAccessUnix::file_exists(const String &p_path) {
int err;
struct stat st = {};
String filename = fix_path(p_path);
const CharString filename_utf8 = fix_path(p_path).utf8();
// Does the name exist at all?
err = stat(filename.utf8().get_data(), &st);
if (err) {
if (stat(filename_utf8.get_data(), &st)) {
return false;
}
// See if we have access to the file
if (access(filename.utf8().get_data(), F_OK)) {
if (access(filename_utf8.get_data(), F_OK)) {
return false;
}

View File

@ -67,10 +67,12 @@ Error FileAccessUnixPipe::open_internal(const String &p_path, int p_mode_flags)
ERR_FAIL_COND_V_MSG(fd[0] >= 0 || fd[1] >= 0, ERR_ALREADY_IN_USE, "Pipe is already in use.");
path = String("/tmp/") + p_path.replace("pipe://", "").replace("/", "_");
const CharString path_utf8 = path.utf8();
struct stat st = {};
int err = stat(path.utf8().get_data(), &st);
int err = stat(path_utf8.get_data(), &st);
if (err) {
if (mkfifo(path.utf8().get_data(), 0600) != 0) {
if (mkfifo(path_utf8.get_data(), 0600) != 0) {
last_error = ERR_FILE_CANT_OPEN;
return last_error;
}
@ -79,7 +81,7 @@ Error FileAccessUnixPipe::open_internal(const String &p_path, int p_mode_flags)
ERR_FAIL_COND_V_MSG(!S_ISFIFO(st.st_mode), ERR_ALREADY_IN_USE, "Pipe name is already used by file.");
}
int f = ::open(path.utf8().get_data(), O_RDWR | O_CLOEXEC | O_NONBLOCK);
int f = ::open(path_utf8.get_data(), O_RDWR | O_CLOEXEC | O_NONBLOCK);
if (f < 0) {
switch (errno) {
case ENOENT: {