Coverage Report

Created: 2026-10-31 06:21

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
123M
#define MAX_PREALLOC 12
17
18
/* 5 splits gives 6 elements */
19
#define PREALLOC_SIZE(maxsplit) \
20
23.4M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
21
22
#define SPLIT_APPEND(data, left, right)         \
23
44.9M
    sub = STRINGLIB_NEW((data) + (left),        \
24
44.9M
                        (right) - (left));      \
25
44.9M
    if (sub == NULL)                            \
26
44.9M
        goto onError;                           \
27
44.9M
    if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
28
44.9M
        goto onError;
29
30
72.3M
#define SPLIT_ADD(data, left, right) {          \
31
72.3M
    sub = STRINGLIB_NEW((data) + (left),        \
32
72.3M
                        (right) - (left));      \
33
72.3M
    if (sub == NULL)                            \
34
72.3M
        goto onError;                           \
35
72.3M
    if (count < MAX_PREALLOC) {                 \
36
35.5M
        PyList_SET_ITEM(list, count, sub);      \
37
36.7M
    } else {                                    \
38
36.7M
        if (_PyList_AppendTakeRef((PyListObject *)list, sub)) \
39
36.7M
            goto onError;                       \
40
36.7M
    }                                           \
41
72.3M
    count++; }
42
43
44
/* Always force the list to the expected size. */
45
23.4M
#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
163k
{
52
163k
    Py_ssize_t i, j, count=0;
53
163k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
163k
    PyObject *sub;
55
56
163k
    if (list == NULL)
57
0
        return NULL;
58
59
163k
    i = j = 0;
60
2.03M
    while (maxcount-- > 0) {
61
3.94M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
1.93M
            i++;
63
2.00M
        if (i == str_len) break;
64
1.90M
        j = i; i++;
65
143M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
141M
            i++;
67
#if !STRINGLIB_MUTABLE
68
1.90M
        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.9k
            Py_INCREF(str_obj);
71
39.9k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
39.9k
            count++;
73
39.9k
            break;
74
39.9k
        }
75
1.86M
#endif
76
5.59M
        SPLIT_ADD(str, j, i);
77
5.59M
    }
78
79
163k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
44.6k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
23.7k
            i++;
84
20.9k
        if (i != str_len)
85
20.9k
            SPLIT_ADD(str, i, str_len);
86
20.9k
    }
87
163k
    FIX_PREALLOC_SIZE(list);
88
163k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
0
    return NULL;
93
163k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
51
69.6k
{
52
69.6k
    Py_ssize_t i, j, count=0;
53
69.6k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
69.6k
    PyObject *sub;
55
56
69.6k
    if (list == NULL)
57
0
        return NULL;
58
59
69.6k
    i = j = 0;
60
545k
    while (maxcount-- > 0) {
61
987k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
456k
            i++;
63
531k
        if (i == str_len) break;
64
496k
        j = i; i++;
65
40.0M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
39.5M
            i++;
67
496k
#if !STRINGLIB_MUTABLE
68
496k
        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.4k
            Py_INCREF(str_obj);
71
20.4k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
20.4k
            count++;
73
20.4k
            break;
74
20.4k
        }
75
475k
#endif
76
1.42M
        SPLIT_ADD(str, j, i);
77
1.42M
    }
78
79
69.6k
    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.7k
            i++;
84
12.9k
        if (i != str_len)
85
12.9k
            SPLIT_ADD(str, i, str_len);
86
12.9k
    }
87
69.6k
    FIX_PREALLOC_SIZE(list);
88
69.6k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
69.6k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
51
23.9k
{
52
23.9k
    Py_ssize_t i, j, count=0;
53
23.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
23.9k
    PyObject *sub;
55
56
23.9k
    if (list == NULL)
57
0
        return NULL;
58
59
23.9k
    i = j = 0;
60
685k
    while (maxcount-- > 0) {
61
1.32M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
650k
            i++;
63
677k
        if (i == str_len) break;
64
663k
        j = i; i++;
65
44.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
43.8M
            i++;
67
663k
#if !STRINGLIB_MUTABLE
68
663k
        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.33k
            Py_INCREF(str_obj);
71
1.33k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
1.33k
            count++;
73
1.33k
            break;
74
1.33k
        }
75
661k
#endif
76
1.98M
        SPLIT_ADD(str, j, i);
77
1.98M
    }
78
79
23.9k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
16.4k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
9.21k
            i++;
84
7.22k
        if (i != str_len)
85
7.22k
            SPLIT_ADD(str, i, str_len);
86
7.22k
    }
87
23.9k
    FIX_PREALLOC_SIZE(list);
88
23.9k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
23.9k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
51
55.4k
{
52
55.4k
    Py_ssize_t i, j, count=0;
53
55.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
55.4k
    PyObject *sub;
55
56
55.4k
    if (list == NULL)
57
0
        return NULL;
58
59
55.4k
    i = j = 0;
60
617k
    while (maxcount-- > 0) {
61
1.27M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
655k
            i++;
63
616k
        if (i == str_len) break;
64
577k
        j = i; i++;
65
44.3M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
43.7M
            i++;
67
577k
#if !STRINGLIB_MUTABLE
68
577k
        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
14.8k
            Py_INCREF(str_obj);
71
14.8k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
14.8k
            count++;
73
14.8k
            break;
74
14.8k
        }
75
562k
#endif
76
1.68M
        SPLIT_ADD(str, j, i);
77
1.68M
    }
78
79
55.4k
    if (i < str_len) {
80
        /* Only occurs when maxcount was reached */
81
        /* Skip any remaining whitespace and copy to end of string */
82
1.44k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
83
722
            i++;
84
722
        if (i != str_len)
85
722
            SPLIT_ADD(str, i, str_len);
86
722
    }
87
55.4k
    FIX_PREALLOC_SIZE(list);
88
55.4k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
55.4k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
51
14.8k
{
52
14.8k
    Py_ssize_t i, j, count=0;
53
14.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
54
14.8k
    PyObject *sub;
55
56
14.8k
    if (list == NULL)
57
0
        return NULL;
58
59
14.8k
    i = j = 0;
60
181k
    while (maxcount-- > 0) {
61
355k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
62
174k
            i++;
63
181k
        if (i == str_len) break;
64
169k
        j = i; i++;
65
14.8M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
66
14.6M
            i++;
67
169k
#if !STRINGLIB_MUTABLE
68
169k
        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.37k
            Py_INCREF(str_obj);
71
3.37k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
72
3.37k
            count++;
73
3.37k
            break;
74
3.37k
        }
75
166k
#endif
76
499k
        SPLIT_ADD(str, j, i);
77
499k
    }
78
79
14.8k
    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
14.8k
    FIX_PREALLOC_SIZE(list);
88
14.8k
    return list;
89
90
0
  onError:
91
0
    Py_DECREF(list);
92
    return NULL;
93
14.8k
}
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
23.0M
{
101
23.0M
    Py_ssize_t i, j, count=0;
102
23.0M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
23.0M
    PyObject *sub;
104
105
23.0M
    if (list == NULL)
106
0
        return NULL;
107
108
23.0M
    i = j = 0;
109
97.1M
    while ((j < str_len) && (maxcount-- > 0)) {
110
535M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
514M
            if (str[j] == ch) {
113
53.4M
                SPLIT_ADD(str, i, j);
114
53.4M
                i = j = j + 1;
115
53.4M
                break;
116
53.4M
            }
117
514M
        }
118
74.0M
    }
119
#if !STRINGLIB_MUTABLE
120
23.0M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
6.26M
        Py_INCREF(str_obj);
123
6.26M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
6.26M
        count++;
125
6.26M
    } else
126
16.7M
#endif
127
16.7M
    if (i <= str_len) {
128
33.5M
        SPLIT_ADD(str, i, str_len);
129
33.5M
    }
130
23.0M
    FIX_PREALLOC_SIZE(list);
131
23.0M
    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.51M
{
101
3.51M
    Py_ssize_t i, j, count=0;
102
3.51M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
3.51M
    PyObject *sub;
104
105
3.51M
    if (list == NULL)
106
0
        return NULL;
107
108
3.51M
    i = j = 0;
109
24.5M
    while ((j < str_len) && (maxcount-- > 0)) {
110
153M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
150M
            if (str[j] == ch) {
113
17.9M
                SPLIT_ADD(str, i, j);
114
17.9M
                i = j = j + 1;
115
17.9M
                break;
116
17.9M
            }
117
150M
        }
118
21.0M
    }
119
3.51M
#if !STRINGLIB_MUTABLE
120
3.51M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
2.93M
        Py_INCREF(str_obj);
123
2.93M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
2.93M
        count++;
125
2.93M
    } else
126
584k
#endif
127
584k
    if (i <= str_len) {
128
1.16M
        SPLIT_ADD(str, i, str_len);
129
1.16M
    }
130
3.51M
    FIX_PREALLOC_SIZE(list);
131
3.51M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
3.51M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
100
18.0M
{
101
18.0M
    Py_ssize_t i, j, count=0;
102
18.0M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
18.0M
    PyObject *sub;
104
105
18.0M
    if (list == NULL)
106
0
        return NULL;
107
108
18.0M
    i = j = 0;
109
55.4M
    while ((j < str_len) && (maxcount-- > 0)) {
110
230M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
213M
            if (str[j] == ch) {
113
20.0M
                SPLIT_ADD(str, i, j);
114
20.0M
                i = j = j + 1;
115
20.0M
                break;
116
20.0M
            }
117
213M
        }
118
37.3M
    }
119
18.0M
#if !STRINGLIB_MUTABLE
120
18.0M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
3.12M
        Py_INCREF(str_obj);
123
3.12M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
3.12M
        count++;
125
3.12M
    } else
126
14.9M
#endif
127
14.9M
    if (i <= str_len) {
128
29.9M
        SPLIT_ADD(str, i, str_len);
129
29.9M
    }
130
18.0M
    FIX_PREALLOC_SIZE(list);
131
18.0M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
18.0M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
100
1.29M
{
101
1.29M
    Py_ssize_t i, j, count=0;
102
1.29M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
1.29M
    PyObject *sub;
104
105
1.29M
    if (list == NULL)
106
0
        return NULL;
107
108
1.29M
    i = j = 0;
109
10.9M
    while ((j < str_len) && (maxcount-- > 0)) {
110
70.5M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
70.3M
            if (str[j] == ch) {
113
9.44M
                SPLIT_ADD(str, i, j);
114
9.44M
                i = j = j + 1;
115
9.44M
                break;
116
9.44M
            }
117
70.3M
        }
118
9.66M
    }
119
1.29M
#if !STRINGLIB_MUTABLE
120
1.29M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
183k
        Py_INCREF(str_obj);
123
183k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
183k
        count++;
125
183k
    } else
126
1.10M
#endif
127
1.10M
    if (i <= str_len) {
128
2.21M
        SPLIT_ADD(str, i, str_len);
129
2.21M
    }
130
1.29M
    FIX_PREALLOC_SIZE(list);
131
1.29M
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
1.29M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
100
121k
{
101
121k
    Py_ssize_t i, j, count=0;
102
121k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
121k
    PyObject *sub;
104
105
121k
    if (list == NULL)
106
0
        return NULL;
107
108
121k
    i = j = 0;
109
4.81M
    while ((j < str_len) && (maxcount-- > 0)) {
110
54.9M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
54.8M
            if (str[j] == ch) {
113
4.61M
                SPLIT_ADD(str, i, j);
114
4.61M
                i = j = j + 1;
115
4.61M
                break;
116
4.61M
            }
117
54.8M
        }
118
4.69M
    }
119
121k
#if !STRINGLIB_MUTABLE
120
121k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
27.3k
        Py_INCREF(str_obj);
123
27.3k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
27.3k
        count++;
125
27.3k
    } else
126
93.8k
#endif
127
93.8k
    if (i <= str_len) {
128
187k
        SPLIT_ADD(str, i, str_len);
129
187k
    }
130
121k
    FIX_PREALLOC_SIZE(list);
131
121k
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
121k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
100
19.3k
{
101
19.3k
    Py_ssize_t i, j, count=0;
102
19.3k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
103
19.3k
    PyObject *sub;
104
105
19.3k
    if (list == NULL)
106
0
        return NULL;
107
108
19.3k
    i = j = 0;
109
1.40M
    while ((j < str_len) && (maxcount-- > 0)) {
110
25.7M
        for(; j < str_len; j++) {
111
            /* I found that using memchr makes no difference */
112
25.7M
            if (str[j] == ch) {
113
1.36M
                SPLIT_ADD(str, i, j);
114
1.36M
                i = j = j + 1;
115
1.36M
                break;
116
1.36M
            }
117
25.7M
        }
118
1.38M
    }
119
19.3k
#if !STRINGLIB_MUTABLE
120
19.3k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
121
        /* ch not in str_obj, so just use str_obj as list[0] */
122
1.02k
        Py_INCREF(str_obj);
123
1.02k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
124
1.02k
        count++;
125
1.02k
    } else
126
18.3k
#endif
127
18.3k
    if (i <= str_len) {
128
36.6k
        SPLIT_ADD(str, i, str_len);
129
36.6k
    }
130
19.3k
    FIX_PREALLOC_SIZE(list);
131
19.3k
    return list;
132
133
0
  onError:
134
0
    Py_DECREF(list);
135
    return NULL;
136
19.3k
}
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
23.2M
{
144
23.2M
    Py_ssize_t i, j, pos, count=0;
145
23.2M
    PyObject *list, *sub;
146
147
23.2M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
23.2M
    else if (sep_len == 1)
152
23.0M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
202k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
202k
    if (list == NULL)
156
0
        return NULL;
157
158
202k
    i = j = 0;
159
363k
    while (maxcount-- > 0) {
160
202k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
202k
        if (pos < 0)
162
41.7k
            break;
163
160k
        j = i + pos;
164
321k
        SPLIT_ADD(str, i, j);
165
321k
        i = j + sep_len;
166
321k
    }
167
#if !STRINGLIB_MUTABLE
168
202k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
41.7k
        Py_INCREF(str_obj);
171
41.7k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
41.7k
        count++;
173
41.7k
    } else
174
160k
#endif
175
160k
    {
176
321k
        SPLIT_ADD(str, i, str_len);
177
321k
    }
178
202k
    FIX_PREALLOC_SIZE(list);
179
202k
    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.51M
{
144
3.51M
    Py_ssize_t i, j, pos, count=0;
145
3.51M
    PyObject *list, *sub;
146
147
3.51M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
3.51M
    else if (sep_len == 1)
152
3.51M
        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.0M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
69.7k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
69.7k
    if (list == NULL)
156
0
        return NULL;
157
158
69.7k
    i = j = 0;
159
113k
    while (maxcount-- > 0) {
160
69.7k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
69.7k
        if (pos < 0)
162
26.2k
            break;
163
43.5k
        j = i + pos;
164
87.0k
        SPLIT_ADD(str, i, j);
165
87.0k
        i = j + sep_len;
166
87.0k
    }
167
69.7k
#if !STRINGLIB_MUTABLE
168
69.7k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
26.2k
        Py_INCREF(str_obj);
171
26.2k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
26.2k
        count++;
173
26.2k
    } else
174
43.5k
#endif
175
43.5k
    {
176
87.0k
        SPLIT_ADD(str, i, str_len);
177
87.0k
    }
178
69.7k
    FIX_PREALLOC_SIZE(list);
179
69.7k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
69.7k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
143
1.31M
{
144
1.31M
    Py_ssize_t i, j, pos, count=0;
145
1.31M
    PyObject *list, *sub;
146
147
1.31M
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
1.31M
    else if (sep_len == 1)
152
1.29M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
18.6k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
18.6k
    if (list == NULL)
156
0
        return NULL;
157
158
18.6k
    i = j = 0;
159
35.3k
    while (maxcount-- > 0) {
160
18.6k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
18.6k
        if (pos < 0)
162
1.98k
            break;
163
16.7k
        j = i + pos;
164
33.4k
        SPLIT_ADD(str, i, j);
165
33.4k
        i = j + sep_len;
166
33.4k
    }
167
18.6k
#if !STRINGLIB_MUTABLE
168
18.6k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
1.98k
        Py_INCREF(str_obj);
171
1.98k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
1.98k
        count++;
173
1.98k
    } else
174
16.7k
#endif
175
16.7k
    {
176
33.4k
        SPLIT_ADD(str, i, str_len);
177
33.4k
    }
178
18.6k
    FIX_PREALLOC_SIZE(list);
179
18.6k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
18.6k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
143
210k
{
144
210k
    Py_ssize_t i, j, pos, count=0;
145
210k
    PyObject *list, *sub;
146
147
210k
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
210k
    else if (sep_len == 1)
152
121k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
89.0k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
89.0k
    if (list == NULL)
156
0
        return NULL;
157
158
89.0k
    i = j = 0;
159
167k
    while (maxcount-- > 0) {
160
89.0k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
89.0k
        if (pos < 0)
162
10.8k
            break;
163
78.1k
        j = i + pos;
164
156k
        SPLIT_ADD(str, i, j);
165
156k
        i = j + sep_len;
166
156k
    }
167
89.0k
#if !STRINGLIB_MUTABLE
168
89.0k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
10.8k
        Py_INCREF(str_obj);
171
10.8k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
10.8k
        count++;
173
10.8k
    } else
174
78.1k
#endif
175
78.1k
    {
176
156k
        SPLIT_ADD(str, i, str_len);
177
156k
    }
178
89.0k
    FIX_PREALLOC_SIZE(list);
179
89.0k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
89.0k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
143
44.3k
{
144
44.3k
    Py_ssize_t i, j, pos, count=0;
145
44.3k
    PyObject *list, *sub;
146
147
44.3k
    if (sep_len == 0) {
148
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
149
0
        return NULL;
150
0
    }
151
44.3k
    else if (sep_len == 1)
152
19.3k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
153
154
25.0k
    list = PyList_New(PREALLOC_SIZE(maxcount));
155
25.0k
    if (list == NULL)
156
0
        return NULL;
157
158
25.0k
    i = j = 0;
159
47.3k
    while (maxcount-- > 0) {
160
25.0k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
161
25.0k
        if (pos < 0)
162
2.73k
            break;
163
22.3k
        j = i + pos;
164
44.6k
        SPLIT_ADD(str, i, j);
165
44.6k
        i = j + sep_len;
166
44.6k
    }
167
25.0k
#if !STRINGLIB_MUTABLE
168
25.0k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
169
        /* No match in str_obj, so just use it as list[0] */
170
2.73k
        Py_INCREF(str_obj);
171
2.73k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
172
2.73k
        count++;
173
2.73k
    } else
174
22.3k
#endif
175
22.3k
    {
176
44.6k
        SPLIT_ADD(str, i, str_len);
177
44.6k
    }
178
25.0k
    FIX_PREALLOC_SIZE(list);
179
25.0k
    return list;
180
181
0
  onError:
182
0
    Py_DECREF(list);
183
    return NULL;
184
25.0k
}
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
16.6k
{
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.6k
    Py_ssize_t i;
343
16.6k
    Py_ssize_t j;
344
16.6k
    PyObject *list = PyList_New(0);
345
16.6k
    PyObject *sub;
346
347
16.6k
    if (list == NULL)
348
0
        return NULL;
349
350
45.0M
    for (i = j = 0; i < str_len; ) {
351
45.0M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
147M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
102M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
45.0M
        eol = i;
359
45.0M
        if (i < str_len) {
360
44.9M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
15.8k
                i += 2;
362
44.9M
            else
363
44.9M
                i++;
364
44.9M
            if (keepends)
365
0
                eol = i;
366
44.9M
        }
367
#if !STRINGLIB_MUTABLE
368
45.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
6.61k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
6.61k
            break;
373
6.61k
        }
374
44.9M
#endif
375
89.9M
        SPLIT_APPEND(str, j, eol);
376
44.9M
        j = i;
377
44.9M
    }
378
16.6k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
16.6k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
333
4.16k
{
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.16k
    Py_ssize_t i;
343
4.16k
    Py_ssize_t j;
344
4.16k
    PyObject *list = PyList_New(0);
345
4.16k
    PyObject *sub;
346
347
4.16k
    if (list == NULL)
348
0
        return NULL;
349
350
9.19M
    for (i = j = 0; i < str_len; ) {
351
9.19M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
15.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
5.84M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
9.19M
        eol = i;
359
9.19M
        if (i < str_len) {
360
9.18M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
495
                i += 2;
362
9.18M
            else
363
9.18M
                i++;
364
9.18M
            if (keepends)
365
0
                eol = i;
366
9.18M
        }
367
9.19M
#if !STRINGLIB_MUTABLE
368
9.19M
        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.00k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
1.00k
            break;
373
1.00k
        }
374
9.19M
#endif
375
18.3M
        SPLIT_APPEND(str, j, eol);
376
9.19M
        j = i;
377
9.19M
    }
378
4.16k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
4.16k
}
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.81M
    for (i = j = 0; i < str_len; ) {
351
7.81M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
17.6M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
9.80M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
7.81M
        eol = i;
359
7.81M
        if (i < str_len) {
360
7.81M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
551
                i += 2;
362
7.80M
            else
363
7.80M
                i++;
364
7.81M
            if (keepends)
365
0
                eol = i;
366
7.81M
        }
367
7.81M
#if !STRINGLIB_MUTABLE
368
7.81M
        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
273
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
273
            break;
373
273
        }
374
7.81M
#endif
375
15.6M
        SPLIT_APPEND(str, j, eol);
376
7.81M
        j = i;
377
7.81M
    }
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.20k
{
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.20k
    Py_ssize_t i;
343
8.20k
    Py_ssize_t j;
344
8.20k
    PyObject *list = PyList_New(0);
345
8.20k
    PyObject *sub;
346
347
8.20k
    if (list == NULL)
348
0
        return NULL;
349
350
12.4M
    for (i = j = 0; i < str_len; ) {
351
12.4M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
52.6M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
40.1M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
12.4M
        eol = i;
359
12.4M
        if (i < str_len) {
360
12.4M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
7.53k
                i += 2;
362
12.4M
            else
363
12.4M
                i++;
364
12.4M
            if (keepends)
365
0
                eol = i;
366
12.4M
        }
367
12.4M
#if !STRINGLIB_MUTABLE
368
12.4M
        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.79k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
3.79k
            break;
373
3.79k
        }
374
12.4M
#endif
375
24.9M
        SPLIT_APPEND(str, j, eol);
376
12.4M
        j = i;
377
12.4M
    }
378
8.20k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
8.20k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
333
3.23k
{
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.23k
    Py_ssize_t i;
343
3.23k
    Py_ssize_t j;
344
3.23k
    PyObject *list = PyList_New(0);
345
3.23k
    PyObject *sub;
346
347
3.23k
    if (list == NULL)
348
0
        return NULL;
349
350
15.5M
    for (i = j = 0; i < str_len; ) {
351
15.5M
        Py_ssize_t eol;
352
353
        /* Find a line and append it */
354
61.9M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
355
46.4M
            i++;
356
357
        /* Skip the line break reading CRLF as one line break */
358
15.5M
        eol = i;
359
15.5M
        if (i < str_len) {
360
15.5M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
361
7.24k
                i += 2;
362
15.5M
            else
363
15.5M
                i++;
364
15.5M
            if (keepends)
365
0
                eol = i;
366
15.5M
        }
367
15.5M
#if !STRINGLIB_MUTABLE
368
15.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.54k
            if (PyList_Append(list, str_obj))
371
0
                goto onError;
372
1.54k
            break;
373
1.54k
        }
374
15.5M
#endif
375
31.0M
        SPLIT_APPEND(str, j, eol);
376
15.5M
        j = i;
377
15.5M
    }
378
3.23k
    return list;
379
380
0
  onError:
381
0
    Py_DECREF(list);
382
    return NULL;
383
3.23k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
384