/src/cpython/Objects/stringlib/partition.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* stringlib: partition implementation */ |
2 | | |
3 | | #ifndef STRINGLIB_FASTSEARCH_H |
4 | | # error must include "stringlib/fastsearch.h" before including this module |
5 | | #endif |
6 | | |
7 | | #if !STRINGLIB_MUTABLE && !defined(STRINGLIB_GET_EMPTY) |
8 | | # error "STRINGLIB_GET_EMPTY must be defined if STRINGLIB_MUTABLE is zero" |
9 | | #endif |
10 | | |
11 | | |
12 | | Py_LOCAL_INLINE(PyObject*) |
13 | | STRINGLIB(partition)(PyObject* str_obj, |
14 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
15 | | PyObject* sep_obj, |
16 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
17 | 6.29M | { |
18 | 6.29M | PyObject* out; |
19 | 6.29M | Py_ssize_t pos; |
20 | | |
21 | 6.29M | if (sep_len == 0) { |
22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
23 | 0 | return NULL; |
24 | 0 | } |
25 | | |
26 | 6.29M | out = PyTuple_New(3); |
27 | 6.29M | if (!out) |
28 | 0 | return NULL; |
29 | | |
30 | 6.29M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
31 | | |
32 | 6.29M | if (pos < 0) { |
33 | | #if STRINGLIB_MUTABLE |
34 | 0 | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); |
35 | 0 | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
36 | 0 | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); |
37 | | |
38 | 0 | if (PyErr_Occurred()) { |
39 | 0 | Py_DECREF(out); |
40 | 0 | return NULL; |
41 | 0 | } |
42 | | #else |
43 | 1.05M | Py_INCREF(str_obj); |
44 | 1.05M | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
45 | 1.05M | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); |
46 | | assert(empty != NULL); |
47 | 1.05M | Py_INCREF(empty); |
48 | 1.05M | PyTuple_SET_ITEM(out, 1, empty); |
49 | 1.05M | Py_INCREF(empty); |
50 | 1.05M | PyTuple_SET_ITEM(out, 2, empty); |
51 | | #endif |
52 | 0 | return out; |
53 | 1.05M | } |
54 | | |
55 | 5.24M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
56 | 5.24M | Py_INCREF(sep_obj); |
57 | 5.24M | PyTuple_SET_ITEM(out, 1, sep_obj); |
58 | 5.24M | pos += sep_len; |
59 | 5.24M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
60 | | |
61 | 5.24M | if (PyErr_Occurred()) { |
62 | 0 | Py_DECREF(out); |
63 | 0 | return NULL; |
64 | 0 | } |
65 | | |
66 | 5.24M | return out; |
67 | 5.24M | } Unexecuted instantiation: bytesobject.c:stringlib_partition unicodeobject.c:asciilib_partition Line | Count | Source | 17 | 2.16M | { | 18 | 2.16M | PyObject* out; | 19 | 2.16M | Py_ssize_t pos; | 20 | | | 21 | 2.16M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 2.16M | out = PyTuple_New(3); | 27 | 2.16M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 2.16M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 2.16M | if (pos < 0) { | 33 | | #if STRINGLIB_MUTABLE | 34 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); | 35 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 36 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); | 37 | | | 38 | | if (PyErr_Occurred()) { | 39 | | Py_DECREF(out); | 40 | | return NULL; | 41 | | } | 42 | | #else | 43 | 702k | Py_INCREF(str_obj); | 44 | 702k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 702k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 702k | assert(empty != NULL); | 47 | 702k | Py_INCREF(empty); | 48 | 702k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 702k | Py_INCREF(empty); | 50 | 702k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 702k | #endif | 52 | 702k | return out; | 53 | 702k | } | 54 | | | 55 | 1.45M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 1.45M | Py_INCREF(sep_obj); | 57 | 1.45M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 1.45M | pos += sep_len; | 59 | 1.45M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 1.45M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 1.45M | return out; | 67 | 1.45M | } |
unicodeobject.c:ucs1lib_partition Line | Count | Source | 17 | 4.05M | { | 18 | 4.05M | PyObject* out; | 19 | 4.05M | Py_ssize_t pos; | 20 | | | 21 | 4.05M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 4.05M | out = PyTuple_New(3); | 27 | 4.05M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 4.05M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 4.05M | if (pos < 0) { | 33 | | #if STRINGLIB_MUTABLE | 34 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); | 35 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 36 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); | 37 | | | 38 | | if (PyErr_Occurred()) { | 39 | | Py_DECREF(out); | 40 | | return NULL; | 41 | | } | 42 | | #else | 43 | 325k | Py_INCREF(str_obj); | 44 | 325k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 325k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 325k | assert(empty != NULL); | 47 | 325k | Py_INCREF(empty); | 48 | 325k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 325k | Py_INCREF(empty); | 50 | 325k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 325k | #endif | 52 | 325k | return out; | 53 | 325k | } | 54 | | | 55 | 3.72M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 3.72M | Py_INCREF(sep_obj); | 57 | 3.72M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 3.72M | pos += sep_len; | 59 | 3.72M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 3.72M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 3.72M | return out; | 67 | 3.72M | } |
unicodeobject.c:ucs2lib_partition Line | Count | Source | 17 | 68.2k | { | 18 | 68.2k | PyObject* out; | 19 | 68.2k | Py_ssize_t pos; | 20 | | | 21 | 68.2k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 68.2k | out = PyTuple_New(3); | 27 | 68.2k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 68.2k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 68.2k | if (pos < 0) { | 33 | | #if STRINGLIB_MUTABLE | 34 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); | 35 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 36 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); | 37 | | | 38 | | if (PyErr_Occurred()) { | 39 | | Py_DECREF(out); | 40 | | return NULL; | 41 | | } | 42 | | #else | 43 | 18.4k | Py_INCREF(str_obj); | 44 | 18.4k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 18.4k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 18.4k | assert(empty != NULL); | 47 | 18.4k | Py_INCREF(empty); | 48 | 18.4k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 18.4k | Py_INCREF(empty); | 50 | 18.4k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 18.4k | #endif | 52 | 18.4k | return out; | 53 | 18.4k | } | 54 | | | 55 | 49.8k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 49.8k | Py_INCREF(sep_obj); | 57 | 49.8k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 49.8k | pos += sep_len; | 59 | 49.8k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 49.8k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 49.8k | return out; | 67 | 49.8k | } |
unicodeobject.c:ucs4lib_partition Line | Count | Source | 17 | 9.23k | { | 18 | 9.23k | PyObject* out; | 19 | 9.23k | Py_ssize_t pos; | 20 | | | 21 | 9.23k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 9.23k | out = PyTuple_New(3); | 27 | 9.23k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 9.23k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 9.23k | if (pos < 0) { | 33 | | #if STRINGLIB_MUTABLE | 34 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); | 35 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 36 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); | 37 | | | 38 | | if (PyErr_Occurred()) { | 39 | | Py_DECREF(out); | 40 | | return NULL; | 41 | | } | 42 | | #else | 43 | 3.15k | Py_INCREF(str_obj); | 44 | 3.15k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 3.15k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 3.15k | assert(empty != NULL); | 47 | 3.15k | Py_INCREF(empty); | 48 | 3.15k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 3.15k | Py_INCREF(empty); | 50 | 3.15k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 3.15k | #endif | 52 | 3.15k | return out; | 53 | 3.15k | } | 54 | | | 55 | 6.07k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 6.07k | Py_INCREF(sep_obj); | 57 | 6.07k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 6.07k | pos += sep_len; | 59 | 6.07k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 6.07k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 6.07k | return out; | 67 | 6.07k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_partition |
68 | | |
69 | | Py_LOCAL_INLINE(PyObject*) |
70 | | STRINGLIB(rpartition)(PyObject* str_obj, |
71 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
72 | | PyObject* sep_obj, |
73 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
74 | 9.41k | { |
75 | 9.41k | PyObject* out; |
76 | 9.41k | Py_ssize_t pos; |
77 | | |
78 | 9.41k | if (sep_len == 0) { |
79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
80 | 0 | return NULL; |
81 | 0 | } |
82 | | |
83 | 9.41k | out = PyTuple_New(3); |
84 | 9.41k | if (!out) |
85 | 0 | return NULL; |
86 | | |
87 | 9.41k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
88 | | |
89 | 9.41k | if (pos < 0) { |
90 | | #if STRINGLIB_MUTABLE |
91 | 0 | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); |
92 | 0 | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
93 | 0 | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); |
94 | | |
95 | 0 | if (PyErr_Occurred()) { |
96 | 0 | Py_DECREF(out); |
97 | 0 | return NULL; |
98 | 0 | } |
99 | | #else |
100 | 2.18k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); |
101 | | assert(empty != NULL); |
102 | 2.18k | Py_INCREF(empty); |
103 | 2.18k | PyTuple_SET_ITEM(out, 0, empty); |
104 | 2.18k | Py_INCREF(empty); |
105 | 2.18k | PyTuple_SET_ITEM(out, 1, empty); |
106 | 2.18k | Py_INCREF(str_obj); |
107 | 2.18k | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); |
108 | | #endif |
109 | 0 | return out; |
110 | 2.18k | } |
111 | | |
112 | 7.22k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
113 | 7.22k | Py_INCREF(sep_obj); |
114 | 7.22k | PyTuple_SET_ITEM(out, 1, sep_obj); |
115 | 7.22k | pos += sep_len; |
116 | 7.22k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
117 | | |
118 | 7.22k | if (PyErr_Occurred()) { |
119 | 0 | Py_DECREF(out); |
120 | 0 | return NULL; |
121 | 0 | } |
122 | | |
123 | 7.22k | return out; |
124 | 7.22k | } Unexecuted instantiation: bytesobject.c:stringlib_rpartition unicodeobject.c:asciilib_rpartition Line | Count | Source | 74 | 9.41k | { | 75 | 9.41k | PyObject* out; | 76 | 9.41k | Py_ssize_t pos; | 77 | | | 78 | 9.41k | if (sep_len == 0) { | 79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 80 | 0 | return NULL; | 81 | 0 | } | 82 | | | 83 | 9.41k | out = PyTuple_New(3); | 84 | 9.41k | if (!out) | 85 | 0 | return NULL; | 86 | | | 87 | 9.41k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); | 88 | | | 89 | 9.41k | if (pos < 0) { | 90 | | #if STRINGLIB_MUTABLE | 91 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); | 92 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 93 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); | 94 | | | 95 | | if (PyErr_Occurred()) { | 96 | | Py_DECREF(out); | 97 | | return NULL; | 98 | | } | 99 | | #else | 100 | 2.18k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 101 | 2.18k | assert(empty != NULL); | 102 | 2.18k | Py_INCREF(empty); | 103 | 2.18k | PyTuple_SET_ITEM(out, 0, empty); | 104 | 2.18k | Py_INCREF(empty); | 105 | 2.18k | PyTuple_SET_ITEM(out, 1, empty); | 106 | 2.18k | Py_INCREF(str_obj); | 107 | 2.18k | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); | 108 | 2.18k | #endif | 109 | 2.18k | return out; | 110 | 2.18k | } | 111 | | | 112 | 7.22k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 113 | 7.22k | Py_INCREF(sep_obj); | 114 | 7.22k | PyTuple_SET_ITEM(out, 1, sep_obj); | 115 | 7.22k | pos += sep_len; | 116 | 7.22k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 117 | | | 118 | 7.22k | if (PyErr_Occurred()) { | 119 | 0 | Py_DECREF(out); | 120 | 0 | return NULL; | 121 | 0 | } | 122 | | | 123 | 7.22k | return out; | 124 | 7.22k | } |
Unexecuted instantiation: unicodeobject.c:ucs1lib_rpartition Unexecuted instantiation: unicodeobject.c:ucs2lib_rpartition Unexecuted instantiation: unicodeobject.c:ucs4lib_rpartition Unexecuted instantiation: bytearrayobject.c:stringlib_rpartition |
125 | | |