/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 | | #include "pycore_list.h" // _PyList_AppendTakeRef() |
8 | | |
9 | | /* Overallocate the initial list to reduce the number of reallocs for small |
10 | | split sizes. Eg, "A A A A A A A A A A".split() (10 elements) has three |
11 | | resizes, to sizes 4, 8, then 16. Most observed string splits are for human |
12 | | text (roughly 11 words per line) and field delimited data (usually 1-10 |
13 | | fields). For large strings the split algorithms are bandwidth limited |
14 | | so increasing the preallocation likely will not improve things.*/ |
15 | | |
16 | 120M | #define MAX_PREALLOC 12 |
17 | | |
18 | | /* 5 splits gives 6 elements */ |
19 | | #define PREALLOC_SIZE(maxsplit) \ |
20 | 22.7M | (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1) |
21 | | |
22 | | #define SPLIT_APPEND(data, left, right) \ |
23 | 44.8M | sub = STRINGLIB_NEW((data) + (left), \ |
24 | 44.8M | (right) - (left)); \ |
25 | 44.8M | if (sub == NULL) \ |
26 | 44.8M | goto onError; \ |
27 | 44.8M | if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \ |
28 | 44.8M | goto onError; |
29 | | |
30 | 71.7M | #define SPLIT_ADD(data, left, right) { \ |
31 | 71.7M | sub = STRINGLIB_NEW((data) + (left), \ |
32 | 71.7M | (right) - (left)); \ |
33 | 71.7M | if (sub == NULL) \ |
34 | 71.7M | goto onError; \ |
35 | 71.7M | if (count < MAX_PREALLOC) { \ |
36 | 35.8M | PyList_SET_ITEM(list, count, sub); \ |
37 | 35.8M | } else { \ |
38 | 35.8M | if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \ |
39 | 35.8M | goto onError; \ |
40 | 35.8M | } \ |
41 | 71.7M | count++; } |
42 | | |
43 | | |
44 | | /* Always force the list to the expected size. */ |
45 | 22.7M | #define FIX_PREALLOC_SIZE(list) Py_SET_SIZE(list, count) |
46 | | |
47 | | Py_LOCAL_INLINE(PyObject *) |
48 | | STRINGLIB(split_whitespace)(PyObject* str_obj, |
49 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
50 | | Py_ssize_t maxcount) |
51 | 174k | { |
52 | 174k | Py_ssize_t i, j, count=0; |
53 | 174k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
54 | 174k | PyObject *sub; |
55 | | |
56 | 174k | if (list == NULL) |
57 | 0 | return NULL; |
58 | | |
59 | 174k | i = j = 0; |
60 | 2.07M | while (maxcount-- > 0) { |
61 | 3.98M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
62 | 1.93M | i++; |
63 | 2.04M | if (i == str_len) break; |
64 | 1.93M | j = i; i++; |
65 | 144M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) |
66 | 142M | i++; |
67 | | #if !STRINGLIB_MUTABLE |
68 | 1.93M | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { |
69 | | /* No whitespace in str_obj, so just use it as list[0] */ |
70 | 39.3k | Py_INCREF(str_obj); |
71 | 39.3k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
72 | 39.3k | count++; |
73 | 39.3k | break; |
74 | 39.3k | } |
75 | 1.89M | #endif |
76 | 5.68M | SPLIT_ADD(str, j, i); |
77 | 5.68M | } |
78 | | |
79 | 174k | if (i < str_len) { |
80 | | /* Only occurs when maxcount was reached */ |
81 | | /* Skip any remaining whitespace and copy to end of string */ |
82 | 44.1k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) |
83 | 23.6k | i++; |
84 | 20.5k | if (i != str_len) |
85 | 20.5k | SPLIT_ADD(str, i, str_len); |
86 | 20.5k | } |
87 | 174k | FIX_PREALLOC_SIZE(list); |
88 | 174k | return list; |
89 | | |
90 | 0 | onError: |
91 | 0 | Py_DECREF(list); |
92 | 0 | return NULL; |
93 | 174k | } Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace unicodeobject.c:asciilib_split_whitespace Line | Count | Source | 51 | 72.0k | { | 52 | 72.0k | Py_ssize_t i, j, count=0; | 53 | 72.0k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 54 | 72.0k | PyObject *sub; | 55 | | | 56 | 72.0k | if (list == NULL) | 57 | 0 | return NULL; | 58 | | | 59 | 72.0k | i = j = 0; | 60 | 562k | while (maxcount-- > 0) { | 61 | 1.01M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 62 | 463k | i++; | 63 | 546k | if (i == str_len) break; | 64 | 511k | j = i; i++; | 65 | 43.0M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 66 | 42.4M | i++; | 67 | 511k | #if !STRINGLIB_MUTABLE | 68 | 511k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 69 | | /* No whitespace in str_obj, so just use it as list[0] */ | 70 | 20.8k | Py_INCREF(str_obj); | 71 | 20.8k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 72 | 20.8k | count++; | 73 | 20.8k | break; | 74 | 20.8k | } | 75 | 490k | #endif | 76 | 1.47M | SPLIT_ADD(str, j, i); | 77 | 1.47M | } | 78 | | | 79 | 72.0k | if (i < str_len) { | 80 | | /* Only occurs when maxcount was reached */ | 81 | | /* Skip any remaining whitespace and copy to end of string */ | 82 | 26.7k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 83 | 13.9k | i++; | 84 | 12.8k | if (i != str_len) | 85 | 12.8k | SPLIT_ADD(str, i, str_len); | 86 | 12.8k | } | 87 | 72.0k | FIX_PREALLOC_SIZE(list); | 88 | 72.0k | return list; | 89 | | | 90 | 0 | onError: | 91 | 0 | Py_DECREF(list); | 92 | | return NULL; | 93 | 72.0k | } |
unicodeobject.c:ucs1lib_split_whitespace Line | Count | Source | 51 | 25.5k | { | 52 | 25.5k | Py_ssize_t i, j, count=0; | 53 | 25.5k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 54 | 25.5k | PyObject *sub; | 55 | | | 56 | 25.5k | if (list == NULL) | 57 | 0 | return NULL; | 58 | | | 59 | 25.5k | i = j = 0; | 60 | 741k | while (maxcount-- > 0) { | 61 | 1.43M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 62 | 703k | i++; | 63 | 734k | if (i == str_len) break; | 64 | 718k | j = i; i++; | 65 | 46.3M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 66 | 45.6M | i++; | 67 | 718k | #if !STRINGLIB_MUTABLE | 68 | 718k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 69 | | /* No whitespace in str_obj, so just use it as list[0] */ | 70 | 2.42k | Py_INCREF(str_obj); | 71 | 2.42k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 72 | 2.42k | count++; | 73 | 2.42k | break; | 74 | 2.42k | } | 75 | 716k | #endif | 76 | 2.14M | SPLIT_ADD(str, j, i); | 77 | 2.14M | } | 78 | | | 79 | 25.5k | if (i < str_len) { | 80 | | /* Only occurs when maxcount was reached */ | 81 | | /* Skip any remaining whitespace and copy to end of string */ | 82 | 15.7k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 83 | 8.87k | i++; | 84 | 6.91k | if (i != str_len) | 85 | 6.91k | SPLIT_ADD(str, i, str_len); | 86 | 6.91k | } | 87 | 25.5k | FIX_PREALLOC_SIZE(list); | 88 | 25.5k | return list; | 89 | | | 90 | 0 | onError: | 91 | 0 | Py_DECREF(list); | 92 | | return NULL; | 93 | 25.5k | } |
unicodeobject.c:ucs2lib_split_whitespace Line | Count | Source | 51 | 63.7k | { | 52 | 63.7k | Py_ssize_t i, j, count=0; | 53 | 63.7k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 54 | 63.7k | PyObject *sub; | 55 | | | 56 | 63.7k | if (list == NULL) | 57 | 0 | return NULL; | 58 | | | 59 | 63.7k | i = j = 0; | 60 | 597k | while (maxcount-- > 0) { | 61 | 1.20M | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 62 | 606k | i++; | 63 | 596k | if (i == str_len) break; | 64 | 546k | j = i; i++; | 65 | 40.3M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 66 | 39.8M | i++; | 67 | 546k | #if !STRINGLIB_MUTABLE | 68 | 546k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 69 | | /* No whitespace in str_obj, so just use it as list[0] */ | 70 | 12.6k | Py_INCREF(str_obj); | 71 | 12.6k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 72 | 12.6k | count++; | 73 | 12.6k | break; | 74 | 12.6k | } | 75 | 533k | #endif | 76 | 1.60M | SPLIT_ADD(str, j, i); | 77 | 1.60M | } | 78 | | | 79 | 63.7k | if (i < str_len) { | 80 | | /* Only occurs when maxcount was reached */ | 81 | | /* Skip any remaining whitespace and copy to end of string */ | 82 | 1.58k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 83 | 793 | i++; | 84 | 793 | if (i != str_len) | 85 | 793 | SPLIT_ADD(str, i, str_len); | 86 | 793 | } | 87 | 63.7k | FIX_PREALLOC_SIZE(list); | 88 | 63.7k | return list; | 89 | | | 90 | 0 | onError: | 91 | 0 | Py_DECREF(list); | 92 | | return NULL; | 93 | 63.7k | } |
unicodeobject.c:ucs4lib_split_whitespace Line | Count | Source | 51 | 13.4k | { | 52 | 13.4k | Py_ssize_t i, j, count=0; | 53 | 13.4k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 54 | 13.4k | PyObject *sub; | 55 | | | 56 | 13.4k | if (list == NULL) | 57 | 0 | return NULL; | 58 | | | 59 | 13.4k | i = j = 0; | 60 | 169k | while (maxcount-- > 0) { | 61 | 333k | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 62 | 164k | i++; | 63 | 168k | if (i == str_len) break; | 64 | 159k | j = i; i++; | 65 | 14.7M | while (i < str_len && !STRINGLIB_ISSPACE(str[i])) | 66 | 14.5M | i++; | 67 | 159k | #if !STRINGLIB_MUTABLE | 68 | 159k | if (j == 0 && i == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 69 | | /* No whitespace in str_obj, so just use it as list[0] */ | 70 | 3.38k | Py_INCREF(str_obj); | 71 | 3.38k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 72 | 3.38k | count++; | 73 | 3.38k | break; | 74 | 3.38k | } | 75 | 155k | #endif | 76 | 467k | SPLIT_ADD(str, j, i); | 77 | 467k | } | 78 | | | 79 | 13.4k | if (i < str_len) { | 80 | | /* Only occurs when maxcount was reached */ | 81 | | /* Skip any remaining whitespace and copy to end of string */ | 82 | 0 | while (i < str_len && STRINGLIB_ISSPACE(str[i])) | 83 | 0 | i++; | 84 | 0 | if (i != str_len) | 85 | 0 | SPLIT_ADD(str, i, str_len); | 86 | 0 | } | 87 | 13.4k | FIX_PREALLOC_SIZE(list); | 88 | 13.4k | return list; | 89 | | | 90 | 0 | onError: | 91 | 0 | Py_DECREF(list); | 92 | | return NULL; | 93 | 13.4k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split_whitespace |
94 | | |
95 | | Py_LOCAL_INLINE(PyObject *) |
96 | | STRINGLIB(split_char)(PyObject* str_obj, |
97 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
98 | | const STRINGLIB_CHAR ch, |
99 | | Py_ssize_t maxcount) |
100 | 22.3M | { |
101 | 22.3M | Py_ssize_t i, j, count=0; |
102 | 22.3M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
103 | 22.3M | PyObject *sub; |
104 | | |
105 | 22.3M | if (list == NULL) |
106 | 0 | return NULL; |
107 | | |
108 | 22.3M | i = j = 0; |
109 | 95.1M | while ((j < str_len) && (maxcount-- > 0)) { |
110 | 512M | for(; j < str_len; j++) { |
111 | | /* I found that using memchr makes no difference */ |
112 | 492M | if (str[j] == ch) { |
113 | 52.6M | SPLIT_ADD(str, i, j); |
114 | 52.6M | i = j = j + 1; |
115 | 52.6M | break; |
116 | 52.6M | } |
117 | 492M | } |
118 | 72.8M | } |
119 | | #if !STRINGLIB_MUTABLE |
120 | 22.3M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
121 | | /* ch not in str_obj, so just use str_obj as list[0] */ |
122 | 5.41M | Py_INCREF(str_obj); |
123 | 5.41M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
124 | 5.41M | count++; |
125 | 5.41M | } else |
126 | 16.8M | #endif |
127 | 16.8M | if (i <= str_len) { |
128 | 33.7M | SPLIT_ADD(str, i, str_len); |
129 | 33.7M | } |
130 | 22.3M | FIX_PREALLOC_SIZE(list); |
131 | 22.3M | return list; |
132 | | |
133 | 0 | onError: |
134 | 0 | Py_DECREF(list); |
135 | 0 | return NULL; |
136 | 0 | } bytesobject.c:stringlib_split_char Line | Count | Source | 100 | 2.89M | { | 101 | 2.89M | Py_ssize_t i, j, count=0; | 102 | 2.89M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 103 | 2.89M | PyObject *sub; | 104 | | | 105 | 2.89M | if (list == NULL) | 106 | 0 | return NULL; | 107 | | | 108 | 2.89M | i = j = 0; | 109 | 21.9M | while ((j < str_len) && (maxcount-- > 0)) { | 110 | 132M | for(; j < str_len; j++) { | 111 | | /* I found that using memchr makes no difference */ | 112 | 129M | if (str[j] == ch) { | 113 | 16.5M | SPLIT_ADD(str, i, j); | 114 | 16.5M | i = j = j + 1; | 115 | 16.5M | break; | 116 | 16.5M | } | 117 | 129M | } | 118 | 19.0M | } | 119 | 2.89M | #if !STRINGLIB_MUTABLE | 120 | 2.89M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 121 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 122 | 2.41M | Py_INCREF(str_obj); | 123 | 2.41M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 124 | 2.41M | count++; | 125 | 2.41M | } else | 126 | 481k | #endif | 127 | 481k | if (i <= str_len) { | 128 | 962k | SPLIT_ADD(str, i, str_len); | 129 | 962k | } | 130 | 2.89M | FIX_PREALLOC_SIZE(list); | 131 | 2.89M | return list; | 132 | | | 133 | 0 | onError: | 134 | 0 | Py_DECREF(list); | 135 | | return NULL; | 136 | 2.89M | } |
unicodeobject.c:asciilib_split_char Line | Count | Source | 100 | 18.1M | { | 101 | 18.1M | Py_ssize_t i, j, count=0; | 102 | 18.1M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 103 | 18.1M | PyObject *sub; | 104 | | | 105 | 18.1M | if (list == NULL) | 106 | 0 | return NULL; | 107 | | | 108 | 18.1M | i = j = 0; | 109 | 56.1M | while ((j < str_len) && (maxcount-- > 0)) { | 110 | 235M | for(; j < str_len; j++) { | 111 | | /* I found that using memchr makes no difference */ | 112 | 217M | if (str[j] == ch) { | 113 | 20.5M | SPLIT_ADD(str, i, j); | 114 | 20.5M | i = j = j + 1; | 115 | 20.5M | break; | 116 | 20.5M | } | 117 | 217M | } | 118 | 37.9M | } | 119 | 18.1M | #if !STRINGLIB_MUTABLE | 120 | 18.1M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 121 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 122 | 2.80M | Py_INCREF(str_obj); | 123 | 2.80M | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 124 | 2.80M | count++; | 125 | 2.80M | } else | 126 | 15.3M | #endif | 127 | 15.3M | if (i <= str_len) { | 128 | 30.6M | SPLIT_ADD(str, i, str_len); | 129 | 30.6M | } | 130 | 18.1M | FIX_PREALLOC_SIZE(list); | 131 | 18.1M | return list; | 132 | | | 133 | 0 | onError: | 134 | 0 | Py_DECREF(list); | 135 | | return NULL; | 136 | 18.1M | } |
unicodeobject.c:ucs1lib_split_char Line | Count | Source | 100 | 1.15M | { | 101 | 1.15M | Py_ssize_t i, j, count=0; | 102 | 1.15M | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 103 | 1.15M | PyObject *sub; | 104 | | | 105 | 1.15M | if (list == NULL) | 106 | 0 | return NULL; | 107 | | | 108 | 1.15M | i = j = 0; | 109 | 11.3M | while ((j < str_len) && (maxcount-- > 0)) { | 110 | 70.3M | for(; j < str_len; j++) { | 111 | | /* I found that using memchr makes no difference */ | 112 | 70.1M | if (str[j] == ch) { | 113 | 9.98M | SPLIT_ADD(str, i, j); | 114 | 9.98M | i = j = j + 1; | 115 | 9.98M | break; | 116 | 9.98M | } | 117 | 70.1M | } | 118 | 10.1M | } | 119 | 1.15M | #if !STRINGLIB_MUTABLE | 120 | 1.15M | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 121 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 122 | 168k | Py_INCREF(str_obj); | 123 | 168k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 124 | 168k | count++; | 125 | 168k | } else | 126 | 984k | #endif | 127 | 984k | if (i <= str_len) { | 128 | 1.96M | SPLIT_ADD(str, i, str_len); | 129 | 1.96M | } | 130 | 1.15M | FIX_PREALLOC_SIZE(list); | 131 | 1.15M | return list; | 132 | | | 133 | 0 | onError: | 134 | 0 | Py_DECREF(list); | 135 | | return NULL; | 136 | 1.15M | } |
unicodeobject.c:ucs2lib_split_char Line | Count | Source | 100 | 128k | { | 101 | 128k | Py_ssize_t i, j, count=0; | 102 | 128k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 103 | 128k | PyObject *sub; | 104 | | | 105 | 128k | if (list == NULL) | 106 | 0 | return NULL; | 107 | | | 108 | 128k | i = j = 0; | 109 | 4.44M | while ((j < str_len) && (maxcount-- > 0)) { | 110 | 49.3M | for(; j < str_len; j++) { | 111 | | /* I found that using memchr makes no difference */ | 112 | 49.2M | if (str[j] == ch) { | 113 | 4.22M | SPLIT_ADD(str, i, j); | 114 | 4.22M | i = j = j + 1; | 115 | 4.22M | break; | 116 | 4.22M | } | 117 | 49.2M | } | 118 | 4.31M | } | 119 | 128k | #if !STRINGLIB_MUTABLE | 120 | 128k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 121 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 122 | 28.5k | Py_INCREF(str_obj); | 123 | 28.5k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 124 | 28.5k | count++; | 125 | 28.5k | } else | 126 | 99.8k | #endif | 127 | 99.8k | if (i <= str_len) { | 128 | 199k | SPLIT_ADD(str, i, str_len); | 129 | 199k | } | 130 | 128k | FIX_PREALLOC_SIZE(list); | 131 | 128k | return list; | 132 | | | 133 | 0 | onError: | 134 | 0 | Py_DECREF(list); | 135 | | return NULL; | 136 | 128k | } |
unicodeobject.c:ucs4lib_split_char Line | Count | Source | 100 | 18.2k | { | 101 | 18.2k | Py_ssize_t i, j, count=0; | 102 | 18.2k | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 103 | 18.2k | PyObject *sub; | 104 | | | 105 | 18.2k | if (list == NULL) | 106 | 0 | return NULL; | 107 | | | 108 | 18.2k | i = j = 0; | 109 | 1.35M | while ((j < str_len) && (maxcount-- > 0)) { | 110 | 25.2M | for(; j < str_len; j++) { | 111 | | /* I found that using memchr makes no difference */ | 112 | 25.1M | if (str[j] == ch) { | 113 | 1.32M | SPLIT_ADD(str, i, j); | 114 | 1.32M | i = j = j + 1; | 115 | 1.32M | break; | 116 | 1.32M | } | 117 | 25.1M | } | 118 | 1.33M | } | 119 | 18.2k | #if !STRINGLIB_MUTABLE | 120 | 18.2k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 121 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 122 | 1.04k | Py_INCREF(str_obj); | 123 | 1.04k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 124 | 1.04k | count++; | 125 | 1.04k | } else | 126 | 17.2k | #endif | 127 | 17.2k | if (i <= str_len) { | 128 | 34.4k | SPLIT_ADD(str, i, str_len); | 129 | 34.4k | } | 130 | 18.2k | FIX_PREALLOC_SIZE(list); | 131 | 18.2k | return list; | 132 | | | 133 | 0 | onError: | 134 | 0 | Py_DECREF(list); | 135 | | return NULL; | 136 | 18.2k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split_char |
137 | | |
138 | | Py_LOCAL_INLINE(PyObject *) |
139 | | STRINGLIB(split)(PyObject* str_obj, |
140 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
141 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len, |
142 | | Py_ssize_t maxcount) |
143 | 22.5M | { |
144 | 22.5M | Py_ssize_t i, j, pos, count=0; |
145 | 22.5M | PyObject *list, *sub; |
146 | | |
147 | 22.5M | if (sep_len == 0) { |
148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
149 | 0 | return NULL; |
150 | 0 | } |
151 | 22.5M | else if (sep_len == 1) |
152 | 22.3M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); |
153 | | |
154 | 218k | list = PyList_New(PREALLOC_SIZE(maxcount)); |
155 | 218k | if (list == NULL) |
156 | 0 | return NULL; |
157 | | |
158 | 218k | i = j = 0; |
159 | 396k | while (maxcount-- > 0) { |
160 | 218k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); |
161 | 218k | if (pos < 0) |
162 | 41.9k | break; |
163 | 177k | j = i + pos; |
164 | 354k | SPLIT_ADD(str, i, j); |
165 | 354k | i = j + sep_len; |
166 | 354k | } |
167 | | #if !STRINGLIB_MUTABLE |
168 | 218k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
169 | | /* No match in str_obj, so just use it as list[0] */ |
170 | 41.9k | Py_INCREF(str_obj); |
171 | 41.9k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
172 | 41.9k | count++; |
173 | 41.9k | } else |
174 | 177k | #endif |
175 | 177k | { |
176 | 354k | SPLIT_ADD(str, i, str_len); |
177 | 354k | } |
178 | 218k | FIX_PREALLOC_SIZE(list); |
179 | 218k | return list; |
180 | | |
181 | 0 | onError: |
182 | 0 | Py_DECREF(list); |
183 | 0 | return NULL; |
184 | 0 | } bytesobject.c:stringlib_split Line | Count | Source | 143 | 2.89M | { | 144 | 2.89M | Py_ssize_t i, j, pos, count=0; | 145 | 2.89M | PyObject *list, *sub; | 146 | | | 147 | 2.89M | if (sep_len == 0) { | 148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 149 | 0 | return NULL; | 150 | 0 | } | 151 | 2.89M | else if (sep_len == 1) | 152 | 2.89M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 153 | | | 154 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); | 155 | 0 | if (list == NULL) | 156 | 0 | return NULL; | 157 | | | 158 | 0 | i = j = 0; | 159 | 0 | while (maxcount-- > 0) { | 160 | 0 | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 161 | 0 | if (pos < 0) | 162 | 0 | break; | 163 | 0 | j = i + pos; | 164 | 0 | SPLIT_ADD(str, i, j); | 165 | 0 | i = j + sep_len; | 166 | 0 | } | 167 | 0 | #if !STRINGLIB_MUTABLE | 168 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 169 | | /* No match in str_obj, so just use it as list[0] */ | 170 | 0 | Py_INCREF(str_obj); | 171 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 172 | 0 | count++; | 173 | 0 | } else | 174 | 0 | #endif | 175 | 0 | { | 176 | 0 | SPLIT_ADD(str, i, str_len); | 177 | 0 | } | 178 | 0 | FIX_PREALLOC_SIZE(list); | 179 | 0 | return list; | 180 | | | 181 | 0 | onError: | 182 | 0 | Py_DECREF(list); | 183 | | return NULL; | 184 | 0 | } |
unicodeobject.c:asciilib_split Line | Count | Source | 143 | 18.1M | { | 144 | 18.1M | Py_ssize_t i, j, pos, count=0; | 145 | 18.1M | PyObject *list, *sub; | 146 | | | 147 | 18.1M | if (sep_len == 0) { | 148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 149 | 0 | return NULL; | 150 | 0 | } | 151 | 18.1M | else if (sep_len == 1) | 152 | 18.1M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 153 | | | 154 | 74.4k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 155 | 74.4k | if (list == NULL) | 156 | 0 | return NULL; | 157 | | | 158 | 74.4k | i = j = 0; | 159 | 119k | while (maxcount-- > 0) { | 160 | 74.4k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 161 | 74.4k | if (pos < 0) | 162 | 29.2k | break; | 163 | 45.1k | j = i + pos; | 164 | 90.3k | SPLIT_ADD(str, i, j); | 165 | 90.3k | i = j + sep_len; | 166 | 90.3k | } | 167 | 74.4k | #if !STRINGLIB_MUTABLE | 168 | 74.4k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 169 | | /* No match in str_obj, so just use it as list[0] */ | 170 | 29.2k | Py_INCREF(str_obj); | 171 | 29.2k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 172 | 29.2k | count++; | 173 | 29.2k | } else | 174 | 45.1k | #endif | 175 | 45.1k | { | 176 | 90.3k | SPLIT_ADD(str, i, str_len); | 177 | 90.3k | } | 178 | 74.4k | FIX_PREALLOC_SIZE(list); | 179 | 74.4k | return list; | 180 | | | 181 | 0 | onError: | 182 | 0 | Py_DECREF(list); | 183 | | return NULL; | 184 | 74.4k | } |
unicodeobject.c:ucs1lib_split Line | Count | Source | 143 | 1.17M | { | 144 | 1.17M | Py_ssize_t i, j, pos, count=0; | 145 | 1.17M | PyObject *list, *sub; | 146 | | | 147 | 1.17M | if (sep_len == 0) { | 148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 149 | 0 | return NULL; | 150 | 0 | } | 151 | 1.17M | else if (sep_len == 1) | 152 | 1.15M | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 153 | | | 154 | 19.5k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 155 | 19.5k | if (list == NULL) | 156 | 0 | return NULL; | 157 | | | 158 | 19.5k | i = j = 0; | 159 | 37.2k | while (maxcount-- > 0) { | 160 | 19.5k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 161 | 19.5k | if (pos < 0) | 162 | 1.84k | break; | 163 | 17.7k | j = i + pos; | 164 | 35.4k | SPLIT_ADD(str, i, j); | 165 | 35.4k | i = j + sep_len; | 166 | 35.4k | } | 167 | 19.5k | #if !STRINGLIB_MUTABLE | 168 | 19.5k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 169 | | /* No match in str_obj, so just use it as list[0] */ | 170 | 1.84k | Py_INCREF(str_obj); | 171 | 1.84k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 172 | 1.84k | count++; | 173 | 1.84k | } else | 174 | 17.7k | #endif | 175 | 17.7k | { | 176 | 35.4k | SPLIT_ADD(str, i, str_len); | 177 | 35.4k | } | 178 | 19.5k | FIX_PREALLOC_SIZE(list); | 179 | 19.5k | return list; | 180 | | | 181 | 0 | onError: | 182 | 0 | Py_DECREF(list); | 183 | | return NULL; | 184 | 19.5k | } |
unicodeobject.c:ucs2lib_split Line | Count | Source | 143 | 231k | { | 144 | 231k | Py_ssize_t i, j, pos, count=0; | 145 | 231k | PyObject *list, *sub; | 146 | | | 147 | 231k | if (sep_len == 0) { | 148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 149 | 0 | return NULL; | 150 | 0 | } | 151 | 231k | else if (sep_len == 1) | 152 | 128k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 153 | | | 154 | 102k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 155 | 102k | if (list == NULL) | 156 | 0 | return NULL; | 157 | | | 158 | 102k | i = j = 0; | 159 | 197k | while (maxcount-- > 0) { | 160 | 102k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 161 | 102k | if (pos < 0) | 162 | 8.28k | break; | 163 | 94.4k | j = i + pos; | 164 | 188k | SPLIT_ADD(str, i, j); | 165 | 188k | i = j + sep_len; | 166 | 188k | } | 167 | 102k | #if !STRINGLIB_MUTABLE | 168 | 102k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 169 | | /* No match in str_obj, so just use it as list[0] */ | 170 | 8.28k | Py_INCREF(str_obj); | 171 | 8.28k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 172 | 8.28k | count++; | 173 | 8.28k | } else | 174 | 94.4k | #endif | 175 | 94.4k | { | 176 | 188k | SPLIT_ADD(str, i, str_len); | 177 | 188k | } | 178 | 102k | FIX_PREALLOC_SIZE(list); | 179 | 102k | return list; | 180 | | | 181 | 0 | onError: | 182 | 0 | Py_DECREF(list); | 183 | | return NULL; | 184 | 102k | } |
unicodeobject.c:ucs4lib_split Line | Count | Source | 143 | 40.6k | { | 144 | 40.6k | Py_ssize_t i, j, pos, count=0; | 145 | 40.6k | PyObject *list, *sub; | 146 | | | 147 | 40.6k | if (sep_len == 0) { | 148 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 149 | 0 | return NULL; | 150 | 0 | } | 151 | 40.6k | else if (sep_len == 1) | 152 | 18.2k | return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount); | 153 | | | 154 | 22.3k | list = PyList_New(PREALLOC_SIZE(maxcount)); | 155 | 22.3k | if (list == NULL) | 156 | 0 | return NULL; | 157 | | | 158 | 22.3k | i = j = 0; | 159 | 42.0k | while (maxcount-- > 0) { | 160 | 22.3k | pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH); | 161 | 22.3k | if (pos < 0) | 162 | 2.58k | break; | 163 | 19.7k | j = i + pos; | 164 | 39.5k | SPLIT_ADD(str, i, j); | 165 | 39.5k | i = j + sep_len; | 166 | 39.5k | } | 167 | 22.3k | #if !STRINGLIB_MUTABLE | 168 | 22.3k | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 169 | | /* No match in str_obj, so just use it as list[0] */ | 170 | 2.58k | Py_INCREF(str_obj); | 171 | 2.58k | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 172 | 2.58k | count++; | 173 | 2.58k | } else | 174 | 19.7k | #endif | 175 | 19.7k | { | 176 | 39.5k | SPLIT_ADD(str, i, str_len); | 177 | 39.5k | } | 178 | 22.3k | FIX_PREALLOC_SIZE(list); | 179 | 22.3k | return list; | 180 | | | 181 | 0 | onError: | 182 | 0 | Py_DECREF(list); | 183 | | return NULL; | 184 | 22.3k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_split |
185 | | |
186 | | Py_LOCAL_INLINE(PyObject *) |
187 | | STRINGLIB(rsplit_whitespace)(PyObject* str_obj, |
188 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
189 | | Py_ssize_t maxcount) |
190 | 0 | { |
191 | 0 | Py_ssize_t i, j, count=0; |
192 | 0 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
193 | 0 | PyObject *sub; |
194 | |
|
195 | 0 | if (list == NULL) |
196 | 0 | return NULL; |
197 | | |
198 | 0 | i = j = str_len - 1; |
199 | 0 | while (maxcount-- > 0) { |
200 | 0 | while (i >= 0 && STRINGLIB_ISSPACE(str[i])) |
201 | 0 | i--; |
202 | 0 | if (i < 0) break; |
203 | 0 | j = i; i--; |
204 | 0 | while (i >= 0 && !STRINGLIB_ISSPACE(str[i])) |
205 | 0 | i--; |
206 | | #if !STRINGLIB_MUTABLE |
207 | 0 | if (j == str_len - 1 && i < 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
208 | | /* No whitespace in str_obj, so just use it as list[0] */ |
209 | 0 | Py_INCREF(str_obj); |
210 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
211 | 0 | count++; |
212 | 0 | break; |
213 | 0 | } |
214 | 0 | #endif |
215 | 0 | SPLIT_ADD(str, i + 1, j + 1); |
216 | 0 | } |
217 | | |
218 | 0 | if (i >= 0) { |
219 | | /* Only occurs when maxcount was reached */ |
220 | | /* Skip any remaining whitespace and copy to beginning of string */ |
221 | 0 | while (i >= 0 && STRINGLIB_ISSPACE(str[i])) |
222 | 0 | i--; |
223 | 0 | if (i >= 0) |
224 | 0 | SPLIT_ADD(str, 0, i + 1); |
225 | 0 | } |
226 | 0 | FIX_PREALLOC_SIZE(list); |
227 | 0 | if (PyList_Reverse(list) < 0) |
228 | 0 | goto onError; |
229 | 0 | return list; |
230 | | |
231 | 0 | onError: |
232 | 0 | Py_DECREF(list); |
233 | 0 | return NULL; |
234 | 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 |
235 | | |
236 | | Py_LOCAL_INLINE(PyObject *) |
237 | | STRINGLIB(rsplit_char)(PyObject* str_obj, |
238 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
239 | | const STRINGLIB_CHAR ch, |
240 | | Py_ssize_t maxcount) |
241 | 66 | { |
242 | 66 | Py_ssize_t i, j, count=0; |
243 | 66 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); |
244 | 66 | PyObject *sub; |
245 | | |
246 | 66 | if (list == NULL) |
247 | 0 | return NULL; |
248 | | |
249 | 66 | i = j = str_len - 1; |
250 | 132 | while ((i >= 0) && (maxcount-- > 0)) { |
251 | 138 | for(; i >= 0; i--) { |
252 | 138 | if (str[i] == ch) { |
253 | 66 | SPLIT_ADD(str, i + 1, j + 1); |
254 | 66 | j = i = i - 1; |
255 | 66 | break; |
256 | 66 | } |
257 | 138 | } |
258 | 66 | } |
259 | | #if !STRINGLIB_MUTABLE |
260 | 66 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
261 | | /* ch not in str_obj, so just use str_obj as list[0] */ |
262 | 0 | Py_INCREF(str_obj); |
263 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
264 | 0 | count++; |
265 | 0 | } else |
266 | 66 | #endif |
267 | 66 | if (j >= -1) { |
268 | 132 | SPLIT_ADD(str, 0, j + 1); |
269 | 132 | } |
270 | 66 | FIX_PREALLOC_SIZE(list); |
271 | 66 | if (PyList_Reverse(list) < 0) |
272 | 0 | goto onError; |
273 | 66 | return list; |
274 | | |
275 | 0 | onError: |
276 | 0 | Py_DECREF(list); |
277 | 0 | return NULL; |
278 | 66 | } Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char unicodeobject.c:asciilib_rsplit_char Line | Count | Source | 241 | 66 | { | 242 | 66 | Py_ssize_t i, j, count=0; | 243 | 66 | PyObject *list = PyList_New(PREALLOC_SIZE(maxcount)); | 244 | 66 | PyObject *sub; | 245 | | | 246 | 66 | if (list == NULL) | 247 | 0 | return NULL; | 248 | | | 249 | 66 | i = j = str_len - 1; | 250 | 132 | while ((i >= 0) && (maxcount-- > 0)) { | 251 | 138 | for(; i >= 0; i--) { | 252 | 138 | if (str[i] == ch) { | 253 | 66 | SPLIT_ADD(str, i + 1, j + 1); | 254 | 66 | j = i = i - 1; | 255 | 66 | break; | 256 | 66 | } | 257 | 138 | } | 258 | 66 | } | 259 | 66 | #if !STRINGLIB_MUTABLE | 260 | 66 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 261 | | /* ch not in str_obj, so just use str_obj as list[0] */ | 262 | 0 | Py_INCREF(str_obj); | 263 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 264 | 0 | count++; | 265 | 0 | } else | 266 | 66 | #endif | 267 | 66 | if (j >= -1) { | 268 | 132 | SPLIT_ADD(str, 0, j + 1); | 269 | 132 | } | 270 | 66 | FIX_PREALLOC_SIZE(list); | 271 | 66 | if (PyList_Reverse(list) < 0) | 272 | 0 | goto onError; | 273 | 66 | return list; | 274 | | | 275 | 0 | onError: | 276 | 0 | Py_DECREF(list); | 277 | | return NULL; | 278 | 66 | } |
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 |
279 | | |
280 | | Py_LOCAL_INLINE(PyObject *) |
281 | | STRINGLIB(rsplit)(PyObject* str_obj, |
282 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
283 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len, |
284 | | Py_ssize_t maxcount) |
285 | 66 | { |
286 | 66 | Py_ssize_t j, pos, count=0; |
287 | 66 | PyObject *list, *sub; |
288 | | |
289 | 66 | if (sep_len == 0) { |
290 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
291 | 0 | return NULL; |
292 | 0 | } |
293 | 66 | else if (sep_len == 1) |
294 | 66 | return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount); |
295 | | |
296 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); |
297 | 0 | if (list == NULL) |
298 | 0 | return NULL; |
299 | | |
300 | 0 | j = str_len; |
301 | 0 | while (maxcount-- > 0) { |
302 | 0 | pos = FASTSEARCH(str, j, sep, sep_len, -1, FAST_RSEARCH); |
303 | 0 | if (pos < 0) |
304 | 0 | break; |
305 | 0 | SPLIT_ADD(str, pos + sep_len, j); |
306 | 0 | j = pos; |
307 | 0 | } |
308 | | #if !STRINGLIB_MUTABLE |
309 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { |
310 | | /* No match in str_obj, so just use it as list[0] */ |
311 | 0 | Py_INCREF(str_obj); |
312 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); |
313 | 0 | count++; |
314 | 0 | } else |
315 | 0 | #endif |
316 | 0 | { |
317 | 0 | SPLIT_ADD(str, 0, j); |
318 | 0 | } |
319 | 0 | FIX_PREALLOC_SIZE(list); |
320 | 0 | if (PyList_Reverse(list) < 0) |
321 | 0 | goto onError; |
322 | 0 | return list; |
323 | | |
324 | 0 | onError: |
325 | 0 | Py_DECREF(list); |
326 | 0 | return NULL; |
327 | 0 | } Unexecuted instantiation: bytesobject.c:stringlib_rsplit unicodeobject.c:asciilib_rsplit Line | Count | Source | 285 | 66 | { | 286 | 66 | Py_ssize_t j, pos, count=0; | 287 | 66 | PyObject *list, *sub; | 288 | | | 289 | 66 | if (sep_len == 0) { | 290 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 291 | 0 | return NULL; | 292 | 0 | } | 293 | 66 | else if (sep_len == 1) | 294 | 66 | return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount); | 295 | | | 296 | 0 | list = PyList_New(PREALLOC_SIZE(maxcount)); | 297 | 0 | if (list == NULL) | 298 | 0 | return NULL; | 299 | | | 300 | 0 | j = str_len; | 301 | 0 | while (maxcount-- > 0) { | 302 | 0 | pos = FASTSEARCH(str, j, sep, sep_len, -1, FAST_RSEARCH); | 303 | 0 | if (pos < 0) | 304 | 0 | break; | 305 | 0 | SPLIT_ADD(str, pos + sep_len, j); | 306 | 0 | j = pos; | 307 | 0 | } | 308 | 0 | #if !STRINGLIB_MUTABLE | 309 | 0 | if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) { | 310 | | /* No match in str_obj, so just use it as list[0] */ | 311 | 0 | Py_INCREF(str_obj); | 312 | 0 | PyList_SET_ITEM(list, 0, (PyObject *)str_obj); | 313 | 0 | count++; | 314 | 0 | } else | 315 | 0 | #endif | 316 | 0 | { | 317 | 0 | SPLIT_ADD(str, 0, j); | 318 | 0 | } | 319 | 0 | FIX_PREALLOC_SIZE(list); | 320 | 0 | if (PyList_Reverse(list) < 0) | 321 | 0 | goto onError; | 322 | 0 | return list; | 323 | | | 324 | 0 | onError: | 325 | 0 | Py_DECREF(list); | 326 | | return NULL; | 327 | 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 |
328 | | |
329 | | Py_LOCAL_INLINE(PyObject *) |
330 | | STRINGLIB(splitlines)(PyObject* str_obj, |
331 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
332 | | int keepends) |
333 | 16.4k | { |
334 | | /* This does not use the preallocated list because splitlines is |
335 | | usually run with hundreds of newlines. The overhead of |
336 | | switching between PyList_SET_ITEM and append causes about a |
337 | | 2-3% slowdown for that common case. A smarter implementation |
338 | | could move the if check out, so the SET_ITEMs are done first |
339 | | and the appends only done when the prealloc buffer is full. |
340 | | That's too much work for little gain.*/ |
341 | | |
342 | 16.4k | Py_ssize_t i; |
343 | 16.4k | Py_ssize_t j; |
344 | 16.4k | PyObject *list = PyList_New(0); |
345 | 16.4k | PyObject *sub; |
346 | | |
347 | 16.4k | if (list == NULL) |
348 | 0 | return NULL; |
349 | | |
350 | 44.8M | for (i = j = 0; i < str_len; ) { |
351 | 44.8M | Py_ssize_t eol; |
352 | | |
353 | | /* Find a line and append it */ |
354 | 144M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) |
355 | 100M | i++; |
356 | | |
357 | | /* Skip the line break reading CRLF as one line break */ |
358 | 44.8M | eol = i; |
359 | 44.8M | if (i < str_len) { |
360 | 44.8M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') |
361 | 23.1k | i += 2; |
362 | 44.8M | else |
363 | 44.8M | i++; |
364 | 44.8M | if (keepends) |
365 | 0 | eol = i; |
366 | 44.8M | } |
367 | | #if !STRINGLIB_MUTABLE |
368 | 44.8M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { |
369 | | /* No linebreak in str_obj, so just use it as list[0] */ |
370 | 6.59k | if (PyList_Append(list, str_obj)) |
371 | 0 | goto onError; |
372 | 6.59k | break; |
373 | 6.59k | } |
374 | 44.8M | #endif |
375 | 89.7M | SPLIT_APPEND(str, j, eol); |
376 | 44.8M | j = i; |
377 | 44.8M | } |
378 | 16.4k | return list; |
379 | | |
380 | 0 | onError: |
381 | 0 | Py_DECREF(list); |
382 | | return NULL; |
383 | 16.4k | } Unexecuted instantiation: bytesobject.c:stringlib_splitlines unicodeobject.c:asciilib_splitlines Line | Count | Source | 333 | 4.07k | { | 334 | | /* This does not use the preallocated list because splitlines is | 335 | | usually run with hundreds of newlines. The overhead of | 336 | | switching between PyList_SET_ITEM and append causes about a | 337 | | 2-3% slowdown for that common case. A smarter implementation | 338 | | could move the if check out, so the SET_ITEMs are done first | 339 | | and the appends only done when the prealloc buffer is full. | 340 | | That's too much work for little gain.*/ | 341 | | | 342 | 4.07k | Py_ssize_t i; | 343 | 4.07k | Py_ssize_t j; | 344 | 4.07k | PyObject *list = PyList_New(0); | 345 | 4.07k | PyObject *sub; | 346 | | | 347 | 4.07k | if (list == NULL) | 348 | 0 | return NULL; | 349 | | | 350 | 11.2M | for (i = j = 0; i < str_len; ) { | 351 | 11.2M | Py_ssize_t eol; | 352 | | | 353 | | /* Find a line and append it */ | 354 | 16.0M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 355 | 4.75M | i++; | 356 | | | 357 | | /* Skip the line break reading CRLF as one line break */ | 358 | 11.2M | eol = i; | 359 | 11.2M | if (i < str_len) { | 360 | 11.2M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 361 | 762 | i += 2; | 362 | 11.2M | else | 363 | 11.2M | i++; | 364 | 11.2M | if (keepends) | 365 | 0 | eol = i; | 366 | 11.2M | } | 367 | 11.2M | #if !STRINGLIB_MUTABLE | 368 | 11.2M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 369 | | /* No linebreak in str_obj, so just use it as list[0] */ | 370 | 967 | if (PyList_Append(list, str_obj)) | 371 | 0 | goto onError; | 372 | 967 | break; | 373 | 967 | } | 374 | 11.2M | #endif | 375 | 22.5M | SPLIT_APPEND(str, j, eol); | 376 | 11.2M | j = i; | 377 | 11.2M | } | 378 | 4.07k | return list; | 379 | | | 380 | 0 | onError: | 381 | 0 | Py_DECREF(list); | 382 | | return NULL; | 383 | 4.07k | } |
unicodeobject.c:ucs1lib_splitlines Line | Count | Source | 333 | 1.01k | { | 334 | | /* This does not use the preallocated list because splitlines is | 335 | | usually run with hundreds of newlines. The overhead of | 336 | | switching between PyList_SET_ITEM and append causes about a | 337 | | 2-3% slowdown for that common case. A smarter implementation | 338 | | could move the if check out, so the SET_ITEMs are done first | 339 | | and the appends only done when the prealloc buffer is full. | 340 | | That's too much work for little gain.*/ | 341 | | | 342 | 1.01k | Py_ssize_t i; | 343 | 1.01k | Py_ssize_t j; | 344 | 1.01k | PyObject *list = PyList_New(0); | 345 | 1.01k | PyObject *sub; | 346 | | | 347 | 1.01k | if (list == NULL) | 348 | 0 | return NULL; | 349 | | | 350 | 7.36M | for (i = j = 0; i < str_len; ) { | 351 | 7.36M | Py_ssize_t eol; | 352 | | | 353 | | /* Find a line and append it */ | 354 | 17.5M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 355 | 10.1M | i++; | 356 | | | 357 | | /* Skip the line break reading CRLF as one line break */ | 358 | 7.36M | eol = i; | 359 | 7.36M | if (i < str_len) { | 360 | 7.36M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 361 | 582 | i += 2; | 362 | 7.36M | else | 363 | 7.36M | i++; | 364 | 7.36M | if (keepends) | 365 | 0 | eol = i; | 366 | 7.36M | } | 367 | 7.36M | #if !STRINGLIB_MUTABLE | 368 | 7.36M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 369 | | /* No linebreak in str_obj, so just use it as list[0] */ | 370 | 286 | if (PyList_Append(list, str_obj)) | 371 | 0 | goto onError; | 372 | 286 | break; | 373 | 286 | } | 374 | 7.36M | #endif | 375 | 14.7M | SPLIT_APPEND(str, j, eol); | 376 | 7.36M | j = i; | 377 | 7.36M | } | 378 | 1.01k | return list; | 379 | | | 380 | 0 | onError: | 381 | 0 | Py_DECREF(list); | 382 | | return NULL; | 383 | 1.01k | } |
unicodeobject.c:ucs2lib_splitlines Line | Count | Source | 333 | 8.12k | { | 334 | | /* This does not use the preallocated list because splitlines is | 335 | | usually run with hundreds of newlines. The overhead of | 336 | | switching between PyList_SET_ITEM and append causes about a | 337 | | 2-3% slowdown for that common case. A smarter implementation | 338 | | could move the if check out, so the SET_ITEMs are done first | 339 | | and the appends only done when the prealloc buffer is full. | 340 | | That's too much work for little gain.*/ | 341 | | | 342 | 8.12k | Py_ssize_t i; | 343 | 8.12k | Py_ssize_t j; | 344 | 8.12k | PyObject *list = PyList_New(0); | 345 | 8.12k | PyObject *sub; | 346 | | | 347 | 8.12k | if (list == NULL) | 348 | 0 | return NULL; | 349 | | | 350 | 12.0M | for (i = j = 0; i < str_len; ) { | 351 | 12.0M | Py_ssize_t eol; | 352 | | | 353 | | /* Find a line and append it */ | 354 | 51.9M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 355 | 39.9M | i++; | 356 | | | 357 | | /* Skip the line break reading CRLF as one line break */ | 358 | 12.0M | eol = i; | 359 | 12.0M | if (i < str_len) { | 360 | 12.0M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 361 | 7.70k | i += 2; | 362 | 12.0M | else | 363 | 12.0M | i++; | 364 | 12.0M | if (keepends) | 365 | 0 | eol = i; | 366 | 12.0M | } | 367 | 12.0M | #if !STRINGLIB_MUTABLE | 368 | 12.0M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 369 | | /* No linebreak in str_obj, so just use it as list[0] */ | 370 | 3.78k | if (PyList_Append(list, str_obj)) | 371 | 0 | goto onError; | 372 | 3.78k | break; | 373 | 3.78k | } | 374 | 12.0M | #endif | 375 | 24.0M | SPLIT_APPEND(str, j, eol); | 376 | 12.0M | j = i; | 377 | 12.0M | } | 378 | 8.12k | return list; | 379 | | | 380 | 0 | onError: | 381 | 0 | Py_DECREF(list); | 382 | | return NULL; | 383 | 8.12k | } |
unicodeobject.c:ucs4lib_splitlines Line | Count | Source | 333 | 3.25k | { | 334 | | /* This does not use the preallocated list because splitlines is | 335 | | usually run with hundreds of newlines. The overhead of | 336 | | switching between PyList_SET_ITEM and append causes about a | 337 | | 2-3% slowdown for that common case. A smarter implementation | 338 | | could move the if check out, so the SET_ITEMs are done first | 339 | | and the appends only done when the prealloc buffer is full. | 340 | | That's too much work for little gain.*/ | 341 | | | 342 | 3.25k | Py_ssize_t i; | 343 | 3.25k | Py_ssize_t j; | 344 | 3.25k | PyObject *list = PyList_New(0); | 345 | 3.25k | PyObject *sub; | 346 | | | 347 | 3.25k | if (list == NULL) | 348 | 0 | return NULL; | 349 | | | 350 | 14.1M | for (i = j = 0; i < str_len; ) { | 351 | 14.1M | Py_ssize_t eol; | 352 | | | 353 | | /* Find a line and append it */ | 354 | 59.4M | while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i])) | 355 | 45.2M | i++; | 356 | | | 357 | | /* Skip the line break reading CRLF as one line break */ | 358 | 14.1M | eol = i; | 359 | 14.1M | if (i < str_len) { | 360 | 14.1M | if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n') | 361 | 14.0k | i += 2; | 362 | 14.1M | else | 363 | 14.1M | i++; | 364 | 14.1M | if (keepends) | 365 | 0 | eol = i; | 366 | 14.1M | } | 367 | 14.1M | #if !STRINGLIB_MUTABLE | 368 | 14.1M | if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) { | 369 | | /* No linebreak in str_obj, so just use it as list[0] */ | 370 | 1.55k | if (PyList_Append(list, str_obj)) | 371 | 0 | goto onError; | 372 | 1.55k | break; | 373 | 1.55k | } | 374 | 14.1M | #endif | 375 | 28.3M | SPLIT_APPEND(str, j, eol); | 376 | 14.1M | j = i; | 377 | 14.1M | } | 378 | 3.25k | return list; | 379 | | | 380 | 0 | onError: | 381 | 0 | Py_DECREF(list); | 382 | | return NULL; | 383 | 3.25k | } |
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines |
384 | | |