/src/cpython/Objects/stringlib/split.h
Line | Count | Source |
1 | | /* stringlib: split implementation */ |
2 | | |
3 | | #ifndef STRINGLIB_FASTSEARCH_H |
4 | | #error must include "stringlib/fastsearch.h" before including this module |
5 | | #endif |
6 | | |
7 | | /* Overallocate the initial list to reduce the number of reallocs for small |
8 | | split sizes. Eg, "A A A A A A A A A A".split() (10 elements) has three |
9 | | resizes, to sizes 4, 8, then 16. Most observed string splits are for human |
10 | | text (roughly 11 words per line) and field delimited data (usually 1-10 |
11 | | fields). For large strings the split algorithms are bandwidth limited |
12 | | so increasing the preallocation likely will not improve things.*/ |
13 | | |
14 | 118M | #define MAX_PREALLOC 12 |
15 | | |
16 | | /* 5 splits gives 6 elements */ |
17 | | #define PREALLOC_SIZE(maxsplit) \ |
18 | 25.7M | (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1) |
19 | | |
20 | | #define SPLIT_APPEND(data, left, right) \ |
21 | 36.3M | sub = STRINGLIB_NEW((data) + (left), \ |
22 | 36.3M | (right) - (left)); \ |
23 | 36.3M | if (sub == NULL) \ |
24 | 36.3M | goto onError; \ |
25 | 36.3M | if (PyList_Append(list, sub)) { \ |
26 | 0 | Py_DECREF(sub); \ |
27 | 0 | goto onError; \ |
28 | 0 | } \ |
29 | 36.3M | else \ |
30 | 36.3M | Py_DECREF(sub); |
31 | | |
32 | 63.8M | #define SPLIT_ADD(data, left, right) { \ |
33 | 63.8M | sub = STRINGLIB_NEW((data) + (left), \ |
34 | 63.8M | (right) - (left)); \ |
35 | 63.8M | if (sub == NULL) \ |
36 | 63.8M | goto onError; \ |
37 | 63.8M | if (count < MAX_PREALLOC) { \ |
38 | 40.5M | PyList_SET_ITEM(list, count, sub); \ |
39 | 40.5M | } else { \ |
40 | 23.2M | if (PyList_Append(list, sub)) { \ |
41 | 0 | Py_DECREF(sub); \ |
42 | 0 | goto onError; \ |
43 | 0 | } \ |
44 | 23.2M | else \ |
45 | 23.2M | Py_DECREF(sub); \ |
46 | 23.2M | } \ |
47 | 63.8M | count++; } |
48 | | |
49 | | |
50 | | /* Always force the list to the expected size. */ |
51 | 25.7M | #define FIX_PREALLOC_SIZE(list) Py_SET_SIZE(list, count) |
52 | | |
53 | | Py_LOCAL_INLINE(PyObject *) |
54 | | STRINGLIB(split_whitespace)(PyObject* str_obj, |
55 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
56 | | Py_ssize_t maxcount) |
57 | 194k | { |
58 | 194k | Py_ssize_t i, j, count=0; |
59 | 194k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
60 | 194k | PyObject *sub; |
61 | | |
62 | 194k | if (list == NULL) |
63 | 0 | return NULL; |
64 | | |
65 | 194k | i = j = 0; |
66 | 1.99M | while (maxcount-- > 0) { |
67 | 3.77M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
68 | 1.81M | i++; |
69 | 1.95M | if (i == str_len) break; |
70 | 1.84M | j = i; i++; |
71 | 103M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) |
72 | 101M | i++; |
73 | | #if !STRINGLIB_MUTABLE |
74 | 1.84M | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { |
75 | | /* No whitespace in str_obj, so just use it as list[0] */ |
76 | 45.5k | Py_INCREF(str_obj); |
77 | 45.5k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
78 | 45.5k | count++; |
79 | 45.5k | break; |
80 | 45.5k | } |
81 | 1.79M | #endif |
82 | 5.39M | SPLIT_ADD(str, j, i); |
83 | 5.39M | } |
84 | | |
85 | 194k | if (i < str_len) { |
86 | | /* Only occurs when maxcount was reached */ |
87 | | /* Skip any remaining whitespace and copy to end of string */ |
88 | 58.2k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
89 | 31.3k | i++; |
90 | 26.8k | if (i != str_len) |
91 | 26.8k | SPLIT_ADD(str, i, str_len); |
92 | 26.8k | } |
93 | 194k | FIX_PREALLOC_SIZE(list); |
94 | 194k | return list; |
95 | | |
96 | 0 | onError: |
97 | 0 | Py_DECREF(list); |
98 | 0 | return NULL; |
99 | 194k | } Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace unicodeobject.c:asciilib_split_whitespace Line | Count | Source | 57 | 86.3k | { | 58 | 86.3k | Py_ssize_t i, j, count=0; | 59 | 86.3k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 86.3k | PyObject *sub; | 61 | | | 62 | 86.3k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 86.3k | i = j = 0; | 66 | 627k | while (maxcount-- > 0) { | 67 | 1.09M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 487k | i++; | 69 | 610k | if (i == str_len) break; | 70 | 564k | j = i; i++; | 71 | 38.7M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 38.1M | i++; | 73 | 564k | #if !STRINGLIB_MUTABLE | 74 | 564k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 75 | | /* No whitespace in str_obj, so just use it as list[0] */ | 76 | 23.8k | Py_INCREF(str_obj); | 77 | 23.8k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 23.8k | count++; | 79 | 23.8k | break; | 80 | 23.8k | } | 81 | 541k | #endif | 82 | 1.62M | SPLIT_ADD(str, j, i); | 83 | 1.62M | } | 84 | | | 85 | 86.3k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 28.8k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 14.8k | i++; | 90 | 13.9k | if (i != str_len) | 91 | 13.9k | SPLIT_ADD(str, i, str_len); | 92 | 13.9k | } | 93 | 86.3k | FIX_PREALLOC_SIZE(list); | 94 | 86.3k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | | return NULL; | 99 | 86.3k | } |
unicodeobject.c:ucs1lib_split_whitespace Line | Count | Source | 57 | 34.3k | { | 58 | 34.3k | Py_ssize_t i, j, count=0; | 59 | 34.3k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 34.3k | PyObject *sub; | 61 | | | 62 | 34.3k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 34.3k | i = j = 0; | 66 | 726k | while (maxcount-- > 0) { | 67 | 1.38M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 671k | i++; | 69 | 711k | if (i == str_len) break; | 70 | 695k | j = i; i++; | 71 | 28.9M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 28.2M | i++; | 73 | 695k | #if !STRINGLIB_MUTABLE | 74 | 695k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 75 | | /* No whitespace in str_obj, so just use it as list[0] */ | 76 | 3.52k | Py_INCREF(str_obj); | 77 | 3.52k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 3.52k | count++; | 79 | 3.52k | break; | 80 | 3.52k | } | 81 | 691k | #endif | 82 | 2.07M | SPLIT_ADD(str, j, i); | 83 | 2.07M | } | 84 | | | 85 | 34.3k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 27.2k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 15.4k | i++; | 90 | 11.7k | if (i != str_len) | 91 | 11.7k | SPLIT_ADD(str, i, str_len); | 92 | 11.7k | } | 93 | 34.3k | FIX_PREALLOC_SIZE(list); | 94 | 34.3k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | | return NULL; | 99 | 34.3k | } |
unicodeobject.c:ucs2lib_split_whitespace Line | Count | Source | 57 | 62.3k | { | 58 | 62.3k | Py_ssize_t i, j, count=0; | 59 | 62.3k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 62.3k | PyObject *sub; | 61 | | | 62 | 62.3k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 62.3k | i = j = 0; | 66 | 553k | while (maxcount-- > 0) { | 67 | 1.12M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 572k | i++; | 69 | 552k | if (i == str_len) break; | 70 | 505k | j = i; i++; | 71 | 25.7M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 25.2M | i++; | 73 | 505k | #if !STRINGLIB_MUTABLE | 74 | 505k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 75 | | /* No whitespace in str_obj, so just use it as list[0] */ | 76 | 14.1k | Py_INCREF(str_obj); | 77 | 14.1k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 14.1k | count++; | 79 | 14.1k | break; | 80 | 14.1k | } | 81 | 491k | #endif | 82 | 1.47M | SPLIT_ADD(str, j, i); | 83 | 1.47M | } | 84 | | | 85 | 62.3k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 2.17k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 1.08k | i++; | 90 | 1.08k | if (i != str_len) | 91 | 1.08k | SPLIT_ADD(str, i, str_len); | 92 | 1.08k | } | 93 | 62.3k | FIX_PREALLOC_SIZE(list); | 94 | 62.3k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | | return NULL; | 99 | 62.3k | } |
unicodeobject.c:ucs4lib_split_whitespace Line | Count | Source | 57 | 11.5k | { | 58 | 11.5k | Py_ssize_t i, j, count=0; | 59 | 11.5k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 11.5k | PyObject *sub; | 61 | | | 62 | 11.5k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 11.5k | i = j = 0; | 66 | 84.2k | while (maxcount-- > 0) { | 67 | 164k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 80.6k | i++; | 69 | 83.9k | if (i == str_len) break; | 70 | 76.7k | j = i; i++; | 71 | 10.1M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 10.0M | i++; | 73 | 76.7k | #if !STRINGLIB_MUTABLE | 74 | 76.7k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 75 | | /* No whitespace in str_obj, so just use it as list[0] */ | 76 | 4.01k | Py_INCREF(str_obj); | 77 | 4.01k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 4.01k | count++; | 79 | 4.01k | break; | 80 | 4.01k | } | 81 | 72.7k | #endif | 82 | 218k | SPLIT_ADD(str, j, i); | 83 | 218k | } | 84 | | | 85 | 11.5k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 0 | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 0 | i++; | 90 | 0 | if (i != str_len) | 91 | 0 | SPLIT_ADD(str, i, str_len); | 92 | 0 | } | 93 | 11.5k | FIX_PREALLOC_SIZE(list); | 94 | 11.5k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | | return NULL; | 99 | 11.5k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split_whitespace |
100 | | |
101 | | Py_LOCAL_INLINE(PyObject *) |
102 | | STRINGLIB(split_char)(PyObject* str_obj, |
103 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
104 | | const STRINGLIB_CHAR ch, |
105 | | Py_ssize_t maxcount) |
106 | 25.2M | { |
107 | 25.2M | Py_ssize_t i, j, count=0; |
108 | 25.2M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
109 | 25.2M | PyObject *sub; |
110 | | |
111 | 25.2M | if (list == NULL) |
112 | 0 | return NULL; |
113 | | |
114 | 25.2M | i = j = 0; |
115 | 90.7M | while ((j < str_len) && (maxcount-- > 0)) { |
116 | 424M | for(; j < str_len; j++) { |
117 | | /* I found that using memchr makes no difference */ |
118 | 401M | if (str[j] == ch) { |
119 | 42.4M | SPLIT_ADD(str, i, j); |
120 | 42.4M | i = j = j + 1; |
121 | 42.4M | break; |
122 | 42.4M | } |
123 | 401M | } |
124 | 65.4M | } |
125 | | #if !STRINGLIB_MUTABLE |
126 | 25.2M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
127 | | /* ch not in str_obj, so just use str_obj as list[0] */ |
128 | 6.11M | Py_INCREF(str_obj); |
129 | 6.11M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
130 | 6.11M | count++; |
131 | 6.11M | } else |
132 | 19.1M | #endif |
133 | 19.1M | if (i <= str_len) { |
134 | 38.3M | SPLIT_ADD(str, i, str_len); |
135 | 38.3M | } |
136 | 25.2M | FIX_PREALLOC_SIZE(list); |
137 | 25.2M | return list; |
138 | | |
139 | 0 | onError: |
140 | 0 | Py_DECREF(list); |
141 | 0 | return NULL; |
142 | 0 | } bytesobject.c:stringlib_split_char Line | Count | Source | 106 | 3.30M | { | 107 | 3.30M | Py_ssize_t i, j, count=0; | 108 | 3.30M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 3.30M | PyObject *sub; | 110 | | | 111 | 3.30M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 3.30M | i = j = 0; | 115 | 11.8M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 59.6M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 56.8M | if (str[j] == ch) { | 119 | 5.73M | SPLIT_ADD(str, i, j); | 120 | 5.73M | i = j = j + 1; | 121 | 5.73M | break; | 122 | 5.73M | } | 123 | 56.8M | } | 124 | 8.56M | } | 125 | 3.30M | #if !STRINGLIB_MUTABLE | 126 | 3.30M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 2.73M | Py_INCREF(str_obj); | 129 | 2.73M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 2.73M | count++; | 131 | 2.73M | } else | 132 | 572k | #endif | 133 | 572k | if (i <= str_len) { | 134 | 1.14M | SPLIT_ADD(str, i, str_len); | 135 | 1.14M | } | 136 | 3.30M | FIX_PREALLOC_SIZE(list); | 137 | 3.30M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | | return NULL; | 142 | 3.30M | } |
unicodeobject.c:asciilib_split_char Line | Count | Source | 106 | 20.5M | { | 107 | 20.5M | Py_ssize_t i, j, count=0; | 108 | 20.5M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 20.5M | PyObject *sub; | 110 | | | 111 | 20.5M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 20.5M | i = j = 0; | 115 | 63.7M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 254M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 234M | if (str[j] == ch) { | 119 | 23.3M | SPLIT_ADD(str, i, j); | 120 | 23.3M | i = j = j + 1; | 121 | 23.3M | break; | 122 | 23.3M | } | 123 | 234M | } | 124 | 43.1M | } | 125 | 20.5M | #if !STRINGLIB_MUTABLE | 126 | 20.5M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 3.17M | Py_INCREF(str_obj); | 129 | 3.17M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 3.17M | count++; | 131 | 3.17M | } else | 132 | 17.4M | #endif | 133 | 17.4M | if (i <= str_len) { | 134 | 34.8M | SPLIT_ADD(str, i, str_len); | 135 | 34.8M | } | 136 | 20.5M | FIX_PREALLOC_SIZE(list); | 137 | 20.5M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | | return NULL; | 142 | 20.5M | } |
unicodeobject.c:ucs1lib_split_char Line | Count | Source | 106 | 1.23M | { | 107 | 1.23M | Py_ssize_t i, j, count=0; | 108 | 1.23M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 1.23M | PyObject *sub; | 110 | | | 111 | 1.23M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 1.23M | i = j = 0; | 115 | 11.0M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 54.6M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 54.4M | if (str[j] == ch) { | 119 | 9.58M | SPLIT_ADD(str, i, j); | 120 | 9.58M | i = j = j + 1; | 121 | 9.58M | break; | 122 | 9.58M | } | 123 | 54.4M | } | 124 | 9.79M | } | 125 | 1.23M | #if !STRINGLIB_MUTABLE | 126 | 1.23M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 171k | Py_INCREF(str_obj); | 129 | 171k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 171k | count++; | 131 | 171k | } else | 132 | 1.06M | #endif | 133 | 1.06M | if (i <= str_len) { | 134 | 2.12M | SPLIT_ADD(str, i, str_len); | 135 | 2.12M | } | 136 | 1.23M | FIX_PREALLOC_SIZE(list); | 137 | 1.23M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | | return NULL; | 142 | 1.23M | } |
unicodeobject.c:ucs2lib_split_char Line | Count | Source | 106 | 131k | { | 107 | 131k | Py_ssize_t i, j, count=0; | 108 | 131k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 131k | PyObject *sub; | 110 | | | 111 | 131k | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 131k | i = j = 0; | 115 | 3.82M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 33.3M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 33.2M | if (str[j] == ch) { | 119 | 3.59M | SPLIT_ADD(str, i, j); | 120 | 3.59M | i = j = j + 1; | 121 | 3.59M | break; | 122 | 3.59M | } | 123 | 33.2M | } | 124 | 3.69M | } | 125 | 131k | #if !STRINGLIB_MUTABLE | 126 | 131k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 29.1k | Py_INCREF(str_obj); | 129 | 29.1k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 29.1k | count++; | 131 | 29.1k | } else | 132 | 102k | #endif | 133 | 102k | if (i <= str_len) { | 134 | 205k | SPLIT_ADD(str, i, str_len); | 135 | 205k | } | 136 | 131k | FIX_PREALLOC_SIZE(list); | 137 | 131k | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | | return NULL; | 142 | 131k | } |
unicodeobject.c:ucs4lib_split_char Line | Count | Source | 106 | 15.9k | { | 107 | 15.9k | Py_ssize_t i, j, count=0; | 108 | 15.9k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 15.9k | PyObject *sub; | 110 | | | 111 | 15.9k | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 15.9k | i = j = 0; | 115 | 252k | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 22.0M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 22.0M | if (str[j] == ch) { | 119 | 223k | SPLIT_ADD(str, i, j); | 120 | 223k | i = j = j + 1; | 121 | 223k | break; | 122 | 223k | } | 123 | 22.0M | } | 124 | 236k | } | 125 | 15.9k | #if !STRINGLIB_MUTABLE | 126 | 15.9k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 877 | Py_INCREF(str_obj); | 129 | 877 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 877 | count++; | 131 | 877 | } else | 132 | 15.0k | #endif | 133 | 15.0k | if (i <= str_len) { | 134 | 30.0k | SPLIT_ADD(str, i, str_len); | 135 | 30.0k | } | 136 | 15.9k | FIX_PREALLOC_SIZE(list); | 137 | 15.9k | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | | return NULL; | 142 | 15.9k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split_char |
143 | | |
144 | | Py_LOCAL_INLINE(PyObject *) |
145 | | STRINGLIB(split)(PyObject* str_obj, |
146 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
147 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len, |
148 | | Py_ssize_t maxcount) |
149 | 25.5M | { |
150 | 25.5M | Py_ssize_t i, j, pos, count=0; |
151 | 25.5M | PyObject *list, *sub; |
152 | | |
153 | 25.5M | if (sep_len == 0) { |
154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
155 | 0 | return NULL; |
156 | 0 | } |
157 | 25.5M | else if (sep_len == 1) |
158 | 25.2M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); |
159 | | |
160 | 246k | list = PyList_New(PREALLOC_SIZE(maxcount)); |
161 | 246k | if (list == NULL) |
162 | 0 | return NULL; |
163 | | |
164 | 246k | i = j = 0; |
165 | 439k | while (maxcount-- > 0) { |
166 | 246k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); |
167 | 246k | if (pos < 0) |
168 | 54.8k | break; |
169 | 192k | j = i + pos; |
170 | 384k | SPLIT_ADD(str, i, j); |
171 | 384k | i = j + sep_len; |
172 | 384k | } |
173 | | #if !STRINGLIB_MUTABLE |
174 | 246k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
175 | | /* No match in str_obj, so just use it as list[0] */ |
176 | 54.8k | Py_INCREF(str_obj); |
177 | 54.8k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
178 | 54.8k | count++; |
179 | 54.8k | } else |
180 | 192k | #endif |
181 | 192k | { |
182 | 384k | SPLIT_ADD(str, i, str_len); |
183 | 384k | } |
184 | 246k | FIX_PREALLOC_SIZE(list); |
185 | 246k | return list; |
186 | | |
187 | 0 | onError: |
188 | 0 | Py_DECREF(list); |
189 | 0 | return NULL; |
190 | 0 | } bytesobject.c:stringlib_split Line | Count | Source | 149 | 3.30M | { | 150 | 3.30M | Py_ssize_t i, j, pos, count=0; | 151 | 3.30M | PyObject *list, *sub; | 152 | | | 153 | 3.30M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 3.30M | else if (sep_len == 1) | 158 | 3.30M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 0 | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 0 | i = j = 0; | 165 | 0 | while (maxcount-- > 0) { | 166 | 0 | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 0 | if (pos < 0) | 168 | 0 | break; | 169 | 0 | j = i + pos; | 170 | 0 | SPLIT_ADD(str, i, j); | 171 | 0 | i = j + sep_len; | 172 | 0 | } | 173 | 0 | #if !STRINGLIB_MUTABLE | 174 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 0 | Py_INCREF(str_obj); | 177 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 0 | count++; | 179 | 0 | } else | 180 | 0 | #endif | 181 | 0 | { | 182 | 0 | SPLIT_ADD(str, i, str_len); | 183 | 0 | } | 184 | 0 | FIX_PREALLOC_SIZE(list); | 185 | 0 | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | | return NULL; | 190 | 0 | } |
unicodeobject.c:asciilib_split Line | Count | Source | 149 | 20.6M | { | 150 | 20.6M | Py_ssize_t i, j, pos, count=0; | 151 | 20.6M | PyObject *list, *sub; | 152 | | | 153 | 20.6M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 20.6M | else if (sep_len == 1) | 158 | 20.5M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 92.0k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 92.0k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 92.0k | i = j = 0; | 165 | 149k | while (maxcount-- > 0) { | 166 | 92.0k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 92.0k | if (pos < 0) | 168 | 34.9k | break; | 169 | 57.0k | j = i + pos; | 170 | 114k | SPLIT_ADD(str, i, j); | 171 | 114k | i = j + sep_len; | 172 | 114k | } | 173 | 92.0k | #if !STRINGLIB_MUTABLE | 174 | 92.0k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 34.9k | Py_INCREF(str_obj); | 177 | 34.9k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 34.9k | count++; | 179 | 34.9k | } else | 180 | 57.0k | #endif | 181 | 57.0k | { | 182 | 114k | SPLIT_ADD(str, i, str_len); | 183 | 114k | } | 184 | 92.0k | FIX_PREALLOC_SIZE(list); | 185 | 92.0k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | | return NULL; | 190 | 92.0k | } |
unicodeobject.c:ucs1lib_split Line | Count | Source | 149 | 1.25M | { | 150 | 1.25M | Py_ssize_t i, j, pos, count=0; | 151 | 1.25M | PyObject *list, *sub; | 152 | | | 153 | 1.25M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 1.25M | else if (sep_len == 1) | 158 | 1.23M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 27.4k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 27.4k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 27.4k | i = j = 0; | 165 | 52.6k | while (maxcount-- > 0) { | 166 | 27.4k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 27.4k | if (pos < 0) | 168 | 2.28k | break; | 169 | 25.1k | j = i + pos; | 170 | 50.3k | SPLIT_ADD(str, i, j); | 171 | 50.3k | i = j + sep_len; | 172 | 50.3k | } | 173 | 27.4k | #if !STRINGLIB_MUTABLE | 174 | 27.4k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 2.28k | Py_INCREF(str_obj); | 177 | 2.28k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 2.28k | count++; | 179 | 2.28k | } else | 180 | 25.1k | #endif | 181 | 25.1k | { | 182 | 50.3k | SPLIT_ADD(str, i, str_len); | 183 | 50.3k | } | 184 | 27.4k | FIX_PREALLOC_SIZE(list); | 185 | 27.4k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | | return NULL; | 190 | 27.4k | } |
unicodeobject.c:ucs2lib_split Line | Count | Source | 149 | 236k | { | 150 | 236k | Py_ssize_t i, j, pos, count=0; | 151 | 236k | PyObject *list, *sub; | 152 | | | 153 | 236k | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 236k | else if (sep_len == 1) | 158 | 131k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 105k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 105k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 105k | i = j = 0; | 165 | 196k | while (maxcount-- > 0) { | 166 | 105k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 105k | if (pos < 0) | 168 | 14.0k | break; | 169 | 91.1k | j = i + pos; | 170 | 182k | SPLIT_ADD(str, i, j); | 171 | 182k | i = j + sep_len; | 172 | 182k | } | 173 | 105k | #if !STRINGLIB_MUTABLE | 174 | 105k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 14.0k | Py_INCREF(str_obj); | 177 | 14.0k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 14.0k | count++; | 179 | 14.0k | } else | 180 | 91.1k | #endif | 181 | 91.1k | { | 182 | 182k | SPLIT_ADD(str, i, str_len); | 183 | 182k | } | 184 | 105k | FIX_PREALLOC_SIZE(list); | 185 | 105k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | | return NULL; | 190 | 105k | } |
unicodeobject.c:ucs4lib_split Line | Count | Source | 149 | 38.1k | { | 150 | 38.1k | Py_ssize_t i, j, pos, count=0; | 151 | 38.1k | PyObject *list, *sub; | 152 | | | 153 | 38.1k | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 38.1k | else if (sep_len == 1) | 158 | 15.9k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 22.2k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 22.2k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 22.2k | i = j = 0; | 165 | 40.9k | while (maxcount-- > 0) { | 166 | 22.2k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 22.2k | if (pos < 0) | 168 | 3.54k | break; | 169 | 18.7k | j = i + pos; | 170 | 37.4k | SPLIT_ADD(str, i, j); | 171 | 37.4k | i = j + sep_len; | 172 | 37.4k | } | 173 | 22.2k | #if !STRINGLIB_MUTABLE | 174 | 22.2k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 3.54k | Py_INCREF(str_obj); | 177 | 3.54k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 3.54k | count++; | 179 | 3.54k | } else | 180 | 18.7k | #endif | 181 | 18.7k | { | 182 | 37.4k | SPLIT_ADD(str, i, str_len); | 183 | 37.4k | } | 184 | 22.2k | FIX_PREALLOC_SIZE(list); | 185 | 22.2k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | | return NULL; | 190 | 22.2k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split |
191 | | |
192 | | Py_LOCAL_INLINE(PyObject *) |
193 | | STRINGLIB(rsplit_whitespace)(PyObject* str_obj, |
194 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
195 | | Py_ssize_t maxcount) |
196 | 0 | { |
197 | 0 | Py_ssize_t i, j, count=0; |
198 | 0 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
199 | 0 | PyObject *sub; |
200 | |
|
201 | 0 | if (list == NULL) |
202 | 0 | return NULL; |
203 | | |
204 | 0 | i = j = str_len - 1; |
205 | 0 | while (maxcount-- > 0) { |
206 | 0 | while (i >= 0 && STRINGLIB_ISSPACE(str[i])) |
207 | 0 | i--; |
208 | 0 | if (i < 0) break; |
209 | 0 | j = i; i--; |
210 | 0 | while (i >= 0 && !STRINGLIB_ISSPACE(str[i])) |
211 | 0 | i--; |
212 | | #if !STRINGLIB_MUTABLE |
213 | 0 | if (j == str_len - 1 && i < 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
214 | | /* No whitespace in str_obj, so just use it as list[0] */ |
215 | 0 | Py_INCREF(str_obj); |
216 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
217 | 0 | count++; |
218 | 0 | break; |
219 | 0 | } |
220 | 0 | #endif |
221 | 0 | SPLIT_ADD(str, i + 1, j + 1); |
222 | 0 | } |
223 | | |
224 | 0 | if (i >= 0) { |
225 | | /* Only occurs when maxcount was reached */ |
226 | | /* Skip any remaining whitespace and copy to beginning of string */ |
227 | 0 | while (i >= 0 && STRINGLIB_ISSPACE(str[i])) |
228 | 0 | i--; |
229 | 0 | if (i >= 0) |
230 | 0 | SPLIT_ADD(str, 0, i + 1); |
231 | 0 | } |
232 | 0 | FIX_PREALLOC_SIZE(list); |
233 | 0 | if (PyList_Reverse(list) < 0) |
234 | 0 | goto onError; |
235 | 0 | return list; |
236 | | |
237 | 0 | onError: |
238 | 0 | Py_DECREF(list); |
239 | 0 | return NULL; |
240 | 0 | } Unexecuted instantiation: bytesobject.c:stringlib_rsplit_whitespace Unexecuted instantiation: unicodeobject.c:asciilib_rsplit_whitespace Unexecuted instantiation: unicodeobject.c:ucs1lib_rsplit_whitespace Unexecuted instantiation: unicodeobject.c:ucs2lib_rsplit_whitespace Unexecuted instantiation: unicodeobject.c:ucs4lib_rsplit_whitespace Unexecuted instantiation: bytearrayobject.c:stringlib_rsplit_whitespace |
241 | | |
242 | | Py_LOCAL_INLINE(PyObject *) |
243 | | STRINGLIB(rsplit_char)(PyObject* str_obj, |
244 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
245 | | const STRINGLIB_CHAR ch, |
246 | | Py_ssize_t maxcount) |
247 | 50 | { |
248 | 50 | Py_ssize_t i, j, count=0; |
249 | 50 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
250 | 50 | PyObject *sub; |
251 | | |
252 | 50 | if (list == NULL) |
253 | 0 | return NULL; |
254 | | |
255 | 50 | i = j = str_len - 1; |
256 | 100 | while ((i >= 0) && (maxcount-- > 0)) { |
257 | 50 | for(; i >= 0; i--) { |
258 | 50 | if (str[i] == ch) { |
259 | 50 | SPLIT_ADD(str, i + 1, j + 1); |
260 | 50 | j = i = i - 1; |
261 | 50 | break; |
262 | 50 | } |
263 | 50 | } |
264 | 50 | } |
265 | | #if !STRINGLIB_MUTABLE |
266 | 50 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
267 | | /* ch not in str_obj, so just use str_obj as list[0] */ |
268 | 0 | Py_INCREF(str_obj); |
269 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
270 | 0 | count++; |
271 | 0 | } else |
272 | 50 | #endif |
273 | 50 | if (j >= -1) { |
274 | 100 | SPLIT_ADD(str, 0, j + 1); |
275 | 100 | } |
276 | 50 | FIX_PREALLOC_SIZE(list); |
277 | 50 | if (PyList_Reverse(list) < 0) |
278 | 0 | goto onError; |
279 | 50 | return list; |
280 | | |
281 | 0 | onError: |
282 | 0 | Py_DECREF(list); |
283 | 0 | return NULL; |
284 | 50 | } Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char unicodeobject.c:asciilib_rsplit_char Line | Count | Source | 247 | 50 | { | 248 | 50 | Py_ssize_t i, j, count=0; | 249 | 50 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 250 | 50 | PyObject *sub; | 251 | | | 252 | 50 | if (list == NULL) | 253 | 0 | return NULL; | 254 | | | 255 | 50 | i = j = str_len - 1; | 256 | 100 | while ((i >= 0) && (maxcount-- > 0)) { | 257 | 50 | for(; i >= 0; i--) { | 258 | 50 | if (str[i] == ch) { | 259 | 50 | SPLIT_ADD(str, i + 1, j + 1); | 260 | 50 | j = i = i - 1; | 261 | 50 | break; | 262 | 50 | } | 263 | 50 | } | 264 | 50 | } | 265 | 50 | #if !STRINGLIB_MUTABLE | 266 | 50 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 267 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 268 | 0 | Py_INCREF(str_obj); | 269 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 270 | 0 | count++; | 271 | 0 | } else | 272 | 50 | #endif | 273 | 50 | if (j >= -1) { | 274 | 100 | SPLIT_ADD(str, 0, j + 1); | 275 | 100 | } | 276 | 50 | FIX_PREALLOC_SIZE(list); | 277 | 50 | if (PyList_Reverse(list) < 0) | 278 | 0 | goto onError; | 279 | 50 | return list; | 280 | | | 281 | 0 | onError: | 282 | 0 | Py_DECREF(list); | 283 | | return NULL; | 284 | 50 | } |
Unexecuted instantiation: unicodeobject.c:ucs1lib_rsplit_char Unexecuted instantiation: unicodeobject.c:ucs2lib_rsplit_char Unexecuted instantiation: unicodeobject.c:ucs4lib_rsplit_char Unexecuted instantiation: bytearrayobject.c:stringlib_rsplit_char |
285 | | |
286 | | Py_LOCAL_INLINE(PyObject *) |
287 | | STRINGLIB(rsplit)(PyObject* str_obj, |
288 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
289 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len, |
290 | | Py_ssize_t maxcount) |
291 | 50 | { |
292 | 50 | Py_ssize_t j, pos, count=0; |
293 | 50 | PyObject *list, *sub; |
294 | | |
295 | 50 | if (sep_len == 0) { |
296 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
297 | 0 | return NULL; |
298 | 0 | } |
299 | 50 | else if (sep_len == 1) |
300 | 50 | return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount); |
301 | | |
302 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); |
303 | 0 | if (list == NULL) |
304 | 0 | return NULL; |
305 | | |
306 | 0 | j = str_len; |
307 | 0 | while (maxcount-- > 0) { |
308 | 0 | pos = FASTSEARCH(str, j, sep, sep_len, -1, FAST_RSEARCH); |
309 | 0 | if (pos < 0) |
310 | 0 | break; |
311 | 0 | SPLIT_ADD(str, pos + sep_len, j); |
312 | 0 | j = pos; |
313 | 0 | } |
314 | | #if !STRINGLIB_MUTABLE |
315 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
316 | | /* No match in str_obj, so just use it as list[0] */ |
317 | 0 | Py_INCREF(str_obj); |
318 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
319 | 0 | count++; |
320 | 0 | } else |
321 | 0 | #endif |
322 | 0 | { |
323 | 0 | SPLIT_ADD(str, 0, j); |
324 | 0 | } |
325 | 0 | FIX_PREALLOC_SIZE(list); |
326 | 0 | if (PyList_Reverse(list) < 0) |
327 | 0 | goto onError; |
328 | 0 | return list; |
329 | | |
330 | 0 | onError: |
331 | 0 | Py_DECREF(list); |
332 | 0 | return NULL; |
333 | 0 | } Unexecuted instantiation: bytesobject.c:stringlib_rsplit unicodeobject.c:asciilib_rsplit Line | Count | Source | 291 | 50 | { | 292 | 50 | Py_ssize_t j, pos, count=0; | 293 | 50 | PyObject *list, *sub; | 294 | | | 295 | 50 | if (sep_len == 0) { | 296 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 297 | 0 | return NULL; | 298 | 0 | } | 299 | 50 | else if (sep_len == 1) | 300 | 50 | return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount); | 301 | | | 302 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); | 303 | 0 | if (list == NULL) | 304 | 0 | return NULL; | 305 | | | 306 | 0 | j = str_len; | 307 | 0 | while (maxcount-- > 0) { | 308 | 0 | pos = FASTSEARCH(str, j, sep, sep_len, -1, FAST_RSEARCH); | 309 | 0 | if (pos < 0) | 310 | 0 | break; | 311 | 0 | SPLIT_ADD(str, pos + sep_len, j); | 312 | 0 | j = pos; | 313 | 0 | } | 314 | 0 | #if !STRINGLIB_MUTABLE | 315 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 316 | | /* No match in str_obj, so just use it as list[0] */ | 317 | 0 | Py_INCREF(str_obj); | 318 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 319 | 0 | count++; | 320 | 0 | } else | 321 | 0 | #endif | 322 | 0 | { | 323 | 0 | SPLIT_ADD(str, 0, j); | 324 | 0 | } | 325 | 0 | FIX_PREALLOC_SIZE(list); | 326 | 0 | if (PyList_Reverse(list) < 0) | 327 | 0 | goto onError; | 328 | 0 | return list; | 329 | | | 330 | 0 | onError: | 331 | 0 | Py_DECREF(list); | 332 | | return NULL; | 333 | 0 | } |
Unexecuted instantiation: unicodeobject.c:ucs1lib_rsplit Unexecuted instantiation: unicodeobject.c:ucs2lib_rsplit Unexecuted instantiation: unicodeobject.c:ucs4lib_rsplit Unexecuted instantiation: bytearrayobject.c:stringlib_rsplit |
334 | | |
335 | | Py_LOCAL_INLINE(PyObject *) |
336 | | STRINGLIB(splitlines)(PyObject* str_obj, |
337 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
338 | | int keepends) |
339 | 13.5k | { |
340 | | /* This does not use the preallocated list because splitlines is |
341 | | usually run with hundreds of newlines. The overhead of |
342 | | switching between PyList_SET_ITEM and append causes about a |
343 | | 2-3% slowdown for that common case. A smarter implementation |
344 | | could move the if check out, so the SET_ITEMs are done first |
345 | | and the appends only done when the prealloc buffer is full. |
346 | | That's too much work for little gain.*/ |
347 | | |
348 | 13.5k | Py_ssize_t i; |
349 | 13.5k | Py_ssize_t j; |
350 | 13.5k | PyObject *list = PyList_New(0); |
351 | 13.5k | PyObject *sub; |
352 | | |
353 | 13.5k | if (list == NULL) |
354 | 0 | return NULL; |
355 | | |
356 | 36.3M | for (i = j = 0; i < str_len; ) { |
357 | 36.3M | Py_ssize_t eol; |
358 | | |
359 | | /* Find a line and append it */ |
360 | 259M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) |
361 | 222M | i++; |
362 | | |
363 | | /* Skip the line break reading CRLF as one line break */ |
364 | 36.3M | eol = i; |
365 | 36.3M | if (i < str_len) { |
366 | 36.3M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') |
367 | 40.5k | i += 2; |
368 | 36.3M | else |
369 | 36.3M | i++; |
370 | 36.3M | if (keepends) |
371 | 0 | eol = i; |
372 | 36.3M | } |
373 | | #if !STRINGLIB_MUTABLE |
374 | 36.3M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { |
375 | | /* No linebreak in str_obj, so just use it as list[0] */ |
376 | 5.41k | if (PyList_Append(list, str_obj)) |
377 | 0 | goto onError; |
378 | 5.41k | break; |
379 | 5.41k | } |
380 | 36.3M | #endif |
381 | 72.7M | SPLIT_APPEND(str, j, eol); |
382 | 36.3M | j = i; |
383 | 36.3M | } |
384 | 13.5k | return list; |
385 | | |
386 | 0 | onError: |
387 | 0 | Py_DECREF(list); |
388 | | return NULL; |
389 | 13.5k | } Unexecuted instantiation: bytesobject.c:stringlib_splitlines unicodeobject.c:asciilib_splitlines Line | Count | Source | 339 | 2.66k | { | 340 | | /* This does not use the preallocated list because splitlines is | 341 | | usually run with hundreds of newlines. The overhead of | 342 | | switching between PyList_SET_ITEM and append causes about a | 343 | | 2-3% slowdown for that common case. A smarter implementation | 344 | | could move the if check out, so the SET_ITEMs are done first | 345 | | and the appends only done when the prealloc buffer is full. | 346 | | That's too much work for little gain.*/ | 347 | | | 348 | 2.66k | Py_ssize_t i; | 349 | 2.66k | Py_ssize_t j; | 350 | 2.66k | PyObject *list = PyList_New(0); | 351 | 2.66k | PyObject *sub; | 352 | | | 353 | 2.66k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 8.11M | for (i = j = 0; i < str_len; ) { | 357 | 8.11M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 42.5M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 34.4M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 8.11M | eol = i; | 365 | 8.11M | if (i < str_len) { | 366 | 8.11M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 994 | i += 2; | 368 | 8.11M | else | 369 | 8.11M | i++; | 370 | 8.11M | if (keepends) | 371 | 0 | eol = i; | 372 | 8.11M | } | 373 | 8.11M | #if !STRINGLIB_MUTABLE | 374 | 8.11M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 375 | | /* No linebreak in str_obj, so just use it as list[0] */ | 376 | 974 | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 974 | break; | 379 | 974 | } | 380 | 8.11M | #endif | 381 | 16.2M | SPLIT_APPEND(str, j, eol); | 382 | 8.11M | j = i; | 383 | 8.11M | } | 384 | 2.66k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | | return NULL; | 389 | 2.66k | } |
unicodeobject.c:ucs1lib_splitlines Line | Count | Source | 339 | 841 | { | 340 | | /* This does not use the preallocated list because splitlines is | 341 | | usually run with hundreds of newlines. The overhead of | 342 | | switching between PyList_SET_ITEM and append causes about a | 343 | | 2-3% slowdown for that common case. A smarter implementation | 344 | | could move the if check out, so the SET_ITEMs are done first | 345 | | and the appends only done when the prealloc buffer is full. | 346 | | That's too much work for little gain.*/ | 347 | | | 348 | 841 | Py_ssize_t i; | 349 | 841 | Py_ssize_t j; | 350 | 841 | PyObject *list = PyList_New(0); | 351 | 841 | PyObject *sub; | 352 | | | 353 | 841 | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 1.20M | for (i = j = 0; i < str_len; ) { | 357 | 1.20M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 12.0M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 10.8M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 1.20M | eol = i; | 365 | 1.20M | if (i < str_len) { | 366 | 1.20M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 1.31k | i += 2; | 368 | 1.20M | else | 369 | 1.20M | i++; | 370 | 1.20M | if (keepends) | 371 | 0 | eol = i; | 372 | 1.20M | } | 373 | 1.20M | #if !STRINGLIB_MUTABLE | 374 | 1.20M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 375 | | /* No linebreak in str_obj, so just use it as list[0] */ | 376 | 219 | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 219 | break; | 379 | 219 | } | 380 | 1.20M | #endif | 381 | 2.40M | SPLIT_APPEND(str, j, eol); | 382 | 1.20M | j = i; | 383 | 1.20M | } | 384 | 841 | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | | return NULL; | 389 | 841 | } |
unicodeobject.c:ucs2lib_splitlines Line | Count | Source | 339 | 7.07k | { | 340 | | /* This does not use the preallocated list because splitlines is | 341 | | usually run with hundreds of newlines. The overhead of | 342 | | switching between PyList_SET_ITEM and append causes about a | 343 | | 2-3% slowdown for that common case. A smarter implementation | 344 | | could move the if check out, so the SET_ITEMs are done first | 345 | | and the appends only done when the prealloc buffer is full. | 346 | | That's too much work for little gain.*/ | 347 | | | 348 | 7.07k | Py_ssize_t i; | 349 | 7.07k | Py_ssize_t j; | 350 | 7.07k | PyObject *list = PyList_New(0); | 351 | 7.07k | PyObject *sub; | 352 | | | 353 | 7.07k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 12.8M | for (i = j = 0; i < str_len; ) { | 357 | 12.8M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 89.7M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 76.9M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 12.8M | eol = i; | 365 | 12.8M | if (i < str_len) { | 366 | 12.8M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 16.1k | i += 2; | 368 | 12.8M | else | 369 | 12.8M | i++; | 370 | 12.8M | if (keepends) | 371 | 0 | eol = i; | 372 | 12.8M | } | 373 | 12.8M | #if !STRINGLIB_MUTABLE | 374 | 12.8M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 375 | | /* No linebreak in str_obj, so just use it as list[0] */ | 376 | 3.04k | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 3.04k | break; | 379 | 3.04k | } | 380 | 12.8M | #endif | 381 | 25.6M | SPLIT_APPEND(str, j, eol); | 382 | 12.8M | j = i; | 383 | 12.8M | } | 384 | 7.07k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | | return NULL; | 389 | 7.07k | } |
unicodeobject.c:ucs4lib_splitlines Line | Count | Source | 339 | 2.99k | { | 340 | | /* This does not use the preallocated list because splitlines is | 341 | | usually run with hundreds of newlines. The overhead of | 342 | | switching between PyList_SET_ITEM and append causes about a | 343 | | 2-3% slowdown for that common case. A smarter implementation | 344 | | could move the if check out, so the SET_ITEMs are done first | 345 | | and the appends only done when the prealloc buffer is full. | 346 | | That's too much work for little gain.*/ | 347 | | | 348 | 2.99k | Py_ssize_t i; | 349 | 2.99k | Py_ssize_t j; | 350 | 2.99k | PyObject *list = PyList_New(0); | 351 | 2.99k | PyObject *sub; | 352 | | | 353 | 2.99k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 14.2M | for (i = j = 0; i < str_len; ) { | 357 | 14.2M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 114M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 100M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 14.2M | eol = i; | 365 | 14.2M | if (i < str_len) { | 366 | 14.1M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 22.0k | i += 2; | 368 | 14.1M | else | 369 | 14.1M | i++; | 370 | 14.1M | if (keepends) | 371 | 0 | eol = i; | 372 | 14.1M | } | 373 | 14.2M | #if !STRINGLIB_MUTABLE | 374 | 14.2M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 375 | | /* No linebreak in str_obj, so just use it as list[0] */ | 376 | 1.18k | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 1.18k | break; | 379 | 1.18k | } | 380 | 14.2M | #endif | 381 | 28.4M | SPLIT_APPEND(str, j, eol); | 382 | 14.2M | j = i; | 383 | 14.2M | } | 384 | 2.99k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | | return NULL; | 389 | 2.99k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines |
390 | | |