Give Emacs another performance boost

This commit is contained in:
Justine Tunney 2023-08-18 09:34:14 -07:00
parent 5b42c810a5
commit 9c7b81ee0f
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
30 changed files with 253 additions and 102 deletions

View file

@ -19,7 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/intrin/_getauxval.internal.h"
#include "libc/intrin/getauxval.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/sysv/consts/auxv.h"
@ -36,7 +36,7 @@
int issetugid(void) {
int rc;
if (IsLinux()) {
rc = !!_getauxval(AT_SECURE).value;
rc = !!__getauxval(AT_SECURE).value;
} else if (IsMetal()) {
rc = 0;
} else {

View file

@ -18,8 +18,8 @@
*/
#include "libc/calls/ntspawn.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/alloca.h"
#include "libc/mem/arraylist2.internal.h"
@ -154,7 +154,7 @@ textwindows int mkntenvblock(char16_t envvars[ARG_MAX / 2], char *const envp[],
if (!have_systemroot && environ) {
// https://jpassing.com/2009/12/28/the-hidden-danger-of-forgetting-to-specify-systemroot-in-a-custom-environment-block/
struct Env systemroot;
systemroot = _getenv(environ, "SYSTEMROOT");
systemroot = __getenv(environ, "SYSTEMROOT");
if (systemroot.s) {
InsertString(vars, n++, environ[systemroot.i], buf, &bufi,
&have_systemroot);

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/_getauxval.internal.h"
#include "libc/intrin/getauxval.internal.h"
#include "libc/runtime/runtime.h"
/**
@ -28,7 +28,7 @@
* @see System Five Application Binary Interface § 3.4.3
* @asyncsignalsafe
*/
dontasan struct AuxiliaryValue _getauxval(unsigned long at) {
dontasan struct AuxiliaryValue __getauxval(unsigned long at) {
unsigned long *ap;
for (ap = __auxv; ap[0]; ap += 2) {
if (at == ap[0]) {

View file

@ -17,12 +17,12 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/getenv.internal.h"
#define ToUpper(c) \
(IsWindows() && (c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
struct Env _getenv(char **p, const char *k) {
dontasan struct Env __getenv(char **p, const char *k) {
char *t;
int i, j;
for (i = 0; (t = p[i]); ++i) {

View file

@ -1,15 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_
#define COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct AuxiliaryValue {
unsigned long value;
bool isfound;
};
struct AuxiliaryValue _getauxval(unsigned long);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_INTERNAL_H_ */

View file

@ -1,15 +0,0 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN__GETENV_INTERNAL_H_
#define COSMOPOLITAN_LIBC_INTRIN__GETENV_INTERNAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct Env {
char *s;
int i;
};
struct Env _getenv(char **, const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN__GETENV_INTERNAL_H_ */

View file

@ -19,9 +19,9 @@
#include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/ttydefaults.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/extend.internal.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/nomultics.internal.h"
#include "libc/intrin/pushpop.internal.h"
@ -95,7 +95,7 @@ textstartup void __init_fds(int argc, char **argv, char **envp) {
} else if (IsWindows()) {
int sockset = 0;
struct Env var;
var = _getenv(envp, "__STDIO_SOCKETS");
var = __getenv(envp, "__STDIO_SOCKETS");
if (var.s) {
int i = var.i + 1;
do {

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/intrin/_getauxval.internal.h"
#include "libc/intrin/getauxval.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"
@ -32,7 +32,7 @@
*/
unsigned long getauxval(unsigned long key) {
struct AuxiliaryValue x;
x = _getauxval(key);
x = __getauxval(key);
if (key == AT_PAGESZ) {
if (!x.isfound) {
#ifdef __aarch64__

View file

@ -0,0 +1,15 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_H_
#define COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct AuxiliaryValue {
unsigned long value;
bool isfound;
};
struct AuxiliaryValue __getauxval(unsigned long);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_GETAUXVAL_H_ */

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/runtime/runtime.h"
@ -33,7 +33,7 @@ char *getenv(const char *s) {
struct Env e;
if (!s) return 0;
if (!(p = environ)) return 0;
e = _getenv(p, s);
e = __getenv(p, s);
#if SYSDEBUG
// if (!(s[0] == 'T' && s[1] == 'Z' && !s[2])) {
// TODO(jart): memoize TZ or something

View file

@ -0,0 +1,15 @@
#ifndef COSMOPOLITAN_LIBC_INTRIN_GETENV_H_
#define COSMOPOLITAN_LIBC_INTRIN_GETENV_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
struct Env {
char *s;
int i;
};
struct Env __getenv(char **, const char *);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_GETENV_H_ */

View file

@ -20,6 +20,7 @@
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/promises.internal.h"
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
@ -45,7 +46,7 @@ int IsDebuggerPresent(bool force) {
int e, fd, res;
char *p, buf[1024];
if (!force && IsGenuineBlink()) return 0;
if (!force && __getenv(environ, "HEISENDEBUG")) return 0;
if (!force && __getenv(environ, "HEISENDEBUG").s) return 0;
if (IsWindows()) return IsBeingDebugged();
if (__isworker) return false;
if (!PLEDGED(RPATH)) return false;

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/kmalloc.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
@ -63,7 +63,7 @@ int PutEnvImpl(char *s, bool overwrite) {
return -1;
}
}
e = _getenv(p, s);
e = __getenv(p, s);
if (e.s && !overwrite) {
return 0;
}

View file

@ -16,7 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/_getauxval.internal.h"
#include "libc/intrin/getauxval.internal.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
@ -54,7 +54,7 @@ uint64_t _rand64(void) {
s = g_rand64.thepool; // normal path
} else {
if (!g_rand64.thepid) {
if (AT_RANDOM && (p = (void *)_getauxval(AT_RANDOM).value)) {
if (AT_RANDOM && (p = (void *)__getauxval(AT_RANDOM).value)) {
// linux / freebsd kernel supplied entropy
memcpy(&s, p, 16);
} else {

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/errfuns.h"
@ -36,7 +36,7 @@ int unsetenv(const char *s) {
if (*t == '=') return einval();
}
if ((p = environ)) {
e = _getenv(p, s);
e = __getenv(p, s);
while (p[e.i]) {
p[e.i] = p[e.i + 1];
++e.i;

View file

@ -9,8 +9,6 @@
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define __ToUpper(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
__funline int __strcmp(const char *l, const char *r) {
size_t i = 0;
while (l[i] == r[i] && r[i]) ++i;
@ -132,26 +130,6 @@ __funline char16_t *__strstr16(const char16_t *haystack,
return 0;
}
__funline char *__getenv(char **p, const char *s) {
size_t i, j;
if (p) {
for (i = 0; p[i]; ++i) {
for (j = 0;; ++j) {
if (!s[j]) {
if (p[i][j] == '=') {
return p[i] + j + 1;
}
break;
}
if ((s[j] & 255) != __ToUpper(p[i][j] & 255)) {
break;
}
}
}
}
return 0;
}
__funline const char *__strchr(const char *s, unsigned char c) {
char *r;
for (;; ++s) {

View file

@ -20,7 +20,7 @@
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/_getauxval.internal.h"
#include "libc/intrin/getauxval.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"
@ -55,7 +55,7 @@ static dontinline int __clk_tck_init(void) {
x = -1;
}
} else {
x = _getauxval(AT_CLKTCK).value;
x = __getauxval(AT_CLKTCK).value;
}
if (x < 1) x = 100;
clk_tck = x;

View file

@ -25,8 +25,8 @@
#include "libc/fmt/conv.h"
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/intrin/_getenv.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
@ -120,7 +120,7 @@ static int GetSignalByName(const char *s) {
static void PutEnv(char **p, const char *kv) {
struct Env e;
e = _getenv(p, kv);
e = __getenv(p, kv);
p[e.i] = kv;
if (!e.s) p[e.i + 1] = 0;
}
@ -128,7 +128,7 @@ static void PutEnv(char **p, const char *kv) {
static void UnsetEnv(char **p, const char *k) {
int i;
struct Env e;
if ((e = _getenv(p, k)).s) {
if ((e = __getenv(p, k)).s) {
p[e.i] = 0;
for (i = e.i + 1; p[i]; ++i) {
p[i - 1] = p[i];
@ -399,7 +399,7 @@ static int Read(void) {
static int Cd(void) {
const char *s;
if ((s = n > 1 ? args[1] : _getenv(envs, "HOME").s)) {
if ((s = n > 1 ? args[1] : __getenv(envs, "HOME").s)) {
if (!chdir(s)) {
return 0;
} else {
@ -776,7 +776,7 @@ static const char *GetVar(const char *key) {
FormatInt32(vbuf, geteuid());
return vbuf;
} else {
return _getenv(envs, key).s;
return __getenv(envs, key).s;
}
}

View file

@ -16,10 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/dce.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/getenv.internal.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/libfatal.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
@ -30,7 +28,7 @@
textstartup int __strace_init(int argc, char **argv, char **envp, long *auxv) {
/* asan isn't initialized yet at runlevel 300 */
if (__intercept_flag(&argc, argv, "--strace") ||
__atoul(nulltoempty(__getenv(envp, "STRACE")))) {
__atoul(nulltoempty(__getenv(envp, "STRACE").s))) {
strace_enabled(+1);
}
return (__argc = argc);