moved GetItemInt_Unicode*() utility functions to StringTools.c
authorStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Jul 2012 19:37:06 +0000 (21:37 +0200)
committerStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Jul 2012 19:37:06 +0000 (21:37 +0200)
Cython/Compiler/ExprNodes.py
Cython/Utility/StringTools.c

index 9a4784c..f5d0cc1 100755 (executable)
@@ -3099,7 +3099,8 @@ class IndexNode(ExprNode):
                 assert self.index.type.is_int
                 index_code = self.index.result()
                 function = "__Pyx_GetItemInt_Unicode"
-                code.globalstate.use_utility_code(getitem_int_pyunicode_utility_code)
+                code.globalstate.use_utility_code(
+                    UtilityCode.load_cached("GetItemIntUnicode", "StringTools.c"))
                 code.putln(
                     "%s = %s(%s, %s%s); if (unlikely(%s == (Py_UCS4)-1)) %s;" % (
                         self.result(),
@@ -9931,49 +9932,6 @@ requires = [raise_unbound_local_error_utility_code])
 
 #------------------------------------------------------------------------------------
 
-getitem_int_pyunicode_utility_code = UtilityCode(
-proto = '''
-#define __Pyx_GetItemInt_Unicode(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \\
-                                               __Pyx_GetItemInt_Unicode_Fast(o, i) : \\
-                                               __Pyx_GetItemInt_Unicode_Generic(o, to_py_func(i)))
-
-static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i) {
-    Py_ssize_t length;
-#if CYTHON_PEP393_ENABLED
-    if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
-#endif
-    length = __Pyx_PyUnicode_GET_LENGTH(ustring);
-    if (likely((0 <= i) & (i < length))) {
-        return __Pyx_PyUnicode_READ_CHAR(ustring, i);
-    } else if ((-length <= i) & (i < 0)) {
-        return __Pyx_PyUnicode_READ_CHAR(ustring, i + length);
-    } else {
-        PyErr_SetString(PyExc_IndexError, "string index out of range");
-        return (Py_UCS4)-1;
-    }
-}
-
-static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring, PyObject* j) {
-    Py_UCS4 uchar;
-    PyObject *uchar_string;
-    if (!j) return (Py_UCS4)-1;
-    uchar_string = PyObject_GetItem(ustring, j);
-    Py_DECREF(j);
-    if (!uchar_string) return (Py_UCS4)-1;
-#if CYTHON_PEP393_ENABLED
-    if (unlikely(__Pyx_PyUnicode_READY(uchar_string) < 0)) {
-        Py_DECREF(uchar_string);
-        return (Py_UCS4)-1;
-    }
-#endif
-    uchar = __Pyx_PyUnicode_READ_CHAR(uchar_string, 0);
-    Py_DECREF(uchar_string);
-    return uchar;
-}
-''')
-
-#------------------------------------------------------------------------------------
-
 raise_too_many_values_to_unpack = UtilityCode.load_cached("RaiseTooManyValuesToUnpack", "ObjectHandling.c")
 raise_need_more_values_to_unpack = UtilityCode.load_cached("RaiseNeedMoreValuesToUnpack", "ObjectHandling.c")
 tuple_unpacking_error_code = UtilityCode.load_cached("UnpackTupleError", "ObjectHandling.c")
index 0c45f1b..21ebabe 100644 (file)
@@ -178,3 +178,48 @@ static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int eq
     }
 #endif
 }
+
+//////////////////// GetItemIntUnicode.proto ////////////////////
+
+#define __Pyx_GetItemInt_Unicode(o, i, size, to_py_func) (((size) <= sizeof(Py_ssize_t)) ? \
+                                               __Pyx_GetItemInt_Unicode_Fast(o, i) : \
+                                               __Pyx_GetItemInt_Unicode_Generic(o, to_py_func(i)))
+
+static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i);
+static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring, PyObject* j);
+
+//////////////////// GetItemIntUnicode ////////////////////
+
+static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Fast(PyObject* ustring, Py_ssize_t i) {
+    Py_ssize_t length;
+#if CYTHON_PEP393_ENABLED
+    if (unlikely(__Pyx_PyUnicode_READY(ustring) < 0)) return (Py_UCS4)-1;
+#endif
+    length = __Pyx_PyUnicode_GET_LENGTH(ustring);
+    if (likely((0 <= i) & (i < length))) {
+        return __Pyx_PyUnicode_READ_CHAR(ustring, i);
+    } else if ((-length <= i) & (i < 0)) {
+        return __Pyx_PyUnicode_READ_CHAR(ustring, i + length);
+    } else {
+        PyErr_SetString(PyExc_IndexError, "string index out of range");
+        return (Py_UCS4)-1;
+    }
+}
+
+static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring, PyObject* j) {
+    Py_UCS4 uchar;
+    PyObject *uchar_string;
+    if (!j) return (Py_UCS4)-1;
+    uchar_string = PyObject_GetItem(ustring, j);
+    Py_DECREF(j);
+    if (!uchar_string) return (Py_UCS4)-1;
+#if CYTHON_PEP393_ENABLED
+    if (unlikely(__Pyx_PyUnicode_READY(uchar_string) < 0)) {
+        Py_DECREF(uchar_string);
+        return (Py_UCS4)-1;
+    }
+#endif
+    uchar = __Pyx_PyUnicode_READ_CHAR(uchar_string, 0);
+    Py_DECREF(uchar_string);
+    return uchar;
+}