Coverage Report

Created: 2026-07-14 06:16

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
115M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
23.3M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
34.7M
    sub = STRINGLIB_NEW((data) + (left),        \
22
34.7M
                        (right) - (left));      \
23
34.7M
    if (sub == NULL)                            \
24
34.7M
        goto onError;                           \
25
34.7M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
34.7M
    else                                        \
30
34.7M
        Py_DECREF(sub);
31
32
65.4M
#define SPLIT_ADD(data, left, right) {          \
33
65.4M
    sub = STRINGLIB_NEW((data) + (left),        \
34
65.4M
                        (right) - (left));      \
35
65.4M
    if (sub == NULL)                            \
36
65.4M
        goto onError;                           \
37
65.4M
    if (count < MAX_PREALLOC) {                 \
38
37.0M
        PyList_SET_ITEM(list, count, sub);      \
39
37.0M
    } else {                                    \
40
28.4M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
28.4M
        else                                    \
45
28.4M
            Py_DECREF(sub);                     \
46
28.4M
    }                                           \
47
65.4M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
23.3M
#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
201k
{
58
201k
    Py_ssize_t i, j, count=0;
59
201k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
201k
    PyObject *sub;
61
62
201k
    if (list == NULL)
63
0
        return NULL;
64
65
201k
    i = j = 0;
66
2.23M
    while (maxcount-- > 0) {
67
4.26M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
2.05M
            i++;
69
2.21M
        if (i == str_len) break;
70
2.08M
        j = i; i++;
71
183M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
181M
            i++;
73
#if !STRINGLIB_MUTABLE
74
2.08M
        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
52.6k
            Py_INCREF(str_obj);
77
52.6k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
52.6k
            count++;
79
52.6k
            break;
80
52.6k
        }
81
2.03M
#endif
82
6.10M
        SPLIT_ADD(str, j, i);
83
6.10M
    }
84
85
201k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
49.4k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
26.8k
            i++;
90
22.6k
        if (i != str_len)
91
22.6k
            SPLIT_ADD(str, i, str_len);
92
22.6k
    }
93
201k
    FIX_PREALLOC_SIZE(list);
94
201k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
201k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
91.6k
{
58
91.6k
    Py_ssize_t i, j, count=0;
59
91.6k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
91.6k
    PyObject *sub;
61
62
91.6k
    if (list == NULL)
63
0
        return NULL;
64
65
91.6k
    i = j = 0;
66
625k
    while (maxcount-- > 0) {
67
1.10M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
496k
            i++;
69
609k
        if (i == str_len) break;
70
562k
        j = i; i++;
71
56.9M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
56.4M
            i++;
73
562k
#if !STRINGLIB_MUTABLE
74
562k
        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
29.3k
            Py_INCREF(str_obj);
77
29.3k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
29.3k
            count++;
79
29.3k
            break;
80
29.3k
        }
81
533k
#endif
82
1.60M
        SPLIT_ADD(str, j, i);
83
1.60M
    }
84
85
91.6k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
26.2k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
13.6k
            i++;
90
12.5k
        if (i != str_len)
91
12.5k
            SPLIT_ADD(str, i, str_len);
92
12.5k
    }
93
91.6k
    FIX_PREALLOC_SIZE(list);
94
91.6k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
91.6k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
57
29.9k
{
58
29.9k
    Py_ssize_t i, j, count=0;
59
29.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
29.9k
    PyObject *sub;
61
62
29.9k
    if (list == NULL)
63
0
        return NULL;
64
65
29.9k
    i = j = 0;
66
833k
    while (maxcount-- > 0) {
67
1.60M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
785k
            i++;
69
823k
        if (i == str_len) break;
70
805k
        j = i; i++;
71
66.4M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
65.6M
            i++;
73
805k
#if !STRINGLIB_MUTABLE
74
805k
        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.65k
            Py_INCREF(str_obj);
77
2.65k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.65k
            count++;
79
2.65k
            break;
80
2.65k
        }
81
803k
#endif
82
2.40M
        SPLIT_ADD(str, j, i);
83
2.40M
    }
84
85
29.9k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
21.6k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
12.3k
            i++;
90
9.27k
        if (i != str_len)
91
9.27k
            SPLIT_ADD(str, i, str_len);
92
9.27k
    }
93
29.9k
    FIX_PREALLOC_SIZE(list);
94
29.9k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
29.9k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
69.8k
{
58
69.8k
    Py_ssize_t i, j, count=0;
59
69.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
69.8k
    PyObject *sub;
61
62
69.8k
    if (list == NULL)
63
0
        return NULL;
64
65
69.8k
    i = j = 0;
66
712k
    while (maxcount-- > 0) {
67
1.42M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
718k
            i++;
69
711k
        if (i == str_len) break;
70
660k
        j = i; i++;
71
49.2M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
48.5M
            i++;
73
660k
#if !STRINGLIB_MUTABLE
74
660k
        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
17.3k
            Py_INCREF(str_obj);
77
17.3k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
17.3k
            count++;
79
17.3k
            break;
80
17.3k
        }
81
642k
#endif
82
1.92M
        SPLIT_ADD(str, j, i);
83
1.92M
    }
84
85
69.8k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
1.61k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
807
            i++;
90
807
        if (i != str_len)
91
807
            SPLIT_ADD(str, i, str_len);
92
807
    }
93
69.8k
    FIX_PREALLOC_SIZE(list);
94
69.8k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
69.8k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
10.0k
{
58
10.0k
    Py_ssize_t i, j, count=0;
59
10.0k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
10.0k
    PyObject *sub;
61
62
10.0k
    if (list == NULL)
63
0
        return NULL;
64
65
10.0k
    i = j = 0;
66
65.7k
    while (maxcount-- > 0) {
67
120k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
55.2k
            i++;
69
65.4k
        if (i == str_len) break;
70
59.0k
        j = i; i++;
71
10.8M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
10.8M
            i++;
73
59.0k
#if !STRINGLIB_MUTABLE
74
59.0k
        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.37k
            Py_INCREF(str_obj);
77
3.37k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.37k
            count++;
79
3.37k
            break;
80
3.37k
        }
81
55.7k
#endif
82
167k
        SPLIT_ADD(str, j, i);
83
167k
    }
84
85
10.0k
    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.0k
    FIX_PREALLOC_SIZE(list);
94
10.0k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
10.0k
}
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
22.9M
{
107
22.9M
    Py_ssize_t i, j, count=0;
108
22.9M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
22.9M
    PyObject *sub;
110
111
22.9M
    if (list == NULL)
112
0
        return NULL;
113
114
22.9M
    i = j = 0;
115
89.4M
    while ((j < str_len) && (maxcount-- > 0)) {
116
521M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
501M
            if (str[j] == ch) {
119
45.6M
                SPLIT_ADD(str, i, j);
120
45.6M
                i = j = j + 1;
121
45.6M
                break;
122
45.6M
            }
123
501M
        }
124
66.5M
    }
125
#if !STRINGLIB_MUTABLE
126
22.9M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
5.56M
        Py_INCREF(str_obj);
129
5.56M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
5.56M
        count++;
131
5.56M
    } else
132
17.3M
#endif
133
17.3M
    if (i <= str_len) {
134
34.7M
        SPLIT_ADD(str, i, str_len);
135
34.7M
    }
136
22.9M
    FIX_PREALLOC_SIZE(list);
137
22.9M
    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
3.04M
{
107
3.04M
    Py_ssize_t i, j, count=0;
108
3.04M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
3.04M
    PyObject *sub;
110
111
3.04M
    if (list == NULL)
112
0
        return NULL;
113
114
3.04M
    i = j = 0;
115
13.2M
    while ((j < str_len) && (maxcount-- > 0)) {
116
94.7M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
92.1M
            if (str[j] == ch) {
119
7.59M
                SPLIT_ADD(str, i, j);
120
7.59M
                i = j = j + 1;
121
7.59M
                break;
122
7.59M
            }
123
92.1M
        }
124
10.2M
    }
125
3.04M
#if !STRINGLIB_MUTABLE
126
3.04M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.51M
        Py_INCREF(str_obj);
129
2.51M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.51M
        count++;
131
2.51M
    } else
132
524k
#endif
133
524k
    if (i <= str_len) {
134
1.04M
        SPLIT_ADD(str, i, str_len);
135
1.04M
    }
136
3.04M
    FIX_PREALLOC_SIZE(list);
137
3.04M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
3.04M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
18.5M
{
107
18.5M
    Py_ssize_t i, j, count=0;
108
18.5M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
18.5M
    PyObject *sub;
110
111
18.5M
    if (list == NULL)
112
0
        return NULL;
113
114
18.5M
    i = j = 0;
115
57.8M
    while ((j < str_len) && (maxcount-- > 0)) {
116
256M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
238M
            if (str[j] == ch) {
119
21.3M
                SPLIT_ADD(str, i, j);
120
21.3M
                i = j = j + 1;
121
21.3M
                break;
122
21.3M
            }
123
238M
        }
124
39.2M
    }
125
18.5M
#if !STRINGLIB_MUTABLE
126
18.5M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.84M
        Py_INCREF(str_obj);
129
2.84M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.84M
        count++;
131
2.84M
    } else
132
15.7M
#endif
133
15.7M
    if (i <= str_len) {
134
31.4M
        SPLIT_ADD(str, i, str_len);
135
31.4M
    }
136
18.5M
    FIX_PREALLOC_SIZE(list);
137
18.5M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
18.5M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.14M
{
107
1.14M
    Py_ssize_t i, j, count=0;
108
1.14M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.14M
    PyObject *sub;
110
111
1.14M
    if (list == NULL)
112
0
        return NULL;
113
114
1.14M
    i = j = 0;
115
12.3M
    while ((j < str_len) && (maxcount-- > 0)) {
116
89.6M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
89.4M
            if (str[j] == ch) {
119
10.9M
                SPLIT_ADD(str, i, j);
120
10.9M
                i = j = j + 1;
121
10.9M
                break;
122
10.9M
            }
123
89.4M
        }
124
11.1M
    }
125
1.14M
#if !STRINGLIB_MUTABLE
126
1.14M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
173k
        Py_INCREF(str_obj);
129
173k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
173k
        count++;
131
173k
    } else
132
973k
#endif
133
973k
    if (i <= str_len) {
134
1.94M
        SPLIT_ADD(str, i, str_len);
135
1.94M
    }
136
1.14M
    FIX_PREALLOC_SIZE(list);
137
1.14M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.14M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
131k
{
107
131k
    Py_ssize_t i, j, count=0;
108
131k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
131k
    PyObject *sub;
110
111
131k
    if (list == NULL)
112
0
        return NULL;
113
114
131k
    i = j = 0;
115
5.73M
    while ((j < str_len) && (maxcount-- > 0)) {
116
57.9M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
57.8M
            if (str[j] == ch) {
119
5.50M
                SPLIT_ADD(str, i, j);
120
5.50M
                i = j = j + 1;
121
5.50M
                break;
122
5.50M
            }
123
57.8M
        }
124
5.60M
    }
125
131k
#if !STRINGLIB_MUTABLE
126
131k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
28.1k
        Py_INCREF(str_obj);
129
28.1k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
28.1k
        count++;
131
28.1k
    } else
132
102k
#endif
133
102k
    if (i <= str_len) {
134
205k
        SPLIT_ADD(str, i, str_len);
135
205k
    }
136
131k
    FIX_PREALLOC_SIZE(list);
137
131k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
131k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
14.3k
{
107
14.3k
    Py_ssize_t i, j, count=0;
108
14.3k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
14.3k
    PyObject *sub;
110
111
14.3k
    if (list == NULL)
112
0
        return NULL;
113
114
14.3k
    i = j = 0;
115
279k
    while ((j < str_len) && (maxcount-- > 0)) {
116
23.5M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
23.4M
            if (str[j] == ch) {
119
253k
                SPLIT_ADD(str, i, j);
120
253k
                i = j = j + 1;
121
253k
                break;
122
253k
            }
123
23.4M
        }
124
264k
    }
125
14.3k
#if !STRINGLIB_MUTABLE
126
14.3k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
858
        Py_INCREF(str_obj);
129
858
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
858
        count++;
131
858
    } else
132
13.4k
#endif
133
13.4k
    if (i <= str_len) {
134
26.9k
        SPLIT_ADD(str, i, str_len);
135
26.9k
    }
136
14.3k
    FIX_PREALLOC_SIZE(list);
137
14.3k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
14.3k
}
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.1M
{
150
23.1M
    Py_ssize_t i, j, pos, count=0;
151
23.1M
    PyObject *list, *sub;
152
153
23.1M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
23.1M
    else if (sep_len == 1)
158
22.9M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
258k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
258k
    if (list == NULL)
162
0
        return NULL;
163
164
258k
    i = j = 0;
165
459k
    while (maxcount-- > 0) {
166
258k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
258k
        if (pos < 0)
168
57.2k
            break;
169
201k
        j = i + pos;
170
402k
        SPLIT_ADD(str, i, j);
171
402k
        i = j + sep_len;
172
402k
    }
173
#if !STRINGLIB_MUTABLE
174
258k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
57.2k
        Py_INCREF(str_obj);
177
57.2k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
57.2k
        count++;
179
57.2k
    } else
180
201k
#endif
181
201k
    {
182
402k
        SPLIT_ADD(str, i, str_len);
183
402k
    }
184
258k
    FIX_PREALLOC_SIZE(list);
185
258k
    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
3.04M
{
150
3.04M
    Py_ssize_t i, j, pos, count=0;
151
3.04M
    PyObject *list, *sub;
152
153
3.04M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
3.04M
    else if (sep_len == 1)
158
3.04M
        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
18.6M
{
150
18.6M
    Py_ssize_t i, j, pos, count=0;
151
18.6M
    PyObject *list, *sub;
152
153
18.6M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
18.6M
    else if (sep_len == 1)
158
18.5M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
101k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
101k
    if (list == NULL)
162
0
        return NULL;
163
164
101k
    i = j = 0;
165
163k
    while (maxcount-- > 0) {
166
101k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
101k
        if (pos < 0)
168
40.2k
            break;
169
61.6k
        j = i + pos;
170
123k
        SPLIT_ADD(str, i, j);
171
123k
        i = j + sep_len;
172
123k
    }
173
101k
#if !STRINGLIB_MUTABLE
174
101k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
40.2k
        Py_INCREF(str_obj);
177
40.2k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
40.2k
        count++;
179
40.2k
    } else
180
61.6k
#endif
181
61.6k
    {
182
123k
        SPLIT_ADD(str, i, str_len);
183
123k
    }
184
101k
    FIX_PREALLOC_SIZE(list);
185
101k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
101k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.17M
{
150
1.17M
    Py_ssize_t i, j, pos, count=0;
151
1.17M
    PyObject *list, *sub;
152
153
1.17M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.17M
    else if (sep_len == 1)
158
1.14M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
27.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
27.2k
    if (list == NULL)
162
0
        return NULL;
163
164
27.2k
    i = j = 0;
165
51.2k
    while (maxcount-- > 0) {
166
27.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
27.2k
        if (pos < 0)
168
3.25k
            break;
169
23.9k
        j = i + pos;
170
47.9k
        SPLIT_ADD(str, i, j);
171
47.9k
        i = j + sep_len;
172
47.9k
    }
173
27.2k
#if !STRINGLIB_MUTABLE
174
27.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
3.25k
        Py_INCREF(str_obj);
177
3.25k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
3.25k
        count++;
179
3.25k
    } else
180
23.9k
#endif
181
23.9k
    {
182
47.9k
        SPLIT_ADD(str, i, str_len);
183
47.9k
    }
184
27.2k
    FIX_PREALLOC_SIZE(list);
185
27.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
27.2k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
238k
{
150
238k
    Py_ssize_t i, j, pos, count=0;
151
238k
    PyObject *list, *sub;
152
153
238k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
238k
    else if (sep_len == 1)
158
131k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
107k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
107k
    if (list == NULL)
162
0
        return NULL;
163
164
107k
    i = j = 0;
165
205k
    while (maxcount-- > 0) {
166
107k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
107k
        if (pos < 0)
168
9.28k
            break;
169
98.2k
        j = i + pos;
170
196k
        SPLIT_ADD(str, i, j);
171
196k
        i = j + sep_len;
172
196k
    }
173
107k
#if !STRINGLIB_MUTABLE
174
107k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
9.28k
        Py_INCREF(str_obj);
177
9.28k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
9.28k
        count++;
179
9.28k
    } else
180
98.2k
#endif
181
98.2k
    {
182
196k
        SPLIT_ADD(str, i, str_len);
183
196k
    }
184
107k
    FIX_PREALLOC_SIZE(list);
185
107k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
107k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
35.8k
{
150
35.8k
    Py_ssize_t i, j, pos, count=0;
151
35.8k
    PyObject *list, *sub;
152
153
35.8k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
35.8k
    else if (sep_len == 1)
158
14.3k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
21.5k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
21.5k
    if (list == NULL)
162
0
        return NULL;
163
164
21.5k
    i = j = 0;
165
38.5k
    while (maxcount-- > 0) {
166
21.5k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
21.5k
        if (pos < 0)
168
4.47k
            break;
169
17.0k
        j = i + pos;
170
34.1k
        SPLIT_ADD(str, i, j);
171
34.1k
        i = j + sep_len;
172
34.1k
    }
173
21.5k
#if !STRINGLIB_MUTABLE
174
21.5k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
4.47k
        Py_INCREF(str_obj);
177
4.47k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
4.47k
        count++;
179
4.47k
    } else
180
17.0k
#endif
181
17.0k
    {
182
34.1k
        SPLIT_ADD(str, i, str_len);
183
34.1k
    }
184
21.5k
    FIX_PREALLOC_SIZE(list);
185
21.5k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
21.5k
}
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.5k
{
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.5k
    Py_ssize_t i;
349
17.5k
    Py_ssize_t j;
350
17.5k
    PyObject *list = PyList_New(0);
351
17.5k
    PyObject *sub;
352
353
17.5k
    if (list == NULL)
354
0
        return NULL;
355
356
34.7M
    for (i = j = 0; i < str_len; ) {
357
34.7M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
134M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
100M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
34.7M
        eol = i;
365
34.7M
        if (i < str_len) {
366
34.7M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
37.0k
                i += 2;
368
34.7M
            else
369
34.7M
                i++;
370
34.7M
            if (keepends)
371
0
                eol = i;
372
34.7M
        }
373
#if !STRINGLIB_MUTABLE
374
34.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
7.22k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
7.22k
            break;
379
7.22k
        }
380
34.7M
#endif
381
69.5M
        SPLIT_APPEND(str, j, eol);
382
34.7M
        j = i;
383
34.7M
    }
384
17.5k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
17.5k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
4.20k
{
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
4.20k
    Py_ssize_t i;
349
4.20k
    Py_ssize_t j;
350
4.20k
    PyObject *list = PyList_New(0);
351
4.20k
    PyObject *sub;
352
353
4.20k
    if (list == NULL)
354
0
        return NULL;
355
356
5.44M
    for (i = j = 0; i < str_len; ) {
357
5.43M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
12.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
6.60M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
5.43M
        eol = i;
365
5.43M
        if (i < str_len) {
366
5.43M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
422
                i += 2;
368
5.43M
            else
369
5.43M
                i++;
370
5.43M
            if (keepends)
371
0
                eol = i;
372
5.43M
        }
373
5.43M
#if !STRINGLIB_MUTABLE
374
5.43M
        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.17k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.17k
            break;
379
1.17k
        }
380
5.43M
#endif
381
10.8M
        SPLIT_APPEND(str, j, eol);
382
5.43M
        j = i;
383
5.43M
    }
384
4.20k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
4.20k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
1.03k
{
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
1.03k
    Py_ssize_t i;
349
1.03k
    Py_ssize_t j;
350
1.03k
    PyObject *list = PyList_New(0);
351
1.03k
    PyObject *sub;
352
353
1.03k
    if (list == NULL)
354
0
        return NULL;
355
356
3.37M
    for (i = j = 0; i < str_len; ) {
357
3.37M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
12.2M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
8.88M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
3.37M
        eol = i;
365
3.37M
        if (i < str_len) {
366
3.37M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
560
                i += 2;
368
3.36M
            else
369
3.36M
                i++;
370
3.37M
            if (keepends)
371
0
                eol = i;
372
3.37M
        }
373
3.37M
#if !STRINGLIB_MUTABLE
374
3.37M
        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
290
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
290
            break;
379
290
        }
380
3.37M
#endif
381
6.74M
        SPLIT_APPEND(str, j, eol);
382
3.37M
        j = i;
383
3.37M
    }
384
1.03k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
1.03k
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
8.85k
{
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.85k
    Py_ssize_t i;
349
8.85k
    Py_ssize_t j;
350
8.85k
    PyObject *list = PyList_New(0);
351
8.85k
    PyObject *sub;
352
353
8.85k
    if (list == NULL)
354
0
        return NULL;
355
356
10.4M
    for (i = j = 0; i < str_len; ) {
357
10.4M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
50.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
39.6M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
10.4M
        eol = i;
365
10.4M
        if (i < str_len) {
366
10.4M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
10.0k
                i += 2;
368
10.4M
            else
369
10.4M
                i++;
370
10.4M
            if (keepends)
371
0
                eol = i;
372
10.4M
        }
373
10.4M
#if !STRINGLIB_MUTABLE
374
10.4M
        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.10k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
4.10k
            break;
379
4.10k
        }
380
10.4M
#endif
381
20.8M
        SPLIT_APPEND(str, j, eol);
382
10.4M
        j = i;
383
10.4M
    }
384
8.85k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
8.85k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
3.50k
{
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.50k
    Py_ssize_t i;
349
3.50k
    Py_ssize_t j;
350
3.50k
    PyObject *list = PyList_New(0);
351
3.50k
    PyObject *sub;
352
353
3.50k
    if (list == NULL)
354
0
        return NULL;
355
356
15.5M
    for (i = j = 0; i < str_len; ) {
357
15.5M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
60.5M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
44.9M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
15.5M
        eol = i;
365
15.5M
        if (i < str_len) {
366
15.5M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
26.0k
                i += 2;
368
15.5M
            else
369
15.5M
                i++;
370
15.5M
            if (keepends)
371
0
                eol = i;
372
15.5M
        }
373
15.5M
#if !STRINGLIB_MUTABLE
374
15.5M
        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.65k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.65k
            break;
379
1.65k
        }
380
15.5M
#endif
381
31.0M
        SPLIT_APPEND(str, j, eol);
382
15.5M
        j = i;
383
15.5M
    }
384
3.50k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
3.50k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390