Add minor improvements and cleanup

This commit is contained in:
Justine Tunney 2020-10-27 03:39:46 -07:00
parent 9e3e985ae5
commit feed0d2b0e
163 changed files with 2286 additions and 2245 deletions

View file

@ -37,8 +37,8 @@ TEST(strclen, testAegeanNumberSupplementaryPlane) {
EXPECT_EQ(18, strlen16(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, wcslen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen("𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen16(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, wcslen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
}
TEST(strlen16, testCoolKidNulTerminator) {

View file

@ -19,25 +19,23 @@
*/
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#if 0
void *isnotplaintext(const void *, size_t)
__attribute__((__pure__, __leaf__, __nothrow__));
#endif
TEST(isnotplaintext, test) {
EXPECT_EQ(NULL, isnotplaintext(kHyperion, kHyperionSize));
EXPECT_STREQ("", isnotplaintext(kHyperion, kHyperionSize + 1));
TEST(strcpy, test) {
char buf[64];
EXPECT_STREQ("hello", strcpy(buf, "hello"));
EXPECT_STREQ("hello there what's up", strcpy(buf, "hello there what's up"));
}
char *doit(char *data, size_t size) {
data = isnotplaintext(data, size);
asm volatile("" : "+r"(data));
return data;
}
BENCH(isnotplaintext, bench) {
EZBENCH(donothing, doit(kHyperion, kHyperionSize));
BENCH(strcpy, bench) {
extern char *strcpy_(char *, const char *) asm("strcpy");
static char buf[1024], buf2[1024];
memset(buf2, -1, sizeof(buf2) - 1);
EZBENCH2("strcpy 1", donothing, strcpy_(buf, ""));
EZBENCH2("strcpy 2", donothing, strcpy_(buf, "1"));
EZBENCH2("strcpy 7", donothing, strcpy_(buf, "123456"));
EZBENCH2("strcpy 8", donothing, strcpy_(buf, "1234567"));
EZBENCH2("strcpy 9", donothing, strcpy_(buf, "12345678"));
EZBENCH2("strcpy 16", donothing, strcpy_(buf, "123456781234567"));
EZBENCH2("strcpy 1023", donothing, strcpy_(buf, buf2));
}

View file

@ -21,6 +21,7 @@
#include "libc/macros.h"
#include "libc/nexgen32e/tinystrlen.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
char u8[] = "utf-8 ☻";
@ -129,3 +130,16 @@ TEST(tinystrnlen16, test) {
EXPECT_EQ(2, tinystrnlen16(u"123", 2));
EXPECT_EQ(3, tinystrnlen16(u"123", 4));
}
BENCH(strlen, bench) {
extern size_t strlen_(const char *) asm("strlen");
static char b[1024];
memset(b, -1, sizeof(b) - 1);
EZBENCH2("strlen 1", donothing, strlen_(""));
EZBENCH2("strlen 2", donothing, strlen_("1"));
EZBENCH2("strlen 7", donothing, strlen_("123456"));
EZBENCH2("strlen 8", donothing, strlen_("1234567"));
EZBENCH2("strlen 9", donothing, strlen_("12345678"));
EZBENCH2("strlen 16", donothing, strlen_("123456781234567"));
EZBENCH2("strlen 1023", donothing, strlen_(b));
}