Commit 92db64f1 authored by Stefan Behnel's avatar Stefan Behnel

moved C string decoding utility code from Optimize.c to StringTools.c

parent 646af4e4
...@@ -2712,7 +2712,7 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform): ...@@ -2712,7 +2712,7 @@ class OptimizeBuiltinCalls(Visitor.MethodDispatcherTransform):
node.pos, '__Pyx_%s' % utility_code_name, helper_func_type, node.pos, '__Pyx_%s' % utility_code_name, helper_func_type,
args = [string_node, start, stop, encoding_node, error_handling_node, decode_function], args = [string_node, start, stop, encoding_node, error_handling_node, decode_function],
is_temp = node.is_temp, is_temp = node.is_temp,
utility_code=UtilityCode.load_cached(utility_code_name, 'Optimize.c'), utility_code=UtilityCode.load_cached(utility_code_name, 'StringTools.c'),
) )
for temp in temps[::-1]: for temp in temps[::-1]:
......
...@@ -487,78 +487,3 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) { ...@@ -487,78 +487,3 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj) {
bad: bad:
return (double)-1; return (double)-1;
} }
/////////////// decode_cpp_string.proto ///////////////
#include <string>
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string(
std::string cppstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
/////////////// decode_cpp_string ///////////////
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string(
std::string cppstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
const char* cstring = cppstring.data();
Py_ssize_t length = cppstring.size();
if (unlikely(start < 0)) {
start += length;
if (unlikely(start < 0))
start = 0;
}
if (unlikely(stop < 0))
stop += length;
else if (stop >= length)
stop = length;
if (unlikely(start >= stop))
return PyUnicode_FromUnicode(NULL, 0);
cstring += start;
length = stop - start;
if (decode_func) {
return decode_func(cstring, length, errors);
} else {
return PyUnicode_Decode(cstring, length, encoding, errors);
}
}
/////////////// decode_c_string.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
/////////////// decode_c_string ///////////////
//@requires StringTools.c::IncludeStringH
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
Py_ssize_t length;
if (unlikely((start < 0) | (stop < 0))) {
length = strlen(cstring);
if (start < 0) {
start += length;
if (start < 0)
start = 0;
}
if (stop < 0)
stop += length;
}
length = stop - start;
if (unlikely(length <= 0))
return PyUnicode_FromUnicode(NULL, 0);
cstring += start;
if (decode_func) {
return decode_func(cstring, length, errors);
} else {
return PyUnicode_Decode(cstring, length, encoding, errors);
}
}
...@@ -223,3 +223,78 @@ static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring, ...@@ -223,3 +223,78 @@ static CYTHON_INLINE Py_UCS4 __Pyx_GetItemInt_Unicode_Generic(PyObject* ustring,
Py_DECREF(uchar_string); Py_DECREF(uchar_string);
return uchar; return uchar;
} }
/////////////// decode_cpp_string.proto ///////////////
#include <string>
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string(
std::string cppstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
/////////////// decode_cpp_string ///////////////
static CYTHON_INLINE PyObject* __Pyx_decode_cpp_string(
std::string cppstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
const char* cstring = cppstring.data();
Py_ssize_t length = cppstring.size();
if (unlikely(start < 0)) {
start += length;
if (unlikely(start < 0))
start = 0;
}
if (unlikely(stop < 0))
stop += length;
else if (stop >= length)
stop = length;
if (unlikely(start >= stop))
return PyUnicode_FromUnicode(NULL, 0);
cstring += start;
length = stop - start;
if (decode_func) {
return decode_func(cstring, length, errors);
} else {
return PyUnicode_Decode(cstring, length, encoding, errors);
}
}
/////////////// decode_c_string.proto ///////////////
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors));
/////////////// decode_c_string ///////////////
//@requires IncludeStringH
static CYTHON_INLINE PyObject* __Pyx_decode_c_string(
const char* cstring, Py_ssize_t start, Py_ssize_t stop,
const char* encoding, const char* errors,
PyObject* (*decode_func)(const char *s, Py_ssize_t size, const char *errors)) {
Py_ssize_t length;
if (unlikely((start < 0) | (stop < 0))) {
length = strlen(cstring);
if (start < 0) {
start += length;
if (start < 0)
start = 0;
}
if (stop < 0)
stop += length;
}
length = stop - start;
if (unlikely(length <= 0))
return PyUnicode_FromUnicode(NULL, 0);
cstring += start;
if (decode_func) {
return decode_func(cstring, length, errors);
} else {
return PyUnicode_Decode(cstring, length, encoding, errors);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment