Coverage Report

Created: 2026-04-20 06:11

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
/* 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
110M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
23.8M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
30.3M
    sub = STRINGLIB_NEW((data) + (left),        \
22
30.3M
                        (right) - (left));      \
23
30.3M
    if (sub == NULL)                            \
24
30.3M
        goto onError;                           \
25
30.3M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
30.3M
    else                                        \
30
30.3M
        Py_DECREF(sub);
31
32
59.9M
#define SPLIT_ADD(data, left, right) {          \
33
59.9M
    sub = STRINGLIB_NEW((data) + (left),        \
34
59.9M
                        (right) - (left));      \
35
59.9M
    if (sub == NULL)                            \
36
59.9M
        goto onError;                           \
37
59.9M
    if (count < MAX_PREALLOC) {                 \
38
37.3M
        PyList_SET_ITEM(list, count, sub);      \
39
37.3M
    } else {                                    \
40
22.6M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
22.6M
        else                                    \
45
22.6M
            Py_DECREF(sub);                     \
46
22.6M
    }                                           \
47
59.9M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
23.8M
#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
155k
{
58
155k
    Py_ssize_t i, j, count=0;
59
155k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
155k
    PyObject *sub;
61
62
155k
    if (list == NULL)
63
0
        return NULL;
64
65
155k
    i = j = 0;
66
1.71M
    while (maxcount-- > 0) {
67
3.30M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
1.61M
            i++;
69
1.68M
        if (i == str_len) break;
70
1.59M
        j = i; i++;
71
128M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
127M
            i++;
73
#if !STRINGLIB_MUTABLE
74
1.59M
        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
1.55M
#endif
82
4.67M
        SPLIT_ADD(str, j, i);
83
4.67M
    }
84
85
155k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
61.7k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
35.1k
            i++;
90
26.6k
        if (i != str_len)
91
26.6k
            SPLIT_ADD(str, i, str_len);
92
26.6k
    }
93
155k
    FIX_PREALLOC_SIZE(list);
94
155k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
155k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
73.1k
{
58
73.1k
    Py_ssize_t i, j, count=0;
59
73.1k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
73.1k
    PyObject *sub;
61
62
73.1k
    if (list == NULL)
63
0
        return NULL;
64
65
73.1k
    i = j = 0;
66
539k
    while (maxcount-- > 0) {
67
965k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
442k
            i++;
69
522k
        if (i == str_len) break;
70
489k
        j = i; i++;
71
46.9M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
46.5M
            i++;
73
489k
#if !STRINGLIB_MUTABLE
74
489k
        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.7k
            Py_INCREF(str_obj);
77
23.7k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
23.7k
            count++;
79
23.7k
            break;
80
23.7k
        }
81
466k
#endif
82
1.39M
        SPLIT_ADD(str, j, i);
83
1.39M
    }
84
85
73.1k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
32.0k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
18.1k
            i++;
90
13.9k
        if (i != str_len)
91
13.9k
            SPLIT_ADD(str, i, str_len);
92
13.9k
    }
93
73.1k
    FIX_PREALLOC_SIZE(list);
94
73.1k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
73.1k
}
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
602k
    while (maxcount-- > 0) {
67
1.14M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
559k
            i++;
69
589k
        if (i == str_len) break;
70
578k
        j = i; i++;
71
39.0M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
38.5M
            i++;
73
578k
#if !STRINGLIB_MUTABLE
74
578k
        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.59k
            Py_INCREF(str_obj);
77
2.59k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.59k
            count++;
79
2.59k
            break;
80
2.59k
        }
81
575k
#endif
82
1.72M
        SPLIT_ADD(str, j, i);
83
1.72M
    }
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
28.1k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
16.2k
            i++;
90
11.9k
        if (i != str_len)
91
11.9k
            SPLIT_ADD(str, i, str_len);
92
11.9k
    }
93
26.7k
    FIX_PREALLOC_SIZE(list);
94
26.7k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
26.7k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
44.9k
{
58
44.9k
    Py_ssize_t i, j, count=0;
59
44.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
44.9k
    PyObject *sub;
61
62
44.9k
    if (list == NULL)
63
0
        return NULL;
64
65
44.9k
    i = j = 0;
66
506k
    while (maxcount-- > 0) {
67
1.06M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
563k
            i++;
69
505k
        if (i == str_len) break;
70
473k
        j = i; i++;
71
31.6M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
31.1M
            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
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
461k
#endif
82
1.38M
        SPLIT_ADD(str, j, i);
83
1.38M
    }
84
85
44.9k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
1.52k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
762
            i++;
90
762
        if (i != str_len)
91
762
            SPLIT_ADD(str, i, str_len);
92
762
    }
93
44.9k
    FIX_PREALLOC_SIZE(list);
94
44.9k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
44.9k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
10.4k
{
58
10.4k
    Py_ssize_t i, j, count=0;
59
10.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
10.4k
    PyObject *sub;
61
62
10.4k
    if (list == NULL)
63
0
        return NULL;
64
65
10.4k
    i = j = 0;
66
64.7k
    while (maxcount-- > 0) {
67
118k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
54.2k
            i++;
69
64.4k
        if (i == str_len) break;
70
57.3k
        j = i; i++;
71
11.0M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
10.9M
            i++;
73
57.3k
#if !STRINGLIB_MUTABLE
74
57.3k
        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.07k
            Py_INCREF(str_obj);
77
3.07k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.07k
            count++;
79
3.07k
            break;
80
3.07k
        }
81
54.2k
#endif
82
162k
        SPLIT_ADD(str, j, i);
83
162k
    }
84
85
10.4k
    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.4k
    FIX_PREALLOC_SIZE(list);
94
10.4k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
10.4k
}
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
23.5M
{
107
23.5M
    Py_ssize_t i, j, count=0;
108
23.5M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
23.5M
    PyObject *sub;
110
111
23.5M
    if (list == NULL)
112
0
        return NULL;
113
114
23.5M
    i = j = 0;
115
85.1M
    while ((j < str_len) && (maxcount-- > 0)) {
116
457M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
435M
            if (str[j] == ch) {
119
40.3M
                SPLIT_ADD(str, i, j);
120
40.3M
                i = j = j + 1;
121
40.3M
                break;
122
40.3M
            }
123
435M
        }
124
61.6M
    }
125
#if !STRINGLIB_MUTABLE
126
23.5M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
5.74M
        Py_INCREF(str_obj);
129
5.74M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
5.74M
        count++;
131
5.74M
    } else
132
17.7M
#endif
133
17.7M
    if (i <= str_len) {
134
35.5M
        SPLIT_ADD(str, i, str_len);
135
35.5M
    }
136
23.5M
    FIX_PREALLOC_SIZE(list);
137
23.5M
    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.93M
{
107
2.93M
    Py_ssize_t i, j, count=0;
108
2.93M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
2.93M
    PyObject *sub;
110
111
2.93M
    if (list == NULL)
112
0
        return NULL;
113
114
2.93M
    i = j = 0;
115
12.3M
    while ((j < str_len) && (maxcount-- > 0)) {
116
84.8M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
82.4M
            if (str[j] == ch) {
119
6.97M
                SPLIT_ADD(str, i, j);
120
6.97M
                i = j = j + 1;
121
6.97M
                break;
122
6.97M
            }
123
82.4M
        }
124
9.45M
    }
125
2.93M
#if !STRINGLIB_MUTABLE
126
2.93M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.39M
        Py_INCREF(str_obj);
129
2.39M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.39M
        count++;
131
2.39M
    } else
132
546k
#endif
133
546k
    if (i <= str_len) {
134
1.09M
        SPLIT_ADD(str, i, str_len);
135
1.09M
    }
136
2.93M
    FIX_PREALLOC_SIZE(list);
137
2.93M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
2.93M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
19.1M
{
107
19.1M
    Py_ssize_t i, j, count=0;
108
19.1M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
19.1M
    PyObject *sub;
110
111
19.1M
    if (list == NULL)
112
0
        return NULL;
113
114
19.1M
    i = j = 0;
115
58.6M
    while ((j < str_len) && (maxcount-- > 0)) {
116
248M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
230M
            if (str[j] == ch) {
119
21.1M
                SPLIT_ADD(str, i, j);
120
21.1M
                i = j = j + 1;
121
21.1M
                break;
122
21.1M
            }
123
230M
        }
124
39.5M
    }
125
19.1M
#if !STRINGLIB_MUTABLE
126
19.1M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
3.05M
        Py_INCREF(str_obj);
129
3.05M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
3.05M
        count++;
131
3.05M
    } else
132
16.0M
#endif
133
16.0M
    if (i <= str_len) {
134
32.1M
        SPLIT_ADD(str, i, str_len);
135
32.1M
    }
136
19.1M
    FIX_PREALLOC_SIZE(list);
137
19.1M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
19.1M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.25M
{
107
1.25M
    Py_ssize_t i, j, count=0;
108
1.25M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.25M
    PyObject *sub;
110
111
1.25M
    if (list == NULL)
112
0
        return NULL;
113
114
1.25M
    i = j = 0;
115
9.64M
    while ((j < str_len) && (maxcount-- > 0)) {
116
63.1M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
62.9M
            if (str[j] == ch) {
119
8.13M
                SPLIT_ADD(str, i, j);
120
8.13M
                i = j = j + 1;
121
8.13M
                break;
122
8.13M
            }
123
62.9M
        }
124
8.38M
    }
125
1.25M
#if !STRINGLIB_MUTABLE
126
1.25M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
227k
        Py_INCREF(str_obj);
129
227k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
227k
        count++;
131
227k
    } else
132
1.03M
#endif
133
1.03M
    if (i <= str_len) {
134
2.06M
        SPLIT_ADD(str, i, str_len);
135
2.06M
    }
136
1.25M
    FIX_PREALLOC_SIZE(list);
137
1.25M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.25M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
151k
{
107
151k
    Py_ssize_t i, j, count=0;
108
151k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
151k
    PyObject *sub;
110
111
151k
    if (list == NULL)
112
0
        return NULL;
113
114
151k
    i = j = 0;
115
4.18M
    while ((j < str_len) && (maxcount-- > 0)) {
116
39.4M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
39.3M
            if (str[j] == ch) {
119
3.91M
                SPLIT_ADD(str, i, j);
120
3.91M
                i = j = j + 1;
121
3.91M
                break;
122
3.91M
            }
123
39.3M
        }
124
4.03M
    }
125
151k
#if !STRINGLIB_MUTABLE
126
151k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
74.1k
        Py_INCREF(str_obj);
129
74.1k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
74.1k
        count++;
131
74.1k
    } else
132
77.6k
#endif
133
77.6k
    if (i <= str_len) {
134
155k
        SPLIT_ADD(str, i, str_len);
135
155k
    }
136
151k
    FIX_PREALLOC_SIZE(list);
137
151k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
151k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
14.4k
{
107
14.4k
    Py_ssize_t i, j, count=0;
108
14.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
14.4k
    PyObject *sub;
110
111
14.4k
    if (list == NULL)
112
0
        return NULL;
113
114
14.4k
    i = j = 0;
115
244k
    while ((j < str_len) && (maxcount-- > 0)) {
116
21.0M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
21.0M
            if (str[j] == ch) {
119
217k
                SPLIT_ADD(str, i, j);
120
217k
                i = j = j + 1;
121
217k
                break;
122
217k
            }
123
21.0M
        }
124
229k
    }
125
14.4k
#if !STRINGLIB_MUTABLE
126
14.4k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
882
        Py_INCREF(str_obj);
129
882
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
882
        count++;
131
882
    } else
132
13.5k
#endif
133
13.5k
    if (i <= str_len) {
134
27.1k
        SPLIT_ADD(str, i, str_len);
135
27.1k
    }
136
14.4k
    FIX_PREALLOC_SIZE(list);
137
14.4k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
14.4k
}
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
23.6M
{
150
23.6M
    Py_ssize_t i, j, pos, count=0;
151
23.6M
    PyObject *list, *sub;
152
153
23.6M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
23.6M
    else if (sep_len == 1)
158
23.5M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
189k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
189k
    if (list == NULL)
162
0
        return NULL;
163
164
189k
    i = j = 0;
165
334k
    while (maxcount-- > 0) {
166
189k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
189k
        if (pos < 0)
168
45.4k
            break;
169
144k
        j = i + pos;
170
288k
        SPLIT_ADD(str, i, j);
171
288k
        i = j + sep_len;
172
288k
    }
173
#if !STRINGLIB_MUTABLE
174
189k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
45.4k
        Py_INCREF(str_obj);
177
45.4k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
45.4k
        count++;
179
45.4k
    } else
180
144k
#endif
181
144k
    {
182
288k
        SPLIT_ADD(str, i, str_len);
183
288k
    }
184
189k
    FIX_PREALLOC_SIZE(list);
185
189k
    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.93M
{
150
2.93M
    Py_ssize_t i, j, pos, count=0;
151
2.93M
    PyObject *list, *sub;
152
153
2.93M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
2.93M
    else if (sep_len == 1)
158
2.93M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
0
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
0
    if (list == NULL)
162
0
        return NULL;
163
164
0
    i = j = 0;
165
0
    while (maxcount-- > 0) {
166
0
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
0
        if (pos < 0)
168
0
            break;
169
0
        j = i + pos;
170
0
        SPLIT_ADD(str, i, j);
171
0
        i = j + sep_len;
172
0
    }
173
0
#if !STRINGLIB_MUTABLE
174
0
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
0
        Py_INCREF(str_obj);
177
0
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
0
        count++;
179
0
    } else
180
0
#endif
181
0
    {
182
0
        SPLIT_ADD(str, i, str_len);
183
0
    }
184
0
    FIX_PREALLOC_SIZE(list);
185
0
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
0
}
unicodeobject.c:asciilib_split
Line
Count
Source
149
19.2M
{
150
19.2M
    Py_ssize_t i, j, pos, count=0;
151
19.2M
    PyObject *list, *sub;
152
153
19.2M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
19.2M
    else if (sep_len == 1)
158
19.1M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
76.9k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
76.9k
    if (list == NULL)
162
0
        return NULL;
163
164
76.9k
    i = j = 0;
165
123k
    while (maxcount-- > 0) {
166
76.9k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
76.9k
        if (pos < 0)
168
30.1k
            break;
169
46.8k
        j = i + pos;
170
93.6k
        SPLIT_ADD(str, i, j);
171
93.6k
        i = j + sep_len;
172
93.6k
    }
173
76.9k
#if !STRINGLIB_MUTABLE
174
76.9k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
30.1k
        Py_INCREF(str_obj);
177
30.1k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
30.1k
        count++;
179
30.1k
    } else
180
46.8k
#endif
181
46.8k
    {
182
93.6k
        SPLIT_ADD(str, i, str_len);
183
93.6k
    }
184
76.9k
    FIX_PREALLOC_SIZE(list);
185
76.9k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
76.9k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.27M
{
150
1.27M
    Py_ssize_t i, j, pos, count=0;
151
1.27M
    PyObject *list, *sub;
152
153
1.27M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.27M
    else if (sep_len == 1)
158
1.25M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
16.3k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
16.3k
    if (list == NULL)
162
0
        return NULL;
163
164
16.3k
    i = j = 0;
165
30.7k
    while (maxcount-- > 0) {
166
16.3k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
16.3k
        if (pos < 0)
168
1.85k
            break;
169
14.4k
        j = i + pos;
170
28.9k
        SPLIT_ADD(str, i, j);
171
28.9k
        i = j + sep_len;
172
28.9k
    }
173
16.3k
#if !STRINGLIB_MUTABLE
174
16.3k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
1.85k
        Py_INCREF(str_obj);
177
1.85k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
1.85k
        count++;
179
1.85k
    } else
180
14.4k
#endif
181
14.4k
    {
182
28.9k
        SPLIT_ADD(str, i, str_len);
183
28.9k
    }
184
16.3k
    FIX_PREALLOC_SIZE(list);
185
16.3k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
16.3k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
230k
{
150
230k
    Py_ssize_t i, j, pos, count=0;
151
230k
    PyObject *list, *sub;
152
153
230k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
230k
    else if (sep_len == 1)
158
151k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
78.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
78.2k
    if (list == NULL)
162
0
        return NULL;
163
164
78.2k
    i = j = 0;
165
145k
    while (maxcount-- > 0) {
166
78.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
78.2k
        if (pos < 0)
168
10.9k
            break;
169
67.3k
        j = i + pos;
170
134k
        SPLIT_ADD(str, i, j);
171
134k
        i = j + sep_len;
172
134k
    }
173
78.2k
#if !STRINGLIB_MUTABLE
174
78.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
10.9k
        Py_INCREF(str_obj);
177
10.9k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
10.9k
        count++;
179
10.9k
    } else
180
67.3k
#endif
181
67.3k
    {
182
134k
        SPLIT_ADD(str, i, str_len);
183
134k
    }
184
78.2k
    FIX_PREALLOC_SIZE(list);
185
78.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
78.2k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
32.6k
{
150
32.6k
    Py_ssize_t i, j, pos, count=0;
151
32.6k
    PyObject *list, *sub;
152
153
32.6k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
32.6k
    else if (sep_len == 1)
158
14.4k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
18.1k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
18.1k
    if (list == NULL)
162
0
        return NULL;
163
164
18.1k
    i = j = 0;
165
33.8k
    while (maxcount-- > 0) {
166
18.1k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
18.1k
        if (pos < 0)
168
2.49k
            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
18.1k
#if !STRINGLIB_MUTABLE
174
18.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.49k
        Py_INCREF(str_obj);
177
2.49k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.49k
        count++;
179
2.49k
    } else
180
15.6k
#endif
181
15.6k
    {
182
31.3k
        SPLIT_ADD(str, i, str_len);
183
31.3k
    }
184
18.1k
    FIX_PREALLOC_SIZE(list);
185
18.1k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
18.1k
}
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
66
{
248
66
    Py_ssize_t i, j, count=0;
249
66
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
66
    PyObject *sub;
251
252
66
    if (list == NULL)
253
0
        return NULL;
254
255
66
    i = j = str_len - 1;
256
132
    while ((i >= 0) && (maxcount-- > 0)) {
257
138
        for(; i >= 0; i--) {
258
138
            if (str[i] == ch) {
259
66
                SPLIT_ADD(str, i + 1, j + 1);
260
66
                j = i = i - 1;
261
66
                break;
262
66
            }
263
138
        }
264
66
    }
265
#if !STRINGLIB_MUTABLE
266
66
    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
66
#endif
273
66
    if (j >= -1) {
274
132
        SPLIT_ADD(str, 0, j + 1);
275
132
    }
276
66
    FIX_PREALLOC_SIZE(list);
277
66
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
66
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
0
    return NULL;
284
66
}
Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char
unicodeobject.c:asciilib_rsplit_char
Line
Count
Source
247
66
{
248
66
    Py_ssize_t i, j, count=0;
249
66
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
66
    PyObject *sub;
251
252
66
    if (list == NULL)
253
0
        return NULL;
254
255
66
    i = j = str_len - 1;
256
132
    while ((i >= 0) && (maxcount-- > 0)) {
257
138
        for(; i >= 0; i--) {
258
138
            if (str[i] == ch) {
259
66
                SPLIT_ADD(str, i + 1, j + 1);
260
66
                j = i = i - 1;
261
66
                break;
262
66
            }
263
138
        }
264
66
    }
265
66
#if !STRINGLIB_MUTABLE
266
66
    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
66
#endif
273
66
    if (j >= -1) {
274
132
        SPLIT_ADD(str, 0, j + 1);
275
132
    }
276
66
    FIX_PREALLOC_SIZE(list);
277
66
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
66
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
    return NULL;
284
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
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
66
{
292
66
    Py_ssize_t j, pos, count=0;
293
66
    PyObject *list, *sub;
294
295
66
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
66
    else if (sep_len == 1)
300
66
        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
66
{
292
66
    Py_ssize_t j, pos, count=0;
293
66
    PyObject *list, *sub;
294
295
66
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
66
    else if (sep_len == 1)
300
66
        return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount);
301
302
0
    list = PyList_New(PREALLOC_SIZE(maxcount));
303
0
    if (list == NULL)
304
0
        return NULL;
305
306
0
    j = str_len;
307
0
    while (maxcount-- > 0) {
308
0
        pos = FASTSEARCH(str, j, sep, sep_len, -1, FAST_RSEARCH);
309
0
        if (pos < 0)
310
0
            break;
311
0
        SPLIT_ADD(str, pos + sep_len, j);
312
0
        j = pos;
313
0
    }
314
0
#if !STRINGLIB_MUTABLE
315
0
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
316
        /* No match in str_obj, so just use it as list[0] */
317
0
        Py_INCREF(str_obj);
318
0
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
319
0
        count++;
320
0
    } else
321
0
#endif
322
0
    {
323
0
        SPLIT_ADD(str, 0, j);
324
0
    }
325
0
    FIX_PREALLOC_SIZE(list);
326
0
    if (PyList_Reverse(list) < 0)
327
0
        goto onError;
328
0
    return list;
329
330
0
  onError:
331
0
    Py_DECREF(list);
332
    return NULL;
333
0
}
Unexecuted instantiation: unicodeobject.c:ucs1lib_rsplit
Unexecuted instantiation: unicodeobject.c:ucs2lib_rsplit
Unexecuted instantiation: unicodeobject.c:ucs4lib_rsplit
Unexecuted instantiation: bytearrayobject.c:stringlib_rsplit
334
335
Py_LOCAL_INLINE(PyObject *)
336
STRINGLIB(splitlines)(PyObject* str_obj,
337
                     const STRINGLIB_CHAR* str, Py_ssize_t str_len,
338
                     int keepends)
339
17.3k
{
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
17.3k
    Py_ssize_t i;
349
17.3k
    Py_ssize_t j;
350
17.3k
    PyObject *list = PyList_New(0);
351
17.3k
    PyObject *sub;
352
353
17.3k
    if (list == NULL)
354
0
        return NULL;
355
356
30.3M
    for (i = j = 0; i < str_len; ) {
357
30.3M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
131M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
100M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
30.3M
        eol = i;
365
30.3M
        if (i < str_len) {
366
30.3M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
27.9k
                i += 2;
368
30.3M
            else
369
30.3M
                i++;
370
30.3M
            if (keepends)
371
0
                eol = i;
372
30.3M
        }
373
#if !STRINGLIB_MUTABLE
374
30.3M
        if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
375
            /* No linebreak in str_obj, so just use it as list[0] */
376
7.26k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
7.26k
            break;
379
7.26k
        }
380
30.3M
#endif
381
60.7M
        SPLIT_APPEND(str, j, eol);
382
30.3M
        j = i;
383
30.3M
    }
384
17.3k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
17.3k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
3.89k
{
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.89k
    Py_ssize_t i;
349
3.89k
    Py_ssize_t j;
350
3.89k
    PyObject *list = PyList_New(0);
351
3.89k
    PyObject *sub;
352
353
3.89k
    if (list == NULL)
354
0
        return NULL;
355
356
5.59M
    for (i = j = 0; i < str_len; ) {
357
5.59M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
12.9M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
7.35M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
5.59M
        eol = i;
365
5.59M
        if (i < str_len) {
366
5.58M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
871
                i += 2;
368
5.58M
            else
369
5.58M
                i++;
370
5.58M
            if (keepends)
371
0
                eol = i;
372
5.58M
        }
373
5.59M
#if !STRINGLIB_MUTABLE
374
5.59M
        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.19k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.19k
            break;
379
1.19k
        }
380
5.58M
#endif
381
11.1M
        SPLIT_APPEND(str, j, eol);
382
5.58M
        j = i;
383
5.58M
    }
384
3.89k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
3.89k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
985
{
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
985
    Py_ssize_t i;
349
985
    Py_ssize_t j;
350
985
    PyObject *list = PyList_New(0);
351
985
    PyObject *sub;
352
353
985
    if (list == NULL)
354
0
        return NULL;
355
356
1.97M
    for (i = j = 0; i < str_len; ) {
357
1.97M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
10.1M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
8.18M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
1.97M
        eol = i;
365
1.97M
        if (i < str_len) {
366
1.97M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
591
                i += 2;
368
1.97M
            else
369
1.97M
                i++;
370
1.97M
            if (keepends)
371
0
                eol = i;
372
1.97M
        }
373
1.97M
#if !STRINGLIB_MUTABLE
374
1.97M
        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
275
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
275
            break;
379
275
        }
380
1.97M
#endif
381
3.94M
        SPLIT_APPEND(str, j, eol);
382
1.97M
        j = i;
383
1.97M
    }
384
985
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
985
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
8.96k
{
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
8.96k
    Py_ssize_t i;
349
8.96k
    Py_ssize_t j;
350
8.96k
    PyObject *list = PyList_New(0);
351
8.96k
    PyObject *sub;
352
353
8.96k
    if (list == NULL)
354
0
        return NULL;
355
356
11.0M
    for (i = j = 0; i < str_len; ) {
357
11.0M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
52.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
41.0M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
11.0M
        eol = i;
365
11.0M
        if (i < str_len) {
366
11.0M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
11.5k
                i += 2;
368
11.0M
            else
369
11.0M
                i++;
370
11.0M
            if (keepends)
371
0
                eol = i;
372
11.0M
        }
373
11.0M
#if !STRINGLIB_MUTABLE
374
11.0M
        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
4.17k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
4.17k
            break;
379
4.17k
        }
380
11.0M
#endif
381
22.1M
        SPLIT_APPEND(str, j, eol);
382
11.0M
        j = i;
383
11.0M
    }
384
8.96k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
8.96k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
3.52k
{
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.52k
    Py_ssize_t i;
349
3.52k
    Py_ssize_t j;
350
3.52k
    PyObject *list = PyList_New(0);
351
3.52k
    PyObject *sub;
352
353
3.52k
    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
56.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
44.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
14.8k
                i += 2;
368
11.7M
            else
369
11.7M
                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.61k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.61k
            break;
379
1.61k
        }
380
11.7M
#endif
381
23.5M
        SPLIT_APPEND(str, j, eol);
382
11.7M
        j = i;
383
11.7M
    }
384
3.52k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
3.52k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390