/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 | 7.46M | { |
18 | 7.46M | PyObject* out; |
19 | 7.46M | Py_ssize_t pos; |
20 | | |
21 | 7.46M | if (sep_len == 0) { |
22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
23 | 0 | return NULL; |
24 | 0 | } |
25 | | |
26 | 7.46M | out = PyTuple_New(3); |
27 | 7.46M | if (!out) |
28 | 0 | return NULL; |
29 | | |
30 | 7.46M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
31 | | |
32 | 7.46M | 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 | 989k | Py_INCREF(str_obj); |
44 | 989k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
45 | 989k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); |
46 | | assert(empty != NULL); |
47 | 989k | Py_INCREF(empty); |
48 | 989k | PyTuple_SET_ITEM(out, 1, empty); |
49 | 989k | Py_INCREF(empty); |
50 | 989k | PyTuple_SET_ITEM(out, 2, empty); |
51 | | #endif |
52 | 0 | return out; |
53 | 989k | } |
54 | | |
55 | 6.47M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
56 | 6.47M | Py_INCREF(sep_obj); |
57 | 6.47M | PyTuple_SET_ITEM(out, 1, sep_obj); |
58 | 6.47M | pos += sep_len; |
59 | 6.47M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
60 | | |
61 | 6.47M | if (PyErr_Occurred()) { |
62 | 0 | Py_DECREF(out); |
63 | 0 | return NULL; |
64 | 0 | } |
65 | | |
66 | 6.47M | return out; |
67 | 6.47M | } Unexecuted instantiation: bytesobject.c:stringlib_partition unicodeobject.c:asciilib_partition Line | Count | Source | 17 | 2.43M | { | 18 | 2.43M | PyObject* out; | 19 | 2.43M | Py_ssize_t pos; | 20 | | | 21 | 2.43M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 2.43M | out = PyTuple_New(3); | 27 | 2.43M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 2.43M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 2.43M | 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 | 730k | Py_INCREF(str_obj); | 44 | 730k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 730k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 730k | assert(empty != NULL); | 47 | 730k | Py_INCREF(empty); | 48 | 730k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 730k | Py_INCREF(empty); | 50 | 730k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 730k | #endif | 52 | 730k | return out; | 53 | 730k | } | 54 | | | 55 | 1.70M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 1.70M | Py_INCREF(sep_obj); | 57 | 1.70M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 1.70M | pos += sep_len; | 59 | 1.70M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 1.70M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 1.70M | return out; | 67 | 1.70M | } |
unicodeobject.c:ucs1lib_partition Line | Count | Source | 17 | 4.95M | { | 18 | 4.95M | PyObject* out; | 19 | 4.95M | Py_ssize_t pos; | 20 | | | 21 | 4.95M | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 4.95M | out = PyTuple_New(3); | 27 | 4.95M | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 4.95M | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 4.95M | 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 | 241k | Py_INCREF(str_obj); | 44 | 241k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 241k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 241k | assert(empty != NULL); | 47 | 241k | Py_INCREF(empty); | 48 | 241k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 241k | Py_INCREF(empty); | 50 | 241k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 241k | #endif | 52 | 241k | return out; | 53 | 241k | } | 54 | | | 55 | 4.71M | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 4.71M | Py_INCREF(sep_obj); | 57 | 4.71M | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 4.71M | pos += sep_len; | 59 | 4.71M | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 4.71M | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 4.71M | return out; | 67 | 4.71M | } |
unicodeobject.c:ucs2lib_partition Line | Count | Source | 17 | 61.3k | { | 18 | 61.3k | PyObject* out; | 19 | 61.3k | Py_ssize_t pos; | 20 | | | 21 | 61.3k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 61.3k | out = PyTuple_New(3); | 27 | 61.3k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 61.3k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 61.3k | 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 | 14.9k | Py_INCREF(str_obj); | 44 | 14.9k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 14.9k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 14.9k | assert(empty != NULL); | 47 | 14.9k | Py_INCREF(empty); | 48 | 14.9k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 14.9k | Py_INCREF(empty); | 50 | 14.9k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 14.9k | #endif | 52 | 14.9k | return out; | 53 | 14.9k | } | 54 | | | 55 | 46.3k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 46.3k | Py_INCREF(sep_obj); | 57 | 46.3k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 46.3k | pos += sep_len; | 59 | 46.3k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 46.3k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 46.3k | return out; | 67 | 46.3k | } |
unicodeobject.c:ucs4lib_partition Line | Count | Source | 17 | 7.96k | { | 18 | 7.96k | PyObject* out; | 19 | 7.96k | Py_ssize_t pos; | 20 | | | 21 | 7.96k | if (sep_len == 0) { | 22 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 23 | 0 | return NULL; | 24 | 0 | } | 25 | | | 26 | 7.96k | out = PyTuple_New(3); | 27 | 7.96k | if (!out) | 28 | 0 | return NULL; | 29 | | | 30 | 7.96k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); | 31 | | | 32 | 7.96k | 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 | 2.58k | Py_INCREF(str_obj); | 44 | 2.58k | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); | 45 | 2.58k | PyObject *empty = (PyObject*)STRINGLIB_GET_EMPTY(); | 46 | 2.58k | assert(empty != NULL); | 47 | 2.58k | Py_INCREF(empty); | 48 | 2.58k | PyTuple_SET_ITEM(out, 1, empty); | 49 | 2.58k | Py_INCREF(empty); | 50 | 2.58k | PyTuple_SET_ITEM(out, 2, empty); | 51 | 2.58k | #endif | 52 | 2.58k | return out; | 53 | 2.58k | } | 54 | | | 55 | 5.38k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 56 | 5.38k | Py_INCREF(sep_obj); | 57 | 5.38k | PyTuple_SET_ITEM(out, 1, sep_obj); | 58 | 5.38k | pos += sep_len; | 59 | 5.38k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 60 | | | 61 | 5.38k | if (PyErr_Occurred()) { | 62 | 0 | Py_DECREF(out); | 63 | 0 | return NULL; | 64 | 0 | } | 65 | | | 66 | 5.38k | return out; | 67 | 5.38k | } |
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.92k | { |
75 | 9.92k | PyObject* out; |
76 | 9.92k | Py_ssize_t pos; |
77 | | |
78 | 9.92k | if (sep_len == 0) { |
79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
80 | 0 | return NULL; |
81 | 0 | } |
82 | | |
83 | 9.92k | out = PyTuple_New(3); |
84 | 9.92k | if (!out) |
85 | 0 | return NULL; |
86 | | |
87 | 9.92k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
88 | | |
89 | 9.92k | 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 | 7.84k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
113 | 7.84k | Py_INCREF(sep_obj); |
114 | 7.84k | PyTuple_SET_ITEM(out, 1, sep_obj); |
115 | 7.84k | pos += sep_len; |
116 | 7.84k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
117 | | |
118 | 7.84k | if (PyErr_Occurred()) { |
119 | 0 | Py_DECREF(out); |
120 | 0 | return NULL; |
121 | 0 | } |
122 | | |
123 | 7.84k | return out; |
124 | 7.84k | } Unexecuted instantiation: bytesobject.c:stringlib_rpartition unicodeobject.c:asciilib_rpartition Line | Count | Source | 74 | 9.92k | { | 75 | 9.92k | PyObject* out; | 76 | 9.92k | Py_ssize_t pos; | 77 | | | 78 | 9.92k | if (sep_len == 0) { | 79 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 80 | 0 | return NULL; | 81 | 0 | } | 82 | | | 83 | 9.92k | out = PyTuple_New(3); | 84 | 9.92k | if (!out) | 85 | 0 | return NULL; | 86 | | | 87 | 9.92k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); | 88 | | | 89 | 9.92k | 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 | 7.84k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 113 | 7.84k | Py_INCREF(sep_obj); | 114 | 7.84k | PyTuple_SET_ITEM(out, 1, sep_obj); | 115 | 7.84k | pos += sep_len; | 116 | 7.84k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 117 | | | 118 | 7.84k | if (PyErr_Occurred()) { | 119 | 0 | Py_DECREF(out); | 120 | 0 | return NULL; | 121 | 0 | } | 122 | | | 123 | 7.84k | return out; | 124 | 7.84k | } |
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 | | |