Reduce build graph by another eight percent

This commit is contained in:
Justine Tunney 2022-08-13 13:11:56 -07:00
parent 367d06d9e4
commit 0ea0d33a77
249 changed files with 889 additions and 988 deletions

View file

@ -1,47 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/str/str.h"
#include "libc/str/utf16.h"
/* TODO: DELETE */
/**
* Decodes UTF-16 character.
*
* @param s is a NUL-terminated string
* @return number of bytes (NUL counts as 1) or -1 w/ errno
* @note synchronization is performed to skip leading continuations;
* canonicalization and validation are performed to some extent
* @todo delete
*/
forcealignargpointer unsigned(getutf16)(const char16_t *p, wint_t *wc) {
unsigned skip = 0;
while (IsUtf16Cont(p[skip])) skip++;
if (IsUcs2(p[skip])) {
*wc = p[skip];
return skip + 1;
} else if (!IsUtf16Cont(p[skip + 1])) {
*wc = INVALID_CODEPOINT;
return -1;
} else {
*wc = MergeUtf16(p[skip], p[skip + 1]);
return skip + 2;
}
}

51
libc/str/oldutf16.internal.h Normal file → Executable file
View file

@ -1,51 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_STR_OLDUTF16_H_
#define COSMOPOLITAN_LIBC_STR_OLDUTF16_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
unsigned getutf16(const char16_t *, wint_t *);
int pututf16(char16_t *, size_t, wint_t, bool);
#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define pututf16(BUF, SIZE, CH, AWESOME) __pututf16(BUF, SIZE, CH, AWESOME)
#define getutf16(BUF, CHPTR) __getutf16(BUF, CHPTR)
forceinline int __pututf16(char16_t *s, size_t size, wint_t wc,
bool32 awesome) {
if (size >= 1 && (0x00 <= wc && wc <= 0xD7FF)) {
if (wc >= 32 || !awesome) {
s[0] = (char16_t)wc;
return 1;
} else if (size >= 2) {
s[0] = 0xd800;
s[1] = 0xdc00 | (char16_t)wc;
return 2;
}
}
int ax;
asm("call\tpututf16"
: "=a"(ax), "=m"(*(char(*)[size])s)
: "D"(s), "S"(size), "d"(wc)
: "cc");
return ax;
}
forceinline unsigned __getutf16(const char16_t *s, wint_t *wc) {
if ((0x00 <= s[0] && s[0] <= 0xD7FF)) {
*wc = s[0];
return 1;
}
unsigned ax;
asm("call\tgetutf16"
: "=a"(ax), "=m"(*wc)
: "D"(s), "S"(wc), "m"(*s), "m"(*(char(*)[4])s)
: "cc");
return ax;
}
#endif
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_OLDUTF16_H_ */

View file

@ -1,60 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
/* TODO(jart): DELETE */
/**
* Encodes character to string as UTF-16.
*
* Implementation Details: The header macro should ensure this function
* is only called for truly huge codepoints. Plus this function makes a
* promise to not clobber any registers but %rax.
*
* @param s is what ch gets encoded to
* @param size is the number of shorts available in s
* @param awesome enables numbers the IETF unilaterally banned
* @return number of shorts written or -1 w/ errno
* @todo delete
*/
int(pututf16)(char16_t *s, size_t size, wint_t wc, bool awesome) {
wint_t wc2;
if (size) {
if ((0 <= wc && wc < 32) && awesome && size >= 2) {
s[0] = 0xd800;
s[1] = 0xdc00 | wc;
return 2;
}
if ((0 <= wc && wc <= 0xD7FF) || (0xE000 <= wc && wc <= 0xFFFF)) {
s[0] = wc;
return 1;
} else if (0x10000 <= wc && wc <= 0x10FFFF && size >= 2) {
wc2 = wc - 0x10000;
s[0] = (wc2 >> 10) + 0xd800;
s[1] = (wc2 & 1023) + 0xdc00;
return 2;
} else {
s[0] = INVALID_CODEPOINT;
return -1;
}
} else {
return 0;
}
}

View file

@ -175,14 +175,6 @@ typedef unsigned mbstate_t;
axdx_t tprecode8to16(char16_t *, size_t, const char *);
axdx_t tprecode16to8(char *, size_t, const char16_t *);
int strcmp8to16(const char *, const char16_t *) strlenesque;
int strncmp8to16(const char *, const char16_t *, size_t) strlenesque;
int strcasecmp8to16(const char *, const char16_t *) strlenesque;
int strncasecmp8to16(const char *, const char16_t *, size_t) strlenesque;
int strcmp16to8(const char16_t *, const char *) strlenesque;
int strncmp16to8(const char16_t *, const char *, size_t) strlenesque;
int strcasecmp16to8(const char16_t *, const char *) strlenesque;
int strncasecmp16to8(const char16_t *, const char *, size_t) strlenesque;
wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t);
int mbtowc(wchar_t *, const char *, size_t);
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);

View file

@ -1,31 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/internal.h"
#include "libc/str/strcmp8to16i.internal.h"
/**
* Compares UTF-8 and UTF-16 strings, ignoring case.
*/
int strcasecmp8to16(const char *s1, const char16_t *s2) {
return strcmp8to16i(s1, s2, -1ul, towlower);
}
int strcasecmp16to8(const char16_t *s1, const char *s2) {
return -strcasecmp8to16(s2, s1);
}

View file

@ -1,35 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/str/internal.h"
#include "libc/str/strcmp8to16i.internal.h"
forceinline unsigned identity32u(unsigned x) {
return x;
}
/**
* Compares UTF-8 and UTF-16 strings.
*/
int strcmp8to16(const char *s1, const char16_t *s2) {
return strcmp8to16i(s1, s2, -1ul, identity32u);
}
int strcmp16to8(const char16_t *s1, const char *s2) {
return -strcmp8to16(s2, s1);
}

View file

@ -1,30 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_
#define COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_
#include "libc/fmt/conv.h"
#include "libc/macros.internal.h"
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.internal.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
forceinline int strcmp8to16i(const char *s1, const char16_t *s2, size_t n,
unsigned xlat(unsigned)) {
int res = 0;
if (n) {
do {
unsigned i, j;
wint_t wc1, wc2;
i = tpdecode(s1, &wc1);
j = getutf16(s2, &wc2);
s1 += ABS(i);
s2 += ABS(j);
if ((res = xlat(wc1) - xlat(wc2)) || !wc1) break;
} while (n == -1ul || --n);
}
return res;
}
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_STR_STRCMP8TO16I_H_ */

View file

@ -1,33 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/str/internal.h"
#include "libc/str/strcmp8to16i.internal.h"
/**
* Compares UTF-8 and UTF-16 strings, ignoring case, with limit.
*/
int strncasecmp8to16(const char *s1, const char16_t *s2, size_t n) {
assert(n != -1ul);
return strcmp8to16i(s1, s2, n, towlower);
}
int strncasecmp16to8(const char16_t *s1, const char *s2, size_t n) {
return -strncasecmp8to16(s2, s1, n);
}

View file

@ -1,37 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/str/internal.h"
#include "libc/str/strcmp8to16i.internal.h"
forceinline unsigned identity32u(unsigned x) {
return x;
}
/**
* Compares UTF-8 and UTF-16 strings, with limit.
*/
int strncmp8to16(const char *s1, const char16_t *s2, size_t n) {
assert(n != -1ul);
return strcmp8to16i(s1, s2, n, identity32u);
}
int strncmp16to8(const char16_t *s1, const char *s2, size_t n) {
return -strncmp8to16(s2, s1, n);
}

View file

@ -17,21 +17,28 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/safemacros.internal.h"
#include "libc/str/oldutf16.internal.h"
#include "libc/str/str.h"
#include "libc/str/unicode.h"
#include "libc/str/utf16.h"
/**
* Returns monospace display width of UTF-16 or UCS-2 string.
*/
int strnwidth16(const char16_t *p, size_t n, size_t o) {
size_t l;
wint_t wc;
wint_t x, y;
l = 0;
if (n) {
while (*p) {
p += getutf16(p, &wc);
l += max(0, wcwidth(wc));
while ((x = *p++)) {
if (!IsUcs2(x)) {
if ((y = *p++)) {
x = MergeUtf16(x, y);
} else {
++l;
break;
}
}
l += max(0, wcwidth(x));
}
}
return l;