Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 8, 2023
1 parent 48d5b68 commit c6ff282
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Sources/Shared/IO/AndroidAssetStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Death::IO
{
_type = Type::AndroidAsset;
_path = path;
OpenAsset(mode);
Open(mode);
}

AndroidAssetStream::~AndroidAssetStream()
Expand Down Expand Up @@ -228,7 +228,7 @@ namespace Death::IO
return AAssetDir_getNextFileName(assetDir);
}

void AndroidAssetStream::OpenAsset(FileAccessMode mode)
void AndroidAssetStream::Open(FileAccessMode mode)
{
#if defined(DEATH_USE_FILE_DESCRIPTORS)
// An asset file can only be read
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/IO/AndroidAssetStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace Death::IO
#endif
bool _shouldCloseOnDestruction;

void OpenAsset(FileAccessMode mode);
void Open(FileAccessMode mode);
};
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Shared/IO/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Death::IO
{
_type = Type::File;
_path = path;
OpenStream(mode);
Open(mode);
}

FileStream::~FileStream()
Expand Down Expand Up @@ -135,7 +135,7 @@ namespace Death::IO
#endif
}

void FileStream::OpenStream(FileAccessMode mode)
void FileStream::Open(FileAccessMode mode)
{
#if defined(DEATH_USE_FILE_DESCRIPTORS)
std::int32_t openFlag;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Shared/IO/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Death::IO
#endif
bool _shouldCloseOnDestruction;

void OpenStream(FileAccessMode mode);
void Open(FileAccessMode mode);
};

}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Shared/IO/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# include <sys/mman.h>
# include <sys/wait.h>
# endif
# if defined(DEATH_TARGET_APPLE) || defined(__FreeBSD__)
# if defined(DEATH_TARGET_APPLE)
# include <copyfile.h>
# elif defined(__linux__)
# include <sys/sendfile.h>
Expand Down Expand Up @@ -1671,22 +1671,22 @@ namespace Death::IO
return false;
}

# if defined(DEATH_TARGET_APPLE) || defined(__FreeBSD__)
# if defined(DEATH_TARGET_APPLE)
// fcopyfile works on FreeBSD and OS X 10.5+
bool success = (::fcopyfile(source, dest, 0, COPYFILE_ALL) == 0);
# elif defined(__linux__)
off_t offset = 0;
bool success = (::sendfile(dest, source, &offset, sb.st_size) == sb.st_size);
# else
# if !defined(DEATH_TARGET_SWITCH) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
# if !defined(DEATH_TARGET_SWITCH) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L
// As noted in https://eklitzke.org/efficient-file-copying-on-linux, might make the file reading faster
::posix_fadvise(source, 0, 0, POSIX_FADV_SEQUENTIAL);
# endif
# if defined(DEATH_TARGET_EMSCRIPTEN)
# endif
# if defined(DEATH_TARGET_EMSCRIPTEN)
constexpr std::size_t BufferSize = 8 * 1024;
# else
# else
constexpr std::size_t BufferSize = 128 * 1024;
# endif
# endif
char buffer[BufferSize];
std::size_t size = 0;
bool success = true;
Expand All @@ -1696,7 +1696,7 @@ namespace Death::IO
break;
}
}
#endif
# endif

::close(source);
::close(dest);
Expand Down
13 changes: 2 additions & 11 deletions Sources/nCine/Base/Algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,24 +342,15 @@ namespace nCine

inline void lowercaseInPlace(const Containers::MutableStringView string)
{
// According to https://twitter.com/MalwareMinigun/status/1087767603647377408, std::tolower() / std::toupper() causes
// a mutex lock and a virtual dispatch per character (!!). A proper Unicode-aware *and* locale-aware solution
// would involve far more than iterating over bytes anyway - multi-byte characters, composed characters
// (ä formed from ¨ and a), SS -> ß in German but not elsewhere etc...
for (char& c : string) {
if (c >= 'A' && c <= 'Z') {
c |= 0x20;
}
c += (std::uint8_t(c - 'A') < 26) << 5;
}
}

inline void uppercaseInPlace(const Containers::MutableStringView string)
{
// See above for why std::toupper() is banned here
for (char& c : string) {
if (c >= 'a' && c <= 'z') {
c &= ~0x20;
}
c -= (std::uint8_t(c - 'a') < 26) << 5;
}
}

Expand Down

0 comments on commit c6ff282

Please sign in to comment.