Coverage Report

Created: 2026-12-01 06:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
134M
#define MAX_PREALLOC 12
17
18
/* 5 splits gives 6 elements */
19
#define PREALLOC_SIZE(maxsplit) \
20
25.3M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
21
22
#define SPLIT_APPEND(data, left, right)         \
23
46.6M
    sub = STRINGLIB_NEW((data) + (left),        \
24
46.6M
                        (right) - (left));      \
25
46.6M
    if (sub == NULL)                            \
26
46.6M
        goto onError;                           \
27
46.6M
    if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
28
46.6M
        goto onError;
29
30
80.3M
#define SPLIT_ADD(data, left, right) {          \
31
80.3M
    sub = STRINGLIB_NEW((data) + (left),        \
32
80.3M
                        (right) - (left));      \
33
80.3M
    if (sub == NULL)                            \
34
80.3M
        goto onError;                           \
35
80.3M
    if (count < MAX_PREALLOC) {                 \
36
39.2M
        PyList_SET_ITEM(list, count, sub);      \
37
41.0M
    } else {                                    \
38
41.0M
        if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
39
41.0M
            goto onError;                       \
40
41.0M
    }                                           \
41
80.3M
    count++; }
42
43
44
/* Always force the list to the expected size. */
45
25.3M
#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
171k
{
52
171k
    Py_ssize_t i, j, count=0;
53
171k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
171k
    PyObject *sub;
55
56
171k
    if (list == NULL)
57
0
        return NULL;
58
59
171k
    i = j = 0;
60
1.81M
    while (maxcount-- > 0) {
61
3.49M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
1.70M
            i++;
63
1.79M
        if (i == str_len) break;
64
1.68M
        j = i; i++;
65
122M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
120M
            i++;
67
#if !STRINGLIB_MUTABLE
68
1.68M
        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
38.6k
            Py_INCREF(str_obj);
71
38.6k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
38.6k
            count++;
73
38.6k
            break;
74
38.6k
        }
75
1.64M
#endif
76
4.92M
        SPLIT_ADD(str, j, i);
77
4.92M
    }
78
79
171k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
43.2k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
23.1k
            i++;
84
20.1k
        if (i != str_len)
85
20.1k
            SPLIT_ADD(str, i, str_len);
86
20.1k
    }
87
171k
    FIX_PREALLOC_SIZE(list);
88
171k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
0
    return NULL;
93
171k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
51
74.2k
{
52
74.2k
    Py_ssize_t i, j, count=0;
53
74.2k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
74.2k
    PyObject *sub;
55
56
74.2k
    if (list == NULL)
57
0
        return NULL;
58
59
74.2k
    i = j = 0;
60
514k
    while (maxcount-- > 0) {
61
910k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
410k
            i++;
63
499k
        if (i == str_len) break;
64
458k
        j = i; i++;
65
42.3M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
41.8M
            i++;
67
458k
#if !STRINGLIB_MUTABLE
68
458k
        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
17.5k
            Py_INCREF(str_obj);
71
17.5k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
17.5k
            count++;
73
17.5k
            break;
74
17.5k
        }
75
440k
#endif
76
1.32M
        SPLIT_ADD(str, j, i);
77
1.32M
    }
78
79
74.2k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
27.3k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
14.2k
            i++;
84
13.1k
        if (i != str_len)
85
13.1k
            SPLIT_ADD(str, i, str_len);
86
13.1k
    }
87
74.2k
    FIX_PREALLOC_SIZE(list);
88
74.2k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
74.2k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
51
19.5k
{
52
19.5k
    Py_ssize_t i, j, count=0;
53
19.5k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
19.5k
    PyObject *sub;
55
56
19.5k
    if (list == NULL)
57
0
        return NULL;
58
59
19.5k
    i = j = 0;
60
380k
    while (maxcount-- > 0) {
61
724k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
351k
            i++;
63
373k
        if (i == str_len) break;
64
362k
        j = i; i++;
65
16.8M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
16.4M
            i++;
67
362k
#if !STRINGLIB_MUTABLE
68
362k
        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
1.48k
            Py_INCREF(str_obj);
71
1.48k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
1.48k
            count++;
73
1.48k
            break;
74
1.48k
        }
75
360k
#endif
76
1.08M
        SPLIT_ADD(str, j, i);
77
1.08M
    }
78
79
19.5k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
14.0k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
7.99k
            i++;
84
6.08k
        if (i != str_len)
85
6.08k
            SPLIT_ADD(str, i, str_len);
86
6.08k
    }
87
19.5k
    FIX_PREALLOC_SIZE(list);
88
19.5k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
19.5k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
51
58.2k
{
52
58.2k
    Py_ssize_t i, j, count=0;
53
58.2k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
58.2k
    PyObject *sub;
55
56
58.2k
    if (list == NULL)
57
0
        return NULL;
58
59
58.2k
    i = j = 0;
60
645k
    while (maxcount-- > 0) {
61
1.31M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
674k
            i++;
63
644k
        if (i == str_len) break;
64
602k
        j = i; i++;
65
40.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
39.9M
            i++;
67
602k
#if !STRINGLIB_MUTABLE
68
602k
        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
15.0k
            Py_INCREF(str_obj);
71
15.0k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
15.0k
            count++;
73
15.0k
            break;
74
15.0k
        }
75
587k
#endif
76
1.76M
        SPLIT_ADD(str, j, i);
77
1.76M
    }
78
79
58.2k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
1.78k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
890
            i++;
84
890
        if (i != str_len)
85
890
            SPLIT_ADD(str, i, str_len);
86
890
    }
87
58.2k
    FIX_PREALLOC_SIZE(list);
88
58.2k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
58.2k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
51
19.4k
{
52
19.4k
    Py_ssize_t i, j, count=0;
53
19.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
19.4k
    PyObject *sub;
55
56
19.4k
    if (list == NULL)
57
0
        return NULL;
58
59
19.4k
    i = j = 0;
60
273k
    while (maxcount-- > 0) {
61
536k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
263k
            i++;
63
272k
        if (i == str_len) break;
64
258k
        j = i; i++;
65
22.4M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
22.1M
            i++;
67
258k
#if !STRINGLIB_MUTABLE
68
258k
        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
4.58k
            Py_INCREF(str_obj);
71
4.58k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
4.58k
            count++;
73
4.58k
            break;
74
4.58k
        }
75
253k
#endif
76
761k
        SPLIT_ADD(str, j, i);
77
761k
    }
78
79
19.4k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
30
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
15
            i++;
84
15
        if (i != str_len)
85
15
            SPLIT_ADD(str, i, str_len);
86
15
    }
87
19.4k
    FIX_PREALLOC_SIZE(list);
88
19.4k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
19.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
24.9M
{
101
24.9M
    Py_ssize_t i, j, count=0;
102
24.9M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
24.9M
    PyObject *sub;
104
105
24.9M
    if (list == NULL)
106
0
        return NULL;
107
108
24.9M
    i = j = 0;
109
107M
    while ((j < str_len) && (maxcount-- > 0)) {
110
550M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
527M
            if (str[j] == ch) {
113
59.7M
                SPLIT_ADD(str, i, j);
114
59.7M
                i = j = j + 1;
115
59.7M
                break;
116
59.7M
            }
117
527M
        }
118
82.2M
    }
119
#if !STRINGLIB_MUTABLE
120
24.9M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
6.37M
        Py_INCREF(str_obj);
123
6.37M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
6.37M
        count++;
125
6.37M
    } else
126
18.5M
#endif
127
18.5M
    if (i <= str_len) {
128
37.1M
        SPLIT_ADD(str, i, str_len);
129
37.1M
    }
130
24.9M
    FIX_PREALLOC_SIZE(list);
131
24.9M
    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
3.61M
{
101
3.61M
    Py_ssize_t i, j, count=0;
102
3.61M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
3.61M
    PyObject *sub;
104
105
3.61M
    if (list == NULL)
106
0
        return NULL;
107
108
3.61M
    i = j = 0;
109
33.5M
    while ((j < str_len) && (maxcount-- > 0)) {
110
169M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
166M
            if (str[j] == ch) {
113
26.8M
                SPLIT_ADD(str, i, j);
114
26.8M
                i = j = j + 1;
115
26.8M
                break;
116
26.8M
            }
117
166M
        }
118
29.9M
    }
119
3.61M
#if !STRINGLIB_MUTABLE
120
3.61M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
3.03M
        Py_INCREF(str_obj);
123
3.03M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
3.03M
        count++;
125
3.03M
    } else
126
586k
#endif
127
586k
    if (i <= str_len) {
128
1.17M
        SPLIT_ADD(str, i, str_len);
129
1.17M
    }
130
3.61M
    FIX_PREALLOC_SIZE(list);
131
3.61M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
3.61M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
100
19.8M
{
101
19.8M
    Py_ssize_t i, j, count=0;
102
19.8M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
19.8M
    PyObject *sub;
104
105
19.8M
    if (list == NULL)
106
0
        return NULL;
107
108
19.8M
    i = j = 0;
109
59.9M
    while ((j < str_len) && (maxcount-- > 0)) {
110
251M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
232M
            if (str[j] == ch) {
113
21.0M
                SPLIT_ADD(str, i, j);
114
21.0M
                i = j = j + 1;
115
21.0M
                break;
116
21.0M
            }
117
232M
        }
118
40.1M
    }
119
19.8M
#if !STRINGLIB_MUTABLE
120
19.8M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
3.11M
        Py_INCREF(str_obj);
123
3.11M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
3.11M
        count++;
125
3.11M
    } else
126
16.7M
#endif
127
16.7M
    if (i <= str_len) {
128
33.4M
        SPLIT_ADD(str, i, str_len);
129
33.4M
    }
130
19.8M
    FIX_PREALLOC_SIZE(list);
131
19.8M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
19.8M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
100
1.36M
{
101
1.36M
    Py_ssize_t i, j, count=0;
102
1.36M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
1.36M
    PyObject *sub;
104
105
1.36M
    if (list == NULL)
106
0
        return NULL;
107
108
1.36M
    i = j = 0;
109
7.21M
    while ((j < str_len) && (maxcount-- > 0)) {
110
46.7M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
46.4M
            if (str[j] == ch) {
113
5.61M
                SPLIT_ADD(str, i, j);
114
5.61M
                i = j = j + 1;
115
5.61M
                break;
116
5.61M
            }
117
46.4M
        }
118
5.84M
    }
119
1.36M
#if !STRINGLIB_MUTABLE
120
1.36M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
200k
        Py_INCREF(str_obj);
123
200k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
200k
        count++;
125
200k
    } else
126
1.16M
#endif
127
1.16M
    if (i <= str_len) {
128
2.33M
        SPLIT_ADD(str, i, str_len);
129
2.33M
    }
130
1.36M
    FIX_PREALLOC_SIZE(list);
131
1.36M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
1.36M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
100
127k
{
101
127k
    Py_ssize_t i, j, count=0;
102
127k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
127k
    PyObject *sub;
104
105
127k
    if (list == NULL)
106
0
        return NULL;
107
108
127k
    i = j = 0;
109
5.32M
    while ((j < str_len) && (maxcount-- > 0)) {
110
48.1M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
48.0M
            if (str[j] == ch) {
113
5.11M
                SPLIT_ADD(str, i, j);
114
5.11M
                i = j = j + 1;
115
5.11M
                break;
116
5.11M
            }
117
48.0M
        }
118
5.20M
    }
119
127k
#if !STRINGLIB_MUTABLE
120
127k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
30.7k
        Py_INCREF(str_obj);
123
30.7k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
30.7k
        count++;
125
30.7k
    } else
126
96.2k
#endif
127
96.2k
    if (i <= str_len) {
128
192k
        SPLIT_ADD(str, i, str_len);
129
192k
    }
130
127k
    FIX_PREALLOC_SIZE(list);
131
127k
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
127k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
100
24.4k
{
101
24.4k
    Py_ssize_t i, j, count=0;
102
24.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
24.4k
    PyObject *sub;
104
105
24.4k
    if (list == NULL)
106
0
        return NULL;
107
108
24.4k
    i = j = 0;
109
1.14M
    while ((j < str_len) && (maxcount-- > 0)) {
110
33.9M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
33.9M
            if (str[j] == ch) {
113
1.10M
                SPLIT_ADD(str, i, j);
114
1.10M
                i = j = j + 1;
115
1.10M
                break;
116
1.10M
            }
117
33.9M
        }
118
1.12M
    }
119
24.4k
#if !STRINGLIB_MUTABLE
120
24.4k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
1.19k
        Py_INCREF(str_obj);
123
1.19k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
1.19k
        count++;
125
1.19k
    } else
126
23.2k
#endif
127
23.2k
    if (i <= str_len) {
128
46.5k
        SPLIT_ADD(str, i, str_len);
129
46.5k
    }
130
24.4k
    FIX_PREALLOC_SIZE(list);
131
24.4k
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
24.4k
}
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
25.1M
{
144
25.1M
    Py_ssize_t i, j, pos, count=0;
145
25.1M
    PyObject *list, *sub;
146
147
25.1M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
25.1M
    else if (sep_len == 1)
152
24.9M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
225k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
225k
    if (list == NULL)
156
0
        return NULL;
157
158
225k
    i = j = 0;
159
402k
    while (maxcount-- > 0) {
160
225k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
225k
        if (pos < 0)
162
49.2k
            break;
163
176k
        j = i + pos;
164
353k
        SPLIT_ADD(str, i, j);
165
353k
        i = j + sep_len;
166
353k
    }
167
#if !STRINGLIB_MUTABLE
168
225k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
49.2k
        Py_INCREF(str_obj);
171
49.2k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
49.2k
        count++;
173
49.2k
    } else
174
176k
#endif
175
176k
    {
176
353k
        SPLIT_ADD(str, i, str_len);
177
353k
    }
178
225k
    FIX_PREALLOC_SIZE(list);
179
225k
    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
3.61M
{
144
3.61M
    Py_ssize_t i, j, pos, count=0;
145
3.61M
    PyObject *list, *sub;
146
147
3.61M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
3.61M
    else if (sep_len == 1)
152
3.61M
        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
19.9M
{
144
19.9M
    Py_ssize_t i, j, pos, count=0;
145
19.9M
    PyObject *list, *sub;
146
147
19.9M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
19.9M
    else if (sep_len == 1)
152
19.8M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
84.9k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
84.9k
    if (list == NULL)
156
0
        return NULL;
157
158
84.9k
    i = j = 0;
159
136k
    while (maxcount-- > 0) {
160
84.9k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
84.9k
        if (pos < 0)
162
33.8k
            break;
163
51.1k
        j = i + pos;
164
102k
        SPLIT_ADD(str, i, j);
165
102k
        i = j + sep_len;
166
102k
    }
167
84.9k
#if !STRINGLIB_MUTABLE
168
84.9k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
33.8k
        Py_INCREF(str_obj);
171
33.8k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
33.8k
        count++;
173
33.8k
    } else
174
51.1k
#endif
175
51.1k
    {
176
102k
        SPLIT_ADD(str, i, str_len);
177
102k
    }
178
84.9k
    FIX_PREALLOC_SIZE(list);
179
84.9k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
84.9k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
143
1.38M
{
144
1.38M
    Py_ssize_t i, j, pos, count=0;
145
1.38M
    PyObject *list, *sub;
146
147
1.38M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
1.38M
    else if (sep_len == 1)
152
1.36M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
13.9k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
13.9k
    if (list == NULL)
156
0
        return NULL;
157
158
13.9k
    i = j = 0;
159
25.9k
    while (maxcount-- > 0) {
160
13.9k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
13.9k
        if (pos < 0)
162
1.84k
            break;
163
12.0k
        j = i + pos;
164
24.1k
        SPLIT_ADD(str, i, j);
165
24.1k
        i = j + sep_len;
166
24.1k
    }
167
13.9k
#if !STRINGLIB_MUTABLE
168
13.9k
    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
12.0k
#endif
175
12.0k
    {
176
24.1k
        SPLIT_ADD(str, i, str_len);
177
24.1k
    }
178
13.9k
    FIX_PREALLOC_SIZE(list);
179
13.9k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
13.9k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
143
224k
{
144
224k
    Py_ssize_t i, j, pos, count=0;
145
224k
    PyObject *list, *sub;
146
147
224k
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
224k
    else if (sep_len == 1)
152
127k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
97.6k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
97.6k
    if (list == NULL)
156
0
        return NULL;
157
158
97.6k
    i = j = 0;
159
184k
    while (maxcount-- > 0) {
160
97.6k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
97.6k
        if (pos < 0)
162
10.7k
            break;
163
86.8k
        j = i + pos;
164
173k
        SPLIT_ADD(str, i, j);
165
173k
        i = j + sep_len;
166
173k
    }
167
97.6k
#if !STRINGLIB_MUTABLE
168
97.6k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
10.7k
        Py_INCREF(str_obj);
171
10.7k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
10.7k
        count++;
173
10.7k
    } else
174
86.8k
#endif
175
86.8k
    {
176
173k
        SPLIT_ADD(str, i, str_len);
177
173k
    }
178
97.6k
    FIX_PREALLOC_SIZE(list);
179
97.6k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
97.6k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
143
53.8k
{
144
53.8k
    Py_ssize_t i, j, pos, count=0;
145
53.8k
    PyObject *list, *sub;
146
147
53.8k
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
53.8k
    else if (sep_len == 1)
152
24.4k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
29.3k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
29.3k
    if (list == NULL)
156
0
        return NULL;
157
158
29.3k
    i = j = 0;
159
55.9k
    while (maxcount-- > 0) {
160
29.3k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
29.3k
        if (pos < 0)
162
2.80k
            break;
163
26.5k
        j = i + pos;
164
53.1k
        SPLIT_ADD(str, i, j);
165
53.1k
        i = j + sep_len;
166
53.1k
    }
167
29.3k
#if !STRINGLIB_MUTABLE
168
29.3k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
2.80k
        Py_INCREF(str_obj);
171
2.80k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
2.80k
        count++;
173
2.80k
    } else
174
26.5k
#endif
175
26.5k
    {
176
53.1k
        SPLIT_ADD(str, i, str_len);
177
53.1k
    }
178
29.3k
    FIX_PREALLOC_SIZE(list);
179
29.3k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
29.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
42
{
242
42
    Py_ssize_t i, j, count=0;
243
42
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
244
42
    PyObject *sub;
245
246
42
    if (list == NULL)
247
0
        return NULL;
248
249
42
    i = j = str_len - 1;
250
84
    while ((i >= 0) && (maxcount-- > 0)) {
251
114
        for(; i >= 0; i--) {
252
114
            if (str[i] == ch) {
253
42
                SPLIT_ADD(str, i + 1, j + 1);
254
42
                j = i = i - 1;
255
42
                break;
256
42
            }
257
114
        }
258
42
    }
259
#if !STRINGLIB_MUTABLE
260
42
    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
42
#endif
267
42
    if (j >= -1) {
268
84
        SPLIT_ADD(str, 0, j + 1);
269
84
    }
270
42
    FIX_PREALLOC_SIZE(list);
271
42
    if (PyList_Reverse(list) < 0)
272
0
        goto onError;
273
42
    return list;
274
275
0
  onError:
276
0
    Py_DECREF(list);
277
0
    return NULL;
278
42
}
Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char
unicodeobject.c:asciilib_rsplit_char
Line
Count
Source
241
42
{
242
42
    Py_ssize_t i, j, count=0;
243
42
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
244
42
    PyObject *sub;
245
246
42
    if (list == NULL)
247
0
        return NULL;
248
249
42
    i = j = str_len - 1;
250
84
    while ((i >= 0) && (maxcount-- > 0)) {
251
114
        for(; i >= 0; i--) {
252
114
            if (str[i] == ch) {
253
42
                SPLIT_ADD(str, i + 1, j + 1);
254
42
                j = i = i - 1;
255
42
                break;
256
42
            }
257
114
        }
258
42
    }
259
42
#if !STRINGLIB_MUTABLE
260
42
    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
42
#endif
267
42
    if (j >= -1) {
268
84
        SPLIT_ADD(str, 0, j + 1);
269
84
    }
270
42
    FIX_PREALLOC_SIZE(list);
271
42
    if (PyList_Reverse(list) < 0)
272
0
        goto onError;
273
42
    return list;
274
275
0
  onError:
276
0
    Py_DECREF(list);
277
    return NULL;
278
42
}
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
42
{
286
42
    Py_ssize_t j, pos, count=0;
287
42
    PyObject *list, *sub;
288
289
42
    if (sep_len == 0) {
290
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
291
0
        return NULL;
292
0
    }
293
42
    else if (sep_len == 1)
294
42
        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
42
{
286
42
    Py_ssize_t j, pos, count=0;
287
42
    PyObject *list, *sub;
288
289
42
    if (sep_len == 0) {
290
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
291
0
        return NULL;
292
0
    }
293
42
    else if (sep_len == 1)
294
42
        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
17.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
17.4k
    Py_ssize_t i;
343
17.4k
    Py_ssize_t j;
344
17.4k
    PyObject *list = PyList_New(0);
345
17.4k
    PyObject *sub;
346
347
17.4k
    if (list == NULL)
348
0
        return NULL;
349
350
46.6M
    for (i = j = 0; i < str_len; ) {
351
46.6M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
143M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
96.4M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
46.6M
        eol = i;
359
46.6M
        if (i < str_len) {
360
46.6M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
17.6k
                i += 2;
362
46.5M
            else
363
46.5M
                i++;
364
46.6M
            if (keepends)
365
0
                eol = i;
366
46.6M
        }
367
#if !STRINGLIB_MUTABLE
368
46.6M
        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
7.05k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
7.05k
            break;
373
7.05k
        }
374
46.6M
#endif
375
93.2M
        SPLIT_APPEND(str, j, eol);
376
46.6M
        j = i;
377
46.6M
    }
378
17.4k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
17.4k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
333
4.36k
{
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.36k
    Py_ssize_t i;
343
4.36k
    Py_ssize_t j;
344
4.36k
    PyObject *list = PyList_New(0);
345
4.36k
    PyObject *sub;
346
347
4.36k
    if (list == NULL)
348
0
        return NULL;
349
350
12.5M
    for (i = j = 0; i < str_len; ) {
351
12.5M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
22.2M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
9.71M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
12.5M
        eol = i;
359
12.5M
        if (i < str_len) {
360
12.5M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
587
                i += 2;
362
12.5M
            else
363
12.5M
                i++;
364
12.5M
            if (keepends)
365
0
                eol = i;
366
12.5M
        }
367
12.5M
#if !STRINGLIB_MUTABLE
368
12.5M
        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.02k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
1.02k
            break;
373
1.02k
        }
374
12.5M
#endif
375
25.1M
        SPLIT_APPEND(str, j, eol);
376
12.5M
        j = i;
377
12.5M
    }
378
4.36k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
4.36k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
333
1.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
1.07k
    Py_ssize_t i;
343
1.07k
    Py_ssize_t j;
344
1.07k
    PyObject *list = PyList_New(0);
345
1.07k
    PyObject *sub;
346
347
1.07k
    if (list == NULL)
348
0
        return NULL;
349
350
8.82M
    for (i = j = 0; i < str_len; ) {
351
8.82M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
16.5M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
7.69M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
8.82M
        eol = i;
359
8.82M
        if (i < str_len) {
360
8.82M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
1.17k
                i += 2;
362
8.82M
            else
363
8.82M
                i++;
364
8.82M
            if (keepends)
365
0
                eol = i;
366
8.82M
        }
367
8.82M
#if !STRINGLIB_MUTABLE
368
8.82M
        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
354
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
354
            break;
373
354
        }
374
8.82M
#endif
375
17.6M
        SPLIT_APPEND(str, j, eol);
376
8.82M
        j = i;
377
8.82M
    }
378
1.07k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
1.07k
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
333
8.63k
{
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.63k
    Py_ssize_t i;
343
8.63k
    Py_ssize_t j;
344
8.63k
    PyObject *list = PyList_New(0);
345
8.63k
    PyObject *sub;
346
347
8.63k
    if (list == NULL)
348
0
        return NULL;
349
350
11.1M
    for (i = j = 0; i < str_len; ) {
351
11.1M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
46.4M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
35.2M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
11.1M
        eol = i;
359
11.1M
        if (i < str_len) {
360
11.1M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
9.76k
                i += 2;
362
11.1M
            else
363
11.1M
                i++;
364
11.1M
            if (keepends)
365
0
                eol = i;
366
11.1M
        }
367
11.1M
#if !STRINGLIB_MUTABLE
368
11.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
4.03k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
4.03k
            break;
373
4.03k
        }
374
11.1M
#endif
375
22.2M
        SPLIT_APPEND(str, j, eol);
376
11.1M
        j = i;
377
11.1M
    }
378
8.63k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
8.63k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
333
3.41k
{
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.41k
    Py_ssize_t i;
343
3.41k
    Py_ssize_t j;
344
3.41k
    PyObject *list = PyList_New(0);
345
3.41k
    PyObject *sub;
346
347
3.41k
    if (list == NULL)
348
0
        return NULL;
349
350
14.0M
    for (i = j = 0; i < str_len; ) {
351
14.0M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
57.8M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
43.7M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
14.0M
        eol = i;
359
14.0M
        if (i < str_len) {
360
14.0M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
6.14k
                i += 2;
362
14.0M
            else
363
14.0M
                i++;
364
14.0M
            if (keepends)
365
0
                eol = i;
366
14.0M
        }
367
14.0M
#if !STRINGLIB_MUTABLE
368
14.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
1.64k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
1.64k
            break;
373
1.64k
        }
374
14.0M
#endif
375
28.1M
        SPLIT_APPEND(str, j, eol);
376
14.0M
        j = i;
377
14.0M
    }
378
3.41k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
3.41k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
384