/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.11M | { |
18 | 6.11M | PyObject* out; |
19 | 6.11M | Py_ssize_t pos; |
20 | | |
21 | 6.11M | if (sep_len == 0) { |
22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
23 | 0 | return NULL; |
24 | 0 | } |
25 | | |
26 | 6.11M | out = PyTuple_New(3); |
27 | 6.11M | if (!out) |
28 | 0 | return NULL; |
29 | | |
30 | 6.11M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
31 | | |
32 | 6.11M | 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 | 945k | Py_INCREF(str_obj); |
44 | 945k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
45 | 945k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); |
46 | | assert(empty != NULL); |
47 | 945k | Py_INCREF(empty); |
48 | 945k | PyTuple_SET_ITEM(out, 1, empty); |
49 | 945k | Py_INCREF(empty); |
50 | 945k | PyTuple_SET_ITEM(out, 2, empty); |
51 | | #endif |
52 | 0 | return out; |
53 | 945k | } |
54 | | |
55 | 5.17M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
56 | 5.17M | Py_INCREF(sep_obj); |
57 | 5.17M | PyTuple_SET_ITEM(out, 1, sep_obj); |
58 | 5.17M | pos += sep_len; |
59 | 5.17M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
60 | | |
61 | 5.17M | if (PyErr_Occurred()) { |
62 | 0 | Py_DECREF(out); |
63 | 0 | return NULL; |
64 | 0 | } |
65 | | |
66 | 5.17M | return out; |
67 | 5.17M | } Unexecuted instantiation: bytesobject.c:stringlib_partition unicodeobject.c:asciilib_partition Line | Count | Source | 17 | 2.03M | { | 18 | 2.03M | PyObject* out; | 19 | 2.03M | Py_ssize_t pos; | 20 | | | 21 | 2.03M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 2.03M | out = PyTuple_New(3); | 27 | 2.03M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 2.03M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 2.03M | 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 | 675k | Py_INCREF(str_obj); | 44 | 675k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 675k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 675k | assert(empty != NULL); | 47 | 675k | Py_INCREF(empty); | 48 | 675k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 675k | Py_INCREF(empty); | 50 | 675k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 675k | #endif | 52 | 675k | return out; | 53 | 675k | } | 54 | | | 55 | 1.35M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 1.35M | Py_INCREF(sep_obj); | 57 | 1.35M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 1.35M | pos += sep_len; | 59 | 1.35M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 1.35M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 1.35M | return out; | 67 | 1.35M | } |
unicodeobject.c:ucs1lib_partition Line | Count | Source | 17 | 4.00M | { | 18 | 4.00M | PyObject* out; | 19 | 4.00M | Py_ssize_t pos; | 20 | | | 21 | 4.00M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 4.00M | out = PyTuple_New(3); | 27 | 4.00M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 4.00M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 4.00M | 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 | 249k | Py_INCREF(str_obj); | 44 | 249k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 249k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 249k | assert(empty != NULL); | 47 | 249k | Py_INCREF(empty); | 48 | 249k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 249k | Py_INCREF(empty); | 50 | 249k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 249k | #endif | 52 | 249k | return out; | 53 | 249k | } | 54 | | | 55 | 3.75M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 3.75M | Py_INCREF(sep_obj); | 57 | 3.75M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 3.75M | pos += sep_len; | 59 | 3.75M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 3.75M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 3.75M | return out; | 67 | 3.75M | } |
unicodeobject.c:ucs2lib_partition Line | Count | Source | 17 | 66.4k | { | 18 | 66.4k | PyObject* out; | 19 | 66.4k | Py_ssize_t pos; | 20 | | | 21 | 66.4k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 66.4k | out = PyTuple_New(3); | 27 | 66.4k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 66.4k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 66.4k | 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 | 17.0k | Py_INCREF(str_obj); | 44 | 17.0k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 17.0k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 17.0k | assert(empty != NULL); | 47 | 17.0k | Py_INCREF(empty); | 48 | 17.0k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 17.0k | Py_INCREF(empty); | 50 | 17.0k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 17.0k | #endif | 52 | 17.0k | return out; | 53 | 17.0k | } | 54 | | | 55 | 49.3k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 49.3k | Py_INCREF(sep_obj); | 57 | 49.3k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 49.3k | pos += sep_len; | 59 | 49.3k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 49.3k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 49.3k | return out; | 67 | 49.3k | } |
unicodeobject.c:ucs4lib_partition Line | Count | Source | 17 | 8.77k | { | 18 | 8.77k | PyObject* out; | 19 | 8.77k | Py_ssize_t pos; | 20 | | | 21 | 8.77k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 8.77k | out = PyTuple_New(3); | 27 | 8.77k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 8.77k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 8.77k | 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.47k | Py_INCREF(str_obj); | 44 | 3.47k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 3.47k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 3.47k | assert(empty != NULL); | 47 | 3.47k | Py_INCREF(empty); | 48 | 3.47k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 3.47k | Py_INCREF(empty); | 50 | 3.47k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 3.47k | #endif | 52 | 3.47k | return out; | 53 | 3.47k | } | 54 | | | 55 | 5.30k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 5.30k | Py_INCREF(sep_obj); | 57 | 5.30k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 5.30k | pos += sep_len; | 59 | 5.30k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 5.30k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 5.30k | return out; | 67 | 5.30k | } |
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.02k | { |
75 | 9.02k | PyObject* out; |
76 | 9.02k | Py_ssize_t pos; |
77 | | |
78 | 9.02k | if (sep_len == 0) { |
79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
80 | 0 | return NULL; |
81 | 0 | } |
82 | | |
83 | 9.02k | out = PyTuple_New(3); |
84 | 9.02k | if (!out) |
85 | 0 | return NULL; |
86 | | |
87 | 9.02k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
88 | | |
89 | 9.02k | 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.08k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); |
101 | | assert(empty != NULL); |
102 | 2.08k | Py_INCREF(empty); |
103 | 2.08k | PyTuple_SET_ITEM(out, 0, empty); |
104 | 2.08k | Py_INCREF(empty); |
105 | 2.08k | PyTuple_SET_ITEM(out, 1, empty); |
106 | 2.08k | Py_INCREF(str_obj); |
107 | 2.08k | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); |
108 | | #endif |
109 | 0 | return out; |
110 | 2.08k | } |
111 | | |
112 | 6.94k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
113 | 6.94k | Py_INCREF(sep_obj); |
114 | 6.94k | PyTuple_SET_ITEM(out, 1, sep_obj); |
115 | 6.94k | pos += sep_len; |
116 | 6.94k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
117 | | |
118 | 6.94k | if (PyErr_Occurred()) { |
119 | 0 | Py_DECREF(out); |
120 | 0 | return NULL; |
121 | 0 | } |
122 | | |
123 | 6.94k | return out; |
124 | 6.94k | } Unexecuted instantiation: bytesobject.c:stringlib_rpartition unicodeobject.c:asciilib_rpartition Line | Count | Source | 74 | 9.02k | { | 75 | 9.02k | PyObject* out; | 76 | 9.02k | Py_ssize_t pos; | 77 | | | 78 | 9.02k | if (sep_len == 0) { | 79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 80 | 0 | return NULL; | 81 | 0 | } | 82 | | | 83 | 9.02k | out = PyTuple_New(3); | 84 | 9.02k | if (!out) | 85 | 0 | return NULL; | 86 | | | 87 | 9.02k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); | 88 | | | 89 | 9.02k | 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.08k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 101 | 2.08k | assert(empty != NULL); | 102 | 2.08k | Py_INCREF(empty); | 103 | 2.08k | PyTuple_SET_ITEM(out, 0, empty); | 104 | 2.08k | Py_INCREF(empty); | 105 | 2.08k | PyTuple_SET_ITEM(out, 1, empty); | 106 | 2.08k | Py_INCREF(str_obj); | 107 | 2.08k | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); | 108 | 2.08k | #endif | 109 | 2.08k | return out; | 110 | 2.08k | } | 111 | | | 112 | 6.94k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 113 | 6.94k | Py_INCREF(sep_obj); | 114 | 6.94k | PyTuple_SET_ITEM(out, 1, sep_obj); | 115 | 6.94k | pos += sep_len; | 116 | 6.94k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 117 | | | 118 | 6.94k | if (PyErr_Occurred()) { | 119 | 0 | Py_DECREF(out); | 120 | 0 | return NULL; | 121 | 0 | } | 122 | | | 123 | 6.94k | return out; | 124 | 6.94k | } |
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 | | |