/src/cpython/Objects/stringlib/split.h
Line | Count | Source (jump to first uncovered line) |
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 | 98.1M | #define MAX_PREALLOC 12 |
15 | | |
16 | | /* 5 splits gives 6 elements */ |
17 | | #define PREALLOC_SIZE(maxsplit) \ |
18 | 19.0M | (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1) |
19 | | |
20 | | #define SPLIT_APPEND(data, left, right) \ |
21 | 30.1M | sub = STRINGLIB_NEW((data) + (left), \ |
22 | 30.1M | (right) - (left)); \ |
23 | 30.1M | if (sub == NULL) \ |
24 | 30.1M | goto onError; \ |
25 | 30.1M | if (PyList_Append(list, sub)) { \ |
26 | 0 | Py_DECREF(sub); \ |
27 | 0 | goto onError; \ |
28 | 0 | } \ |
29 | 30.1M | else \ |
30 | 30.1M | Py_DECREF(sub); |
31 | | |
32 | 56.9M | #define SPLIT_ADD(data, left, right) { \ |
33 | 56.9M | sub = STRINGLIB_NEW((data) + (left), \ |
34 | 56.9M | (right) - (left)); \ |
35 | 56.9M | if (sub == NULL) \ |
36 | 56.9M | goto onError; \ |
37 | 56.9M | if (count < MAX_PREALLOC) { \ |
38 | 28.0M | PyList_SET_ITEM(list, count, sub); \ |
39 | 28.9M | } else { \ |
40 | 28.9M | if (PyList_Append(list, sub)) { \ |
41 | 0 | Py_DECREF(sub); \ |
42 | 0 | goto onError; \ |
43 | 0 | } \ |
44 | 28.9M | else \ |
45 | 28.9M | Py_DECREF(sub); \ |
46 | 28.9M | } \ |
47 | 56.9M | count++; } |
48 | | |
49 | | |
50 | | /* Always force the list to the expected size. */ |
51 | 19.0M | #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 | 166k | { |
58 | 166k | Py_ssize_t i, j, count=0; |
59 | 166k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
60 | 166k | PyObject *sub; |
61 | | |
62 | 166k | if (list == NULL) |
63 | 0 | return NULL; |
64 | | |
65 | 166k | i = j = 0; |
66 | 3.02M | while (maxcount-- > 0) { |
67 | 5.92M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
68 | 2.92M | i++; |
69 | 2.99M | if (i == str_len) break; |
70 | 2.90M | j = i; i++; |
71 | 171M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) |
72 | 169M | i++; |
73 | | #if !STRINGLIB_MUTABLE |
74 | 2.90M | 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 | 41.0k | Py_INCREF(str_obj); |
77 | 41.0k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
78 | 41.0k | count++; |
79 | 41.0k | break; |
80 | 41.0k | } |
81 | 2.86M | #endif |
82 | 8.58M | SPLIT_ADD(str, j, i); |
83 | 8.58M | } |
84 | | |
85 | 166k | if (i < str_len) { |
86 | | /* Only occurs when maxcount was reached */ |
87 | | /* Skip any remaining whitespace and copy to end of string */ |
88 | 58.6k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
89 | 31.5k | i++; |
90 | 27.0k | if (i != str_len) |
91 | 27.0k | SPLIT_ADD(str, i, str_len); |
92 | 27.0k | } |
93 | 166k | FIX_PREALLOC_SIZE(list); |
94 | 166k | return list; |
95 | | |
96 | 0 | onError: |
97 | 0 | Py_DECREF(list); |
98 | 0 | return NULL; |
99 | 166k | } Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace unicodeobject.c:asciilib_split_whitespace Line | Count | Source | 57 | 82.8k | { | 58 | 82.8k | Py_ssize_t i, j, count=0; | 59 | 82.8k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 82.8k | PyObject *sub; | 61 | | | 62 | 82.8k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 82.8k | i = j = 0; | 66 | 1.22M | while (maxcount-- > 0) { | 67 | 2.29M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 1.09M | i++; | 69 | 1.20M | if (i == str_len) break; | 70 | 1.16M | j = i; i++; | 71 | 65.5M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 64.3M | i++; | 73 | 1.16M | #if !STRINGLIB_MUTABLE | 74 | 1.16M | 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.2k | Py_INCREF(str_obj); | 77 | 23.2k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 23.2k | count++; | 79 | 23.2k | break; | 80 | 23.2k | } | 81 | 1.13M | #endif | 82 | 3.41M | SPLIT_ADD(str, j, i); | 83 | 3.41M | } | 84 | | | 85 | 82.8k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 27.5k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 14.1k | i++; | 90 | 13.3k | if (i != str_len) | 91 | 13.3k | SPLIT_ADD(str, i, str_len); | 92 | 13.3k | } | 93 | 82.8k | FIX_PREALLOC_SIZE(list); | 94 | 82.8k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | 0 | return NULL; | 99 | 82.8k | } |
unicodeobject.c:ucs1lib_split_whitespace Line | Count | Source | 57 | 26.7k | { | 58 | 26.7k | Py_ssize_t i, j, count=0; | 59 | 26.7k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 26.7k | PyObject *sub; | 61 | | | 62 | 26.7k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 26.7k | i = j = 0; | 66 | 518k | while (maxcount-- > 0) { | 67 | 981k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 476k | i++; | 69 | 504k | if (i == str_len) break; | 70 | 495k | j = i; i++; | 71 | 21.5M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 21.0M | i++; | 73 | 495k | #if !STRINGLIB_MUTABLE | 74 | 495k | 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.63k | Py_INCREF(str_obj); | 77 | 3.63k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 3.63k | count++; | 79 | 3.63k | break; | 80 | 3.63k | } | 81 | 491k | #endif | 82 | 1.47M | SPLIT_ADD(str, j, i); | 83 | 1.47M | } | 84 | | | 85 | 26.7k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 29.4k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 16.5k | i++; | 90 | 12.8k | if (i != str_len) | 91 | 12.8k | SPLIT_ADD(str, i, str_len); | 92 | 12.8k | } | 93 | 26.7k | FIX_PREALLOC_SIZE(list); | 94 | 26.7k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | 0 | return NULL; | 99 | 26.7k | } |
unicodeobject.c:ucs2lib_split_whitespace Line | Count | Source | 57 | 45.6k | { | 58 | 45.6k | Py_ssize_t i, j, count=0; | 59 | 45.6k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 45.6k | PyObject *sub; | 61 | | | 62 | 45.6k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 45.6k | i = j = 0; | 66 | 805k | while (maxcount-- > 0) { | 67 | 1.69M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 886k | i++; | 69 | 804k | if (i == str_len) break; | 70 | 771k | j = i; i++; | 71 | 50.1M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 49.3M | i++; | 73 | 771k | #if !STRINGLIB_MUTABLE | 74 | 771k | 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 | 11.5k | Py_INCREF(str_obj); | 77 | 11.5k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 11.5k | count++; | 79 | 11.5k | break; | 80 | 11.5k | } | 81 | 760k | #endif | 82 | 2.28M | SPLIT_ADD(str, j, i); | 83 | 2.28M | } | 84 | | | 85 | 45.6k | if (i < str_len) { | 86 | | /* Only occurs when maxcount was reached */ | 87 | | /* Skip any remaining whitespace and copy to end of string */ | 88 | 1.65k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 89 | 827 | i++; | 90 | 827 | if (i != str_len) | 91 | 827 | SPLIT_ADD(str, i, str_len); | 92 | 827 | } | 93 | 45.6k | FIX_PREALLOC_SIZE(list); | 94 | 45.6k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | 0 | return NULL; | 99 | 45.6k | } |
unicodeobject.c:ucs4lib_split_whitespace Line | Count | Source | 57 | 10.7k | { | 58 | 10.7k | Py_ssize_t i, j, count=0; | 59 | 10.7k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 60 | 10.7k | PyObject *sub; | 61 | | | 62 | 10.7k | if (list == NULL) | 63 | 0 | return NULL; | 64 | | | 65 | 10.7k | i = j = 0; | 66 | 481k | while (maxcount-- > 0) { | 67 | 955k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 68 | 474k | i++; | 69 | 481k | if (i == str_len) break; | 70 | 473k | j = i; i++; | 71 | 34.8M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 72 | 34.3M | i++; | 73 | 473k | #if !STRINGLIB_MUTABLE | 74 | 473k | 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 | 2.69k | Py_INCREF(str_obj); | 77 | 2.69k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 78 | 2.69k | count++; | 79 | 2.69k | break; | 80 | 2.69k | } | 81 | 471k | #endif | 82 | 1.41M | SPLIT_ADD(str, j, i); | 83 | 1.41M | } | 84 | | | 85 | 10.7k | 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 | 10.7k | FIX_PREALLOC_SIZE(list); | 94 | 10.7k | return list; | 95 | | | 96 | 0 | onError: | 97 | 0 | Py_DECREF(list); | 98 | 0 | return NULL; | 99 | 10.7k | } |
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 | 18.6M | { |
107 | 18.6M | Py_ssize_t i, j, count=0; |
108 | 18.6M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
109 | 18.6M | PyObject *sub; |
110 | | |
111 | 18.6M | if (list == NULL) |
112 | 0 | return NULL; |
113 | | |
114 | 18.6M | i = j = 0; |
115 | 75.9M | while ((j < str_len) && (maxcount-- > 0)) { |
116 | 426M | for(; j < str_len; j++) { |
117 | | /* I found that using memchr makes no difference */ |
118 | 410M | if (str[j] == ch) { |
119 | 40.7M | SPLIT_ADD(str, i, j); |
120 | 40.7M | i = j = j + 1; |
121 | 40.7M | break; |
122 | 40.7M | } |
123 | 410M | } |
124 | 57.2M | } |
125 | | #if !STRINGLIB_MUTABLE |
126 | 18.6M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
127 | | /* ch not in str_obj, so just use str_obj as list[0] */ |
128 | 5.58M | Py_INCREF(str_obj); |
129 | 5.58M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
130 | 5.58M | count++; |
131 | 5.58M | } else |
132 | 13.0M | #endif |
133 | 13.0M | if (i <= str_len) { |
134 | 26.1M | SPLIT_ADD(str, i, str_len); |
135 | 26.1M | } |
136 | 18.6M | FIX_PREALLOC_SIZE(list); |
137 | 18.6M | 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 | 2.77M | { | 107 | 2.77M | Py_ssize_t i, j, count=0; | 108 | 2.77M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 2.77M | PyObject *sub; | 110 | | | 111 | 2.77M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 2.77M | i = j = 0; | 115 | 10.0M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 62.9M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 60.6M | if (str[j] == ch) { | 119 | 4.95M | SPLIT_ADD(str, i, j); | 120 | 4.95M | i = j = j + 1; | 121 | 4.95M | break; | 122 | 4.95M | } | 123 | 60.6M | } | 124 | 7.24M | } | 125 | 2.77M | #if !STRINGLIB_MUTABLE | 126 | 2.77M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 2.20M | Py_INCREF(str_obj); | 129 | 2.20M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 2.20M | count++; | 131 | 2.20M | } else | 132 | 571k | #endif | 133 | 571k | if (i <= str_len) { | 134 | 1.14M | SPLIT_ADD(str, i, str_len); | 135 | 1.14M | } | 136 | 2.77M | FIX_PREALLOC_SIZE(list); | 137 | 2.77M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | 0 | return NULL; | 142 | 2.77M | } |
unicodeobject.c:asciilib_split_char Line | Count | Source | 106 | 14.7M | { | 107 | 14.7M | Py_ssize_t i, j, count=0; | 108 | 14.7M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 14.7M | PyObject *sub; | 110 | | | 111 | 14.7M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 14.7M | i = j = 0; | 115 | 54.0M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 215M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 201M | if (str[j] == ch) { | 119 | 25.2M | SPLIT_ADD(str, i, j); | 120 | 25.2M | i = j = j + 1; | 121 | 25.2M | break; | 122 | 25.2M | } | 123 | 201M | } | 124 | 39.3M | } | 125 | 14.7M | #if !STRINGLIB_MUTABLE | 126 | 14.7M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 3.25M | Py_INCREF(str_obj); | 129 | 3.25M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 3.25M | count++; | 131 | 3.25M | } else | 132 | 11.4M | #endif | 133 | 11.4M | if (i <= str_len) { | 134 | 22.9M | SPLIT_ADD(str, i, str_len); | 135 | 22.9M | } | 136 | 14.7M | FIX_PREALLOC_SIZE(list); | 137 | 14.7M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | 0 | return NULL; | 142 | 14.7M | } |
unicodeobject.c:ucs1lib_split_char Line | Count | Source | 106 | 1.07M | { | 107 | 1.07M | Py_ssize_t i, j, count=0; | 108 | 1.07M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 1.07M | PyObject *sub; | 110 | | | 111 | 1.07M | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 1.07M | i = j = 0; | 115 | 8.26M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 44.3M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 44.1M | if (str[j] == ch) { | 119 | 7.04M | SPLIT_ADD(str, i, j); | 120 | 7.04M | i = j = j + 1; | 121 | 7.04M | break; | 122 | 7.04M | } | 123 | 44.1M | } | 124 | 7.18M | } | 125 | 1.07M | #if !STRINGLIB_MUTABLE | 126 | 1.07M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 122k | Py_INCREF(str_obj); | 129 | 122k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 122k | count++; | 131 | 122k | } else | 132 | 949k | #endif | 133 | 949k | if (i <= str_len) { | 134 | 1.89M | SPLIT_ADD(str, i, str_len); | 135 | 1.89M | } | 136 | 1.07M | FIX_PREALLOC_SIZE(list); | 137 | 1.07M | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | 0 | return NULL; | 142 | 1.07M | } |
unicodeobject.c:ucs2lib_split_char Line | Count | Source | 106 | 81.7k | { | 107 | 81.7k | Py_ssize_t i, j, count=0; | 108 | 81.7k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 81.7k | PyObject *sub; | 110 | | | 111 | 81.7k | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 81.7k | i = j = 0; | 115 | 3.13M | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 56.8M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 56.7M | if (str[j] == ch) { | 119 | 3.00M | SPLIT_ADD(str, i, j); | 120 | 3.00M | i = j = j + 1; | 121 | 3.00M | break; | 122 | 3.00M | } | 123 | 56.7M | } | 124 | 3.05M | } | 125 | 81.7k | #if !STRINGLIB_MUTABLE | 126 | 81.7k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 6.32k | Py_INCREF(str_obj); | 129 | 6.32k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 6.32k | count++; | 131 | 6.32k | } else | 132 | 75.4k | #endif | 133 | 75.4k | if (i <= str_len) { | 134 | 150k | SPLIT_ADD(str, i, str_len); | 135 | 150k | } | 136 | 81.7k | FIX_PREALLOC_SIZE(list); | 137 | 81.7k | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | 0 | return NULL; | 142 | 81.7k | } |
unicodeobject.c:ucs4lib_split_char Line | Count | Source | 106 | 15.1k | { | 107 | 15.1k | Py_ssize_t i, j, count=0; | 108 | 15.1k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 109 | 15.1k | PyObject *sub; | 110 | | | 111 | 15.1k | if (list == NULL) | 112 | 0 | return NULL; | 113 | | | 114 | 15.1k | i = j = 0; | 115 | 487k | while ((j < str_len) && (maxcount-- > 0)) { | 116 | 47.4M | for(; j < str_len; j++) { | 117 | | /* I found that using memchr makes no difference */ | 118 | 47.4M | if (str[j] == ch) { | 119 | 460k | SPLIT_ADD(str, i, j); | 120 | 460k | i = j = j + 1; | 121 | 460k | break; | 122 | 460k | } | 123 | 47.4M | } | 124 | 472k | } | 125 | 15.1k | #if !STRINGLIB_MUTABLE | 126 | 15.1k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 127 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 128 | 374 | Py_INCREF(str_obj); | 129 | 374 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 130 | 374 | count++; | 131 | 374 | } else | 132 | 14.7k | #endif | 133 | 14.7k | if (i <= str_len) { | 134 | 29.4k | SPLIT_ADD(str, i, str_len); | 135 | 29.4k | } | 136 | 15.1k | FIX_PREALLOC_SIZE(list); | 137 | 15.1k | return list; | 138 | | | 139 | 0 | onError: | 140 | 0 | Py_DECREF(list); | 141 | 0 | return NULL; | 142 | 15.1k | } |
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 | 18.8M | { |
150 | 18.8M | Py_ssize_t i, j, pos, count=0; |
151 | 18.8M | PyObject *list, *sub; |
152 | | |
153 | 18.8M | if (sep_len == 0) { |
154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
155 | 0 | return NULL; |
156 | 0 | } |
157 | 18.8M | else if (sep_len == 1) |
158 | 18.6M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); |
159 | | |
160 | 198k | list = PyList_New(PREALLOC_SIZE(maxcount)); |
161 | 198k | if (list == NULL) |
162 | 0 | return NULL; |
163 | | |
164 | 198k | i = j = 0; |
165 | 355k | while (maxcount-- > 0) { |
166 | 198k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); |
167 | 198k | if (pos < 0) |
168 | 41.8k | break; |
169 | 156k | j = i + pos; |
170 | 313k | SPLIT_ADD(str, i, j); |
171 | 313k | i = j + sep_len; |
172 | 313k | } |
173 | | #if !STRINGLIB_MUTABLE |
174 | 198k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
175 | | /* No match in str_obj, so just use it as list[0] */ |
176 | 41.8k | Py_INCREF(str_obj); |
177 | 41.8k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
178 | 41.8k | count++; |
179 | 41.8k | } else |
180 | 156k | #endif |
181 | 156k | { |
182 | 313k | SPLIT_ADD(str, i, str_len); |
183 | 313k | } |
184 | 198k | FIX_PREALLOC_SIZE(list); |
185 | 198k | 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 | 2.77M | { | 150 | 2.77M | Py_ssize_t i, j, pos, count=0; | 151 | 2.77M | PyObject *list, *sub; | 152 | | | 153 | 2.77M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 2.77M | else if (sep_len == 1) | 158 | 2.77M | 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 | 0 | return NULL; | 190 | 0 | } |
unicodeobject.c:asciilib_split Line | Count | Source | 149 | 14.8M | { | 150 | 14.8M | Py_ssize_t i, j, pos, count=0; | 151 | 14.8M | PyObject *list, *sub; | 152 | | | 153 | 14.8M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 14.8M | else if (sep_len == 1) | 158 | 14.7M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 90.2k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 90.2k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 90.2k | i = j = 0; | 165 | 149k | while (maxcount-- > 0) { | 166 | 90.2k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 90.2k | if (pos < 0) | 168 | 31.3k | break; | 169 | 58.8k | j = i + pos; | 170 | 117k | SPLIT_ADD(str, i, j); | 171 | 117k | i = j + sep_len; | 172 | 117k | } | 173 | 90.2k | #if !STRINGLIB_MUTABLE | 174 | 90.2k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 31.3k | Py_INCREF(str_obj); | 177 | 31.3k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 31.3k | count++; | 179 | 31.3k | } else | 180 | 58.8k | #endif | 181 | 58.8k | { | 182 | 117k | SPLIT_ADD(str, i, str_len); | 183 | 117k | } | 184 | 90.2k | FIX_PREALLOC_SIZE(list); | 185 | 90.2k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | 0 | return NULL; | 190 | 90.2k | } |
unicodeobject.c:ucs1lib_split Line | Count | Source | 149 | 1.08M | { | 150 | 1.08M | Py_ssize_t i, j, pos, count=0; | 151 | 1.08M | PyObject *list, *sub; | 152 | | | 153 | 1.08M | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 1.08M | else if (sep_len == 1) | 158 | 1.07M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 11.3k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 11.3k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 11.3k | i = j = 0; | 165 | 21.8k | while (maxcount-- > 0) { | 166 | 11.3k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 11.3k | if (pos < 0) | 168 | 755 | break; | 169 | 10.5k | j = i + pos; | 170 | 21.1k | SPLIT_ADD(str, i, j); | 171 | 21.1k | i = j + sep_len; | 172 | 21.1k | } | 173 | 11.3k | #if !STRINGLIB_MUTABLE | 174 | 11.3k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 755 | Py_INCREF(str_obj); | 177 | 755 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 755 | count++; | 179 | 755 | } else | 180 | 10.5k | #endif | 181 | 10.5k | { | 182 | 21.1k | SPLIT_ADD(str, i, str_len); | 183 | 21.1k | } | 184 | 11.3k | FIX_PREALLOC_SIZE(list); | 185 | 11.3k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | 0 | return NULL; | 190 | 11.3k | } |
unicodeobject.c:ucs2lib_split Line | Count | Source | 149 | 160k | { | 150 | 160k | Py_ssize_t i, j, pos, count=0; | 151 | 160k | PyObject *list, *sub; | 152 | | | 153 | 160k | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 160k | else if (sep_len == 1) | 158 | 81.7k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 79.1k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 79.1k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 79.1k | i = j = 0; | 165 | 150k | while (maxcount-- > 0) { | 166 | 79.1k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 79.1k | if (pos < 0) | 168 | 7.55k | break; | 169 | 71.6k | j = i + pos; | 170 | 143k | SPLIT_ADD(str, i, j); | 171 | 143k | i = j + sep_len; | 172 | 143k | } | 173 | 79.1k | #if !STRINGLIB_MUTABLE | 174 | 79.1k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 7.55k | Py_INCREF(str_obj); | 177 | 7.55k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 7.55k | count++; | 179 | 7.55k | } else | 180 | 71.6k | #endif | 181 | 71.6k | { | 182 | 143k | SPLIT_ADD(str, i, str_len); | 183 | 143k | } | 184 | 79.1k | FIX_PREALLOC_SIZE(list); | 185 | 79.1k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | 0 | return NULL; | 190 | 79.1k | } |
unicodeobject.c:ucs4lib_split Line | Count | Source | 149 | 32.9k | { | 150 | 32.9k | Py_ssize_t i, j, pos, count=0; | 151 | 32.9k | PyObject *list, *sub; | 152 | | | 153 | 32.9k | if (sep_len == 0) { | 154 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 155 | 0 | return NULL; | 156 | 0 | } | 157 | 32.9k | else if (sep_len == 1) | 158 | 15.1k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 159 | | | 160 | 17.7k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 161 | 17.7k | if (list == NULL) | 162 | 0 | return NULL; | 163 | | | 164 | 17.7k | i = j = 0; | 165 | 33.4k | while (maxcount-- > 0) { | 166 | 17.7k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 167 | 17.7k | if (pos < 0) | 168 | 2.13k | break; | 169 | 15.6k | j = i + pos; | 170 | 31.3k | SPLIT_ADD(str, i, j); | 171 | 31.3k | i = j + sep_len; | 172 | 31.3k | } | 173 | 17.7k | #if !STRINGLIB_MUTABLE | 174 | 17.7k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 175 | | /* No match in str_obj, so just use it as list[0] */ | 176 | 2.13k | Py_INCREF(str_obj); | 177 | 2.13k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 178 | 2.13k | count++; | 179 | 2.13k | } else | 180 | 15.6k | #endif | 181 | 15.6k | { | 182 | 31.3k | SPLIT_ADD(str, i, str_len); | 183 | 31.3k | } | 184 | 17.7k | FIX_PREALLOC_SIZE(list); | 185 | 17.7k | return list; | 186 | | | 187 | 0 | onError: | 188 | 0 | Py_DECREF(list); | 189 | 0 | return NULL; | 190 | 17.7k | } |
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 | 0 | 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 | 0 | 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.8k | { |
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.8k | Py_ssize_t i; |
349 | 13.8k | Py_ssize_t j; |
350 | 13.8k | PyObject *list = PyList_New(0); |
351 | 13.8k | PyObject *sub; |
352 | | |
353 | 13.8k | if (list == NULL) |
354 | 0 | return NULL; |
355 | | |
356 | 30.1M | for (i = j = 0; i < str_len; ) { |
357 | 30.1M | Py_ssize_t eol; |
358 | | |
359 | | /* Find a line and append it */ |
360 | 256M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) |
361 | 226M | i++; |
362 | | |
363 | | /* Skip the line break reading CRLF as one line break */ |
364 | 30.1M | eol = i; |
365 | 30.1M | if (i < str_len) { |
366 | 30.1M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') |
367 | 61.2k | i += 2; |
368 | 30.1M | else |
369 | 30.1M | i++; |
370 | 30.1M | if (keepends) |
371 | 0 | eol = i; |
372 | 30.1M | } |
373 | | #if !STRINGLIB_MUTABLE |
374 | 30.1M | 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.38k | if (PyList_Append(list, str_obj)) |
377 | 0 | goto onError; |
378 | 5.38k | break; |
379 | 5.38k | } |
380 | 30.1M | #endif |
381 | 60.3M | SPLIT_APPEND(str, j, eol); |
382 | 30.1M | j = i; |
383 | 30.1M | } |
384 | 13.8k | return list; |
385 | | |
386 | 0 | onError: |
387 | 0 | Py_DECREF(list); |
388 | 0 | return NULL; |
389 | 13.8k | } Unexecuted instantiation: bytesobject.c:stringlib_splitlines unicodeobject.c:asciilib_splitlines Line | Count | Source | 339 | 2.73k | { | 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.73k | Py_ssize_t i; | 349 | 2.73k | Py_ssize_t j; | 350 | 2.73k | PyObject *list = PyList_New(0); | 351 | 2.73k | PyObject *sub; | 352 | | | 353 | 2.73k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 8.26M | for (i = j = 0; i < str_len; ) { | 357 | 8.26M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 46.6M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 38.3M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 8.26M | eol = i; | 365 | 8.26M | if (i < str_len) { | 366 | 8.26M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 8.74k | i += 2; | 368 | 8.25M | else | 369 | 8.25M | i++; | 370 | 8.26M | if (keepends) | 371 | 0 | eol = i; | 372 | 8.26M | } | 373 | 8.26M | #if !STRINGLIB_MUTABLE | 374 | 8.26M | 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.00k | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 1.00k | break; | 379 | 1.00k | } | 380 | 8.26M | #endif | 381 | 16.5M | SPLIT_APPEND(str, j, eol); | 382 | 8.26M | j = i; | 383 | 8.26M | } | 384 | 2.73k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | 0 | return NULL; | 389 | 2.73k | } |
unicodeobject.c:ucs1lib_splitlines Line | Count | Source | 339 | 842 | { | 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 | 842 | Py_ssize_t i; | 349 | 842 | Py_ssize_t j; | 350 | 842 | PyObject *list = PyList_New(0); | 351 | 842 | PyObject *sub; | 352 | | | 353 | 842 | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 1.04M | for (i = j = 0; i < str_len; ) { | 357 | 1.04M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 9.42M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 8.37M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 1.04M | eol = i; | 365 | 1.04M | if (i < str_len) { | 366 | 1.04M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 1.29k | i += 2; | 368 | 1.04M | else | 369 | 1.04M | i++; | 370 | 1.04M | if (keepends) | 371 | 0 | eol = i; | 372 | 1.04M | } | 373 | 1.04M | #if !STRINGLIB_MUTABLE | 374 | 1.04M | 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 | 212 | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 212 | break; | 379 | 212 | } | 380 | 1.04M | #endif | 381 | 2.09M | SPLIT_APPEND(str, j, eol); | 382 | 1.04M | j = i; | 383 | 1.04M | } | 384 | 842 | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | 0 | return NULL; | 389 | 842 | } |
unicodeobject.c:ucs2lib_splitlines Line | Count | Source | 339 | 7.21k | { | 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.21k | Py_ssize_t i; | 349 | 7.21k | Py_ssize_t j; | 350 | 7.21k | PyObject *list = PyList_New(0); | 351 | 7.21k | PyObject *sub; | 352 | | | 353 | 7.21k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 9.15M | for (i = j = 0; i < str_len; ) { | 357 | 9.15M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 96.2M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 87.0M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 9.15M | eol = i; | 365 | 9.15M | if (i < str_len) { | 366 | 9.14M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 21.0k | i += 2; | 368 | 9.12M | else | 369 | 9.12M | i++; | 370 | 9.14M | if (keepends) | 371 | 0 | eol = i; | 372 | 9.14M | } | 373 | 9.15M | #if !STRINGLIB_MUTABLE | 374 | 9.15M | 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.00k | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 3.00k | break; | 379 | 3.00k | } | 380 | 9.15M | #endif | 381 | 18.3M | SPLIT_APPEND(str, j, eol); | 382 | 9.15M | j = i; | 383 | 9.15M | } | 384 | 7.21k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | 0 | return NULL; | 389 | 7.21k | } |
unicodeobject.c:ucs4lib_splitlines Line | Count | Source | 339 | 3.10k | { | 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 | 3.10k | Py_ssize_t i; | 349 | 3.10k | Py_ssize_t j; | 350 | 3.10k | PyObject *list = PyList_New(0); | 351 | 3.10k | PyObject *sub; | 352 | | | 353 | 3.10k | if (list == NULL) | 354 | 0 | return NULL; | 355 | | | 356 | 11.7M | for (i = j = 0; i < str_len; ) { | 357 | 11.7M | Py_ssize_t eol; | 358 | | | 359 | | /* Find a line and append it */ | 360 | 103M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 361 | 92.2M | i++; | 362 | | | 363 | | /* Skip the line break reading CRLF as one line break */ | 364 | 11.7M | eol = i; | 365 | 11.7M | if (i < str_len) { | 366 | 11.7M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 367 | 30.1k | i += 2; | 368 | 11.6M | else | 369 | 11.6M | i++; | 370 | 11.7M | if (keepends) | 371 | 0 | eol = i; | 372 | 11.7M | } | 373 | 11.7M | #if !STRINGLIB_MUTABLE | 374 | 11.7M | 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.16k | if (PyList_Append(list, str_obj)) | 377 | 0 | goto onError; | 378 | 1.16k | break; | 379 | 1.16k | } | 380 | 11.7M | #endif | 381 | 23.4M | SPLIT_APPEND(str, j, eol); | 382 | 11.7M | j = i; | 383 | 11.7M | } | 384 | 3.10k | return list; | 385 | | | 386 | 0 | onError: | 387 | 0 | Py_DECREF(list); | 388 | 0 | return NULL; | 389 | 3.10k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines |
390 | | |