Add MODE=optlinux build mode (#141)

This commit is contained in:
Justine Tunney 2021-10-14 19:36:49 -07:00
parent 226aaf3547
commit 67b5200a0b
111 changed files with 934 additions and 854 deletions

View file

@ -6,6 +6,7 @@
*/
#include "libc/bits/likely.h"
#include "libc/calls/calls.h"
#include "libc/log/countbranch.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/o.h"
#include "third_party/python/Include/abstract.h"
@ -1422,10 +1423,10 @@ PyDict_GetItem(PyObject *op, PyObject *key)
PyThreadState *tstate;
PyObject **value_addr;
if (!PyDict_Check(op))
if (UNLIKELY(!PyDict_Check(op)))
return NULL;
if (!PyUnicode_CheckExact(key) ||
(hash = ((PyASCIIObject *) key)->hash) == -1)
if (UNLIKELY(!PyUnicode_CheckExact(key)) ||
UNLIKELY((hash = ((PyASCIIObject *) key)->hash) == -1))
{
hash = PyObject_Hash(key);
if (hash == -1) {
@ -1440,7 +1441,7 @@ PyDict_GetItem(PyObject *op, PyObject *key)
_PyThreadState_Current and not PyThreadState_GET() because in debug
mode, the latter complains if tstate is NULL. */
tstate = _PyThreadState_UncheckedGet();
if (tstate != NULL && tstate->curexc_type != NULL) {
if (UNLIKELY(tstate != NULL && tstate->curexc_type != NULL)) {
/* preserve the existing exception */
PyObject *err_type, *err_value, *err_tb;
PyErr_Fetch(&err_type, &err_value, &err_tb);

View file

@ -4,6 +4,8 @@
Python 3
https://docs.python.org/3/license.html │
*/
#include "libc/bits/likely.h"
#include "libc/log/countbranch.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/bytearrayobject.h"
@ -1101,7 +1103,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
Py_ssize_t dictoffset;
PyObject **dictptr;
if (!PyUnicode_Check(name)){
if (UNLIKELY(!PyUnicode_Check(name))){
PyErr_Format(PyExc_TypeError,
"attribute name must be string, not '%.200s'",
name->ob_type->tp_name);
@ -1109,7 +1111,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
}
Py_INCREF(name);
if (tp->tp_dict == NULL) {
if (UNLIKELY(tp->tp_dict == NULL)) {
if (PyType_Ready(tp) < 0)
goto done;
}
@ -1126,7 +1128,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
}
}
if (dict == NULL) {
if (LIKELY(dict == NULL)) {
/* Inline _PyObject_GetDictPtr */
dictoffset = tp->tp_dictoffset;
if (dictoffset != 0) {
@ -1148,6 +1150,7 @@ _PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict)
dict = *dictptr;
}
}
if (dict != NULL) {
Py_INCREF(dict);
res = PyDict_GetItem(dict, name);

View file

@ -5,7 +5,9 @@
https://docs.python.org/3/license.html │
*/
#include "libc/assert.h"
#include "libc/bits/likely.h"
#include "libc/fmt/fmt.h"
#include "libc/log/countbranch.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
#include "third_party/python/Include/cellobject.h"
@ -2940,12 +2942,12 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
PyObject *mro, *res, *base, *dict;
unsigned int h;
if (MCACHE_CACHEABLE_NAME(name) &&
PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
if (LIKELY(MCACHE_CACHEABLE_NAME(name)) &&
LIKELY(PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))) {
/* fast path */
h = MCACHE_HASH_METHOD(type, name);
if (method_cache[h].version == type->tp_version_tag &&
method_cache[h].name == name) {
if (LIKELY(method_cache[h].version == type->tp_version_tag) &&
LIKELY(method_cache[h].name == name)) {
#if MCACHE_STATS
method_cache_hits++;
#endif
@ -2956,9 +2958,9 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
/* Look in tp_dict of types in MRO */
mro = type->tp_mro;
if (mro == NULL) {
if ((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
PyType_Ready(type) < 0) {
if (UNLIKELY(mro == NULL)) {
if (UNLIKELY((type->tp_flags & Py_TPFLAGS_READYING) == 0 &&
PyType_Ready(type) < 0)) {
/* It's not ideal to clear the error condition,
but this function is documented as not setting
an exception, and I don't want to change that.

View file

@ -10,6 +10,7 @@
#include "libc/bits/weaken.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/log/countbranch.h"
#include "libc/str/str.h"
#include "third_party/python/Include/abstract.h"
#include "third_party/python/Include/boolobject.h"
@ -3294,14 +3295,26 @@ PyUnicode_Decode(const char *s,
Py_buffer info;
char buflower[11]; /* strlen("iso-8859-1\0") == 11, longest shortcut */
if (encoding == NULL) {
if (UNLIKELY(encoding == NULL)) {
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
}
/* [jart] faster path based on profiling */
if (encoding[0] == 'l' &&
encoding[1] == 'a' &&
encoding[2] == 't' &&
encoding[3] == 'i' &&
encoding[4] == 'n' &&
(encoding[5] == '1' ||
((encoding[5] == '-' ||
encoding[5] == '_') &&
encoding[6] == '1'))) {
return PyUnicode_DecodeLatin1(s, size, errors);
}
/* Shortcuts for common default encodings */
if (_Py_normalize_encoding(encoding, buflower, sizeof(buflower))) {
char *lower = buflower;
/* Fast paths */
if (lower[0] == 'u' && lower[1] == 't' && lower[2] == 'f') {
lower += 3;
@ -3309,7 +3322,6 @@ PyUnicode_Decode(const char *s,
/* Match "utf8" and "utf_8" */
lower++;
}
if (lower[0] == '8' && lower[1] == 0) {
return PyUnicode_DecodeUTF8Stateful(s, size, errors, NULL);
}