From c287cccfc727d21e37eef4ccb86bb98f307f8797 Mon Sep 17 00:00:00 2001 From: shibbo Date: Fri, 24 Jul 2020 00:16:50 -0400 Subject: [PATCH] Change compiler to emit some inlining, and start on some string utility functions --- compile.py | 2 +- include/al/util/StringUtil.h | 11 ++++ source/al/util/StringUtil.cpp | 99 +++++++++++++++++++++++++++++++++++ source/example.cpp | 6 --- 4 files changed, 111 insertions(+), 7 deletions(-) create mode 100644 include/al/util/StringUtil.h create mode 100644 source/al/util/StringUtil.cpp delete mode 100644 source/example.cpp diff --git a/compile.py b/compile.py index c2255a65..057677f0 100644 --- a/compile.py +++ b/compile.py @@ -16,7 +16,7 @@ includePath = root / "Include" libraryPath = root / "Libraries/NX-NXFP2-a64/Release" releasePath = root / "Common/Configs/Targets/NX-NXFP2-a64/Include" -compilerCommand = f"{compilerPath} -x c++ -std=gnu++14 -fno-common -fno-short-enums -ffunction-sections -fdata-sections -fPIC -Wall -O3 -fomit-frame-pointer -mcpu=cortex-a57+fp+simd+crypto+crc -g -DNN_NINTENDO_SDK -DNN_SDK_BUILD_RELEASE -I include -I {includePath} -I {releasePath} -c " +compilerCommand = f"{compilerPath} -x c++ -std=gnu++14 -fno-common -fno-inline -fno-short-enums -ffunction-sections -fdata-sections -fPIC -Wall -O3 -fomit-frame-pointer -mcpu=cortex-a57+fp+simd+crypto+crc -g -DNN_NINTENDO_SDK -DNN_SDK_BUILD_RELEASE -I include -I {includePath} -I {releasePath} -c " source_folder = pathlib.Path('source/') cpp_files = list(source_folder.rglob('*.cpp')) diff --git a/include/al/util/StringUtil.h b/include/al/util/StringUtil.h new file mode 100644 index 00000000..2ee391c7 --- /dev/null +++ b/include/al/util/StringUtil.h @@ -0,0 +1,11 @@ +#pragma once + +namespace al +{ + bool isEqualString(const char16_t *, const char16_t *); + bool isEqualSubString(const char *, const char *); + // isEqualSubString(const sead::SafeStringBase &, const sead::SafeStringBase &) + bool isStartWithString(const char *, const char *); + bool isEndWithString(const char *, const char *); + bool isEqualString(const char *, const char *); +}; \ No newline at end of file diff --git a/source/al/util/StringUtil.cpp b/source/al/util/StringUtil.cpp new file mode 100644 index 00000000..7cb8f70f --- /dev/null +++ b/source/al/util/StringUtil.cpp @@ -0,0 +1,99 @@ +#include "al/util/StringUtil.h" +#include + +namespace al +{ + bool isEqualString(const char16_t *pString_0, const char16_t *pString_1) + { + unsigned short val; + + while (1) + { + val = *pString_0; + if (val != *pString_1) + { + break; + } + + ++pString_1; + ++pString_0; + + if (!val) + { + return true; + } + } + + return false; + } + + bool isEqualSubString(const char *pString_0, const char *pString_1) + { + return strstr(pString_0, pString_1); + } + + bool isStartWithString(const char *pString_0, const char *pString_1) + { + char val = *pString_1; + + if (!*pString_1) + { + return true; + } + + const char* nextVal = pString_1 + 1; + + while(*pString_0 && *pString_0 == val) + { + char e = *nextVal++; + val = e; + ++pString_0; + + if (!e) + { + return true; + } + } + + return false; + } + + bool isEndWithString(const char *pString_0, const char *pString_1) + { + int pString0_Len = strlen(pString_0); + int pString1_Len = strlen(pString_1); + + if (pString0_Len < pString1_Len) + { + return false; + } + else + { + return isEqualString(&pString_0[pString0_Len - pString1_Len], pString_1); + } + } + + bool isEqualString(const char *pString_0, const char *pString_1) + { + char val; + + while (1) + { + val = *pString_0; + if (val != *pString_1) + { + break; + } + + ++pString_1; + ++pString_0; + + if (!val) + { + return true; + } + } + + return false; + } +}; \ No newline at end of file diff --git a/source/example.cpp b/source/example.cpp deleted file mode 100644 index 2d0d72f1..00000000 --- a/source/example.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int doStuff() -{ - return 0; -} \ No newline at end of file