diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-16 08:19:20 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-16 08:19:20 (GMT) |
commit | 3b73ea127892d0e1f9d8f12f88e4f9c0ba0b89b1 (patch) | |
tree | a1a58a83f9d60f7d5d02e5d116bb76ee13c42254 /Modules | |
parent | 21060105d99a9153db44dd88eb750965392fd966 (diff) | |
parent | f4934ea77da38516731a75fbf9458b248d26dd81 (diff) | |
download | cpython-3b73ea127892d0e1f9d8f12f88e4f9c0ba0b89b1.zip cpython-3b73ea127892d0e1f9d8f12f88e4f9c0ba0b89b1.tar.gz cpython-3b73ea127892d0e1f9d8f12f88e4f9c0ba0b89b1.tar.bz2 |
Issue #28701: Replace PyUnicode_CompareWithASCIIString with _PyUnicode_EqualToASCIIString.
The latter function is more readable, faster and doesn't raise exceptions.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_decimal/_decimal.c | 14 | ||||
-rw-r--r-- | Modules/_elementtree.c | 6 | ||||
-rw-r--r-- | Modules/_io/textio.c | 2 | ||||
-rw-r--r-- | Modules/_io/winconsoleio.c | 6 | ||||
-rw-r--r-- | Modules/_lsprof.c | 2 | ||||
-rw-r--r-- | Modules/_pickle.c | 2 | ||||
-rw-r--r-- | Modules/_sqlite/connection.c | 2 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 2 | ||||
-rw-r--r-- | Modules/pyexpat.c | 43 |
9 files changed, 39 insertions, 40 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c index fcc1f15..9956786 100644 --- a/Modules/_decimal/_decimal.c +++ b/Modules/_decimal/_decimal.c @@ -1118,12 +1118,12 @@ context_getattr(PyObject *self, PyObject *name) PyObject *retval; if (PyUnicode_Check(name)) { - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "traps")) { retval = ((PyDecContextObject *)self)->traps; Py_INCREF(retval); return retval; } - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "flags")) { retval = ((PyDecContextObject *)self)->flags; Py_INCREF(retval); return retval; @@ -1143,10 +1143,10 @@ context_setattr(PyObject *self, PyObject *name, PyObject *value) } if (PyUnicode_Check(name)) { - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "traps")) { return context_settraps_dict(self, value); } - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "flags")) { return context_setstatus_dict(self, value); } } @@ -2449,14 +2449,14 @@ dectuple_as_str(PyObject *dectuple) tmp = PyTuple_GET_ITEM(dectuple, 2); if (PyUnicode_Check(tmp)) { /* special */ - if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) { + if (_PyUnicode_EqualToASCIIString(tmp, "F")) { strcat(sign_special, "Inf"); is_infinite = 1; } - else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) { + else if (_PyUnicode_EqualToASCIIString(tmp, "n")) { strcat(sign_special, "NaN"); } - else if (PyUnicode_CompareWithASCIIString(tmp, "N") == 0) { + else if (_PyUnicode_EqualToASCIIString(tmp, "N")) { strcat(sign_special, "sNaN"); } else { diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 3362195..5937520 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -3661,11 +3661,11 @@ xmlparser_getattro(XMLParserObject* self, PyObject* nameobj) { if (PyUnicode_Check(nameobj)) { PyObject* res; - if (PyUnicode_CompareWithASCIIString(nameobj, "entity") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "entity")) res = self->entity; - else if (PyUnicode_CompareWithASCIIString(nameobj, "target") == 0) + else if (_PyUnicode_EqualToASCIIString(nameobj, "target")) res = self->target; - else if (PyUnicode_CompareWithASCIIString(nameobj, "version") == 0) { + else if (_PyUnicode_EqualToASCIIString(nameobj, "version")) { return PyUnicode_FromFormat( "Expat %d.%d.%d", XML_MAJOR_VERSION, XML_MINOR_VERSION, XML_MICRO_VERSION); diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index dca4ea9..2f55eb0 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1023,7 +1023,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, else if (PyUnicode_Check(res)) { const encodefuncentry *e = encodefuncs; while (e->name != NULL) { - if (!PyUnicode_CompareWithASCIIString(res, e->name)) { + if (_PyUnicode_EqualToASCIIString(res, e->name)) { self->encodefunc = e->encodefunc; break; } diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 4666a38..7b00a9e 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -93,11 +93,11 @@ char _PyIO_get_console_type(PyObject *path_or_fd) { } char m = '\0'; - if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONIN$") == 0) { + if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONIN$")) { m = 'r'; - } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CONOUT$") == 0) { + } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CONOUT$")) { m = 'w'; - } else if (PyUnicode_CompareWithASCIIString(decoded_upper, "CON") == 0) { + } else if (_PyUnicode_EqualToASCIIString(decoded_upper, "CON")) { m = 'x'; } diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index dc3f8ab..0e7623d 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -181,7 +181,7 @@ normalizeUserObj(PyObject *obj) } } if (modname != NULL) { - if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) { + if (!_PyUnicode_EqualToASCIIString(modname, "builtins")) { PyObject *result; result = PyUnicode_FromFormat("<%U.%s>", modname, fn->m_ml->ml_name); diff --git a/Modules/_pickle.c b/Modules/_pickle.c index fc16c63..54b1856 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1687,7 +1687,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) while (PyDict_Next(modules_dict, &i, &module_name, &module)) { PyObject *candidate; if (PyUnicode_Check(module_name) && - !PyUnicode_CompareWithASCIIString(module_name, "__main__")) + _PyUnicode_EqualToASCIIString(module_name, "__main__")) continue; if (module == Py_None) continue; diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 6210227..f37de42 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -1191,7 +1191,7 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py return -1; } for (candidate = begin_statements; *candidate; candidate++) { - if (!PyUnicode_CompareWithASCIIString(uppercase_level, *candidate + 6)) + if (_PyUnicode_EqualToASCIIString(uppercase_level, *candidate + 6)) break; } Py_DECREF(uppercase_level); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ecbec97..ecfc085 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -2329,7 +2329,7 @@ test_string_from_format(PyObject *self, PyObject *args) result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \ if (result == NULL) \ return NULL; \ - if (PyUnicode_CompareWithASCIIString(result, "1")) { \ + if (!_PyUnicode_EqualToASCIIString(result, "1")) { \ msg = FORMAT " failed at 1"; \ goto Fail; \ } \ diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index b19b7be..b3259d5 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1244,8 +1244,7 @@ handlername2int(PyObject *name) { int i; for (i = 0; handler_info[i].name != NULL; i++) { - if (PyUnicode_CompareWithASCIIString( - name, handler_info[i].name) == 0) { + if (_PyUnicode_EqualToASCIIString(name, handler_info[i].name)) { return i; } } @@ -1283,45 +1282,45 @@ xmlparse_getattro(xmlparseobject *self, PyObject *nameobj) first_char = PyUnicode_READ_CHAR(nameobj, 0); if (first_char == 'E') { - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorCode") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorCode")) return PyLong_FromLong((long) XML_GetErrorCode(self->itself)); - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorLineNumber") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorLineNumber")) return PyLong_FromLong((long) XML_GetErrorLineNumber(self->itself)); - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorColumnNumber") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorColumnNumber")) return PyLong_FromLong((long) XML_GetErrorColumnNumber(self->itself)); - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorByteIndex") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorByteIndex")) return PyLong_FromLong((long) XML_GetErrorByteIndex(self->itself)); } if (first_char == 'C') { - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentLineNumber") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentLineNumber")) return PyLong_FromLong((long) XML_GetCurrentLineNumber(self->itself)); - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentColumnNumber") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentColumnNumber")) return PyLong_FromLong((long) XML_GetCurrentColumnNumber(self->itself)); - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentByteIndex") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentByteIndex")) return PyLong_FromLong((long) XML_GetCurrentByteIndex(self->itself)); } if (first_char == 'b') { - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_size") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_size")) return PyLong_FromLong((long) self->buffer_size); - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_text") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_text")) return get_pybool(self->buffer != NULL); - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_used") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_used")) return PyLong_FromLong((long) self->buffer_used); } - if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "namespace_prefixes")) return get_pybool(self->ns_prefixes); - if (PyUnicode_CompareWithASCIIString(nameobj, "ordered_attributes") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "ordered_attributes")) return get_pybool(self->ordered_attributes); - if (PyUnicode_CompareWithASCIIString(nameobj, "specified_attributes") == 0) + if (_PyUnicode_EqualToASCIIString(nameobj, "specified_attributes")) return get_pybool((long) self->specified_attributes); - if (PyUnicode_CompareWithASCIIString(nameobj, "intern") == 0) { + if (_PyUnicode_EqualToASCIIString(nameobj, "intern")) { if (self->intern == NULL) { Py_INCREF(Py_None); return Py_None; @@ -1383,7 +1382,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute"); return -1; } - if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "buffer_text")) { int b = PyObject_IsTrue(v); if (b < 0) return -1; @@ -1405,7 +1404,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) } return 0; } - if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "namespace_prefixes")) { int b = PyObject_IsTrue(v); if (b < 0) return -1; @@ -1413,14 +1412,14 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); return 0; } - if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "ordered_attributes")) { int b = PyObject_IsTrue(v); if (b < 0) return -1; self->ordered_attributes = b; return 0; } - if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "specified_attributes")) { int b = PyObject_IsTrue(v); if (b < 0) return -1; @@ -1428,7 +1427,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) return 0; } - if (PyUnicode_CompareWithASCIIString(name, "buffer_size") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "buffer_size")) { long new_buffer_size; if (!PyLong_Check(v)) { PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer"); @@ -1474,7 +1473,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) return 0; } - if (PyUnicode_CompareWithASCIIString(name, "CharacterDataHandler") == 0) { + if (_PyUnicode_EqualToASCIIString(name, "CharacterDataHandler")) { /* If we're changing the character data handler, flush all * cached data with the old handler. Not sure there's a * "right" thing to do, though, but this probably won't |