summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2018-04-27 21:26:16 +0900
committerDavid Lord <davidism@gmail.com>2018-05-04 08:07:32 -0700
commit2f931bd8b101c572a431255d35efcf2c177e1630 (patch)
tree0024f3765feeeb29b0791a70d5601ee1856b519e
parenta03ecd5efc3d5a2d12a3bc72d7ce9e776cccfc66 (diff)
downloadmarkupsafe-2f931bd8b101c572a431255d35efcf2c177e1630.tar.gz
Use interned '__html__'
-rw-r--r--markupsafe/_speedups.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/markupsafe/_speedups.c b/markupsafe/_speedups.c
index 8362490..22a604d 100644
--- a/markupsafe/_speedups.c
+++ b/markupsafe/_speedups.c
@@ -283,8 +283,20 @@ escape_unicode(PyUnicodeObject *in)
static PyObject*
escape(PyObject *self, PyObject *text)
{
+ static PyObject *id_html;
PyObject *s = NULL, *rv = NULL, *html;
+ if (id_html == NULL) {
+#if PY_MAJOR_VERSION < 3
+ id_html = PyString_InternFromString("__html__");
+#else
+ id_html = PyUnicode_InternFromString("__html__");
+#endif
+ if (id_html == NULL) {
+ return NULL;
+ }
+ }
+
/* we don't have to escape integers, bools or floats */
if (PyLong_CheckExact(text) ||
#if PY_MAJOR_VERSION < 3
@@ -295,7 +307,7 @@ escape(PyObject *self, PyObject *text)
return PyObject_CallFunctionObjArgs(markup, text, NULL);
/* if the object has an __html__ method that performs the escaping */
- html = PyObject_GetAttrString(text, "__html__");
+ html = PyObject_GetAttr(text ,id_html);
if (html) {
s = PyObject_CallObject(html, NULL);
Py_DECREF(html);