Coverage Report

Created: 2026-03-23 06:45

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
109M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
22.1M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
24.6M
    sub = STRINGLIB_NEW((data) + (left),        \
22
24.6M
                        (right) - (left));      \
23
24.6M
    if (sub == NULL)                            \
24
24.6M
        goto onError;                           \
25
24.6M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
24.6M
    else                                        \
30
24.6M
        Py_DECREF(sub);
31
32
62.5M
#define SPLIT_ADD(data, left, right) {          \
33
62.5M
    sub = STRINGLIB_NEW((data) + (left),        \
34
62.5M
                        (right) - (left));      \
35
62.5M
    if (sub == NULL)                            \
36
62.5M
        goto onError;                           \
37
62.5M
    if (count < MAX_PREALLOC) {                 \
38
34.8M
        PyList_SET_ITEM(list, count, sub);      \
39
34.8M
    } else {                                    \
40
27.7M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
27.7M
        else                                    \
45
27.7M
            Py_DECREF(sub);                     \
46
27.7M
    }                                           \
47
62.5M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
22.1M
#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
173k
{
58
173k
    Py_ssize_t i, j, count=0;
59
173k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
173k
    PyObject *sub;
61
62
173k
    if (list == NULL)
63
0
        return NULL;
64
65
173k
    i = j = 0;
66
2.36M
    while (maxcount-- > 0) {
67
4.57M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
2.23M
            i++;
69
2.33M
        if (i == str_len) break;
70
2.24M
        j = i; i++;
71
153M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
151M
            i++;
73
#if !STRINGLIB_MUTABLE
74
2.24M
        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
46.7k
            Py_INCREF(str_obj);
77
46.7k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
46.7k
            count++;
79
46.7k
            break;
80
46.7k
        }
81
2.19M
#endif
82
6.58M
        SPLIT_ADD(str, j, i);
83
6.58M
    }
84
85
173k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
58.2k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
31.7k
            i++;
90
26.5k
        if (i != str_len)
91
26.5k
            SPLIT_ADD(str, i, str_len);
92
26.5k
    }
93
173k
    FIX_PREALLOC_SIZE(list);
94
173k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
173k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
82.5k
{
58
82.5k
    Py_ssize_t i, j, count=0;
59
82.5k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
82.5k
    PyObject *sub;
61
62
82.5k
    if (list == NULL)
63
0
        return NULL;
64
65
82.5k
    i = j = 0;
66
756k
    while (maxcount-- > 0) {
67
1.38M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
641k
            i++;
69
740k
        if (i == str_len) break;
70
700k
        j = i; i++;
71
59.0M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
58.3M
            i++;
73
700k
#if !STRINGLIB_MUTABLE
74
700k
        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
26.7k
            Py_INCREF(str_obj);
77
26.7k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
26.7k
            count++;
79
26.7k
            break;
80
26.7k
        }
81
674k
#endif
82
2.02M
        SPLIT_ADD(str, j, i);
83
2.02M
    }
84
85
82.5k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
29.0k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
15.0k
            i++;
90
14.0k
        if (i != str_len)
91
14.0k
            SPLIT_ADD(str, i, str_len);
92
14.0k
    }
93
82.5k
    FIX_PREALLOC_SIZE(list);
94
82.5k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
82.5k
}
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
1.01M
    while (maxcount-- > 0) {
67
1.97M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
971k
            i++;
69
1.00M
        if (i == str_len) break;
70
992k
        j = i; i++;
71
56.2M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
55.2M
            i++;
73
992k
#if !STRINGLIB_MUTABLE
74
992k
        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.62k
            Py_INCREF(str_obj);
77
2.62k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.62k
            count++;
79
2.62k
            break;
80
2.62k
        }
81
989k
#endif
82
2.96M
        SPLIT_ADD(str, j, i);
83
2.96M
    }
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
27.7k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
15.9k
            i++;
90
11.8k
        if (i != str_len)
91
11.8k
            SPLIT_ADD(str, i, str_len);
92
11.8k
    }
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
49.2k
{
58
49.2k
    Py_ssize_t i, j, count=0;
59
49.2k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
49.2k
    PyObject *sub;
61
62
49.2k
    if (list == NULL)
63
0
        return NULL;
64
65
49.2k
    i = j = 0;
66
519k
    while (maxcount-- > 0) {
67
1.08M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
562k
            i++;
69
518k
        if (i == str_len) break;
70
483k
        j = i; i++;
71
27.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
27.0M
            i++;
73
483k
#if !STRINGLIB_MUTABLE
74
483k
        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
13.2k
            Py_INCREF(str_obj);
77
13.2k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
13.2k
            count++;
79
13.2k
            break;
80
13.2k
        }
81
470k
#endif
82
1.41M
        SPLIT_ADD(str, j, i);
83
1.41M
    }
84
85
49.2k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
1.41k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
708
            i++;
90
708
        if (i != str_len)
91
708
            SPLIT_ADD(str, i, str_len);
92
708
    }
93
49.2k
    FIX_PREALLOC_SIZE(list);
94
49.2k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
49.2k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
11.8k
{
58
11.8k
    Py_ssize_t i, j, count=0;
59
11.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
11.8k
    PyObject *sub;
61
62
11.8k
    if (list == NULL)
63
0
        return NULL;
64
65
11.8k
    i = j = 0;
66
71.4k
    while (maxcount-- > 0) {
67
130k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
59.4k
            i++;
69
71.1k
        if (i == str_len) break;
70
63.7k
        j = i; i++;
71
10.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
10.4M
            i++;
73
63.7k
#if !STRINGLIB_MUTABLE
74
63.7k
        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
4.11k
            Py_INCREF(str_obj);
77
4.11k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
4.11k
            count++;
79
4.11k
            break;
80
4.11k
        }
81
59.6k
#endif
82
178k
        SPLIT_ADD(str, j, i);
83
178k
    }
84
85
11.8k
    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
11.8k
    FIX_PREALLOC_SIZE(list);
94
11.8k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
11.8k
}
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
21.7M
{
107
21.7M
    Py_ssize_t i, j, count=0;
108
21.7M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
21.7M
    PyObject *sub;
110
111
21.7M
    if (list == NULL)
112
0
        return NULL;
113
114
21.7M
    i = j = 0;
115
85.0M
    while ((j < str_len) && (maxcount-- > 0)) {
116
443M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
423M
            if (str[j] == ch) {
119
43.6M
                SPLIT_ADD(str, i, j);
120
43.6M
                i = j = j + 1;
121
43.6M
                break;
122
43.6M
            }
123
423M
        }
124
63.3M
    }
125
#if !STRINGLIB_MUTABLE
126
21.7M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
5.33M
        Py_INCREF(str_obj);
129
5.33M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
5.33M
        count++;
131
5.33M
    } else
132
16.3M
#endif
133
16.3M
    if (i <= str_len) {
134
32.7M
        SPLIT_ADD(str, i, str_len);
135
32.7M
    }
136
21.7M
    FIX_PREALLOC_SIZE(list);
137
21.7M
    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.70M
{
107
2.70M
    Py_ssize_t i, j, count=0;
108
2.70M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
2.70M
    PyObject *sub;
110
111
2.70M
    if (list == NULL)
112
0
        return NULL;
113
114
2.70M
    i = j = 0;
115
8.63M
    while ((j < str_len) && (maxcount-- > 0)) {
116
59.7M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
57.3M
            if (str[j] == ch) {
119
3.60M
                SPLIT_ADD(str, i, j);
120
3.60M
                i = j = j + 1;
121
3.60M
                break;
122
3.60M
            }
123
57.3M
        }
124
5.92M
    }
125
2.70M
#if !STRINGLIB_MUTABLE
126
2.70M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.23M
        Py_INCREF(str_obj);
129
2.23M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.23M
        count++;
131
2.23M
    } else
132
471k
#endif
133
471k
    if (i <= str_len) {
134
943k
        SPLIT_ADD(str, i, str_len);
135
943k
    }
136
2.70M
    FIX_PREALLOC_SIZE(list);
137
2.70M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
2.70M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
17.7M
{
107
17.7M
    Py_ssize_t i, j, count=0;
108
17.7M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
17.7M
    PyObject *sub;
110
111
17.7M
    if (list == NULL)
112
0
        return NULL;
113
114
17.7M
    i = j = 0;
115
57.4M
    while ((j < str_len) && (maxcount-- > 0)) {
116
246M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
229M
            if (str[j] == ch) {
119
22.5M
                SPLIT_ADD(str, i, j);
120
22.5M
                i = j = j + 1;
121
22.5M
                break;
122
22.5M
            }
123
229M
        }
124
39.6M
    }
125
17.7M
#if !STRINGLIB_MUTABLE
126
17.7M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.90M
        Py_INCREF(str_obj);
129
2.90M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.90M
        count++;
131
2.90M
    } else
132
14.8M
#endif
133
14.8M
    if (i <= str_len) {
134
29.7M
        SPLIT_ADD(str, i, str_len);
135
29.7M
    }
136
17.7M
    FIX_PREALLOC_SIZE(list);
137
17.7M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
17.7M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.10M
{
107
1.10M
    Py_ssize_t i, j, count=0;
108
1.10M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.10M
    PyObject *sub;
110
111
1.10M
    if (list == NULL)
112
0
        return NULL;
113
114
1.10M
    i = j = 0;
115
14.6M
    while ((j < str_len) && (maxcount-- > 0)) {
116
79.0M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
78.8M
            if (str[j] == ch) {
119
13.3M
                SPLIT_ADD(str, i, j);
120
13.3M
                i = j = j + 1;
121
13.3M
                break;
122
13.3M
            }
123
78.8M
        }
124
13.5M
    }
125
1.10M
#if !STRINGLIB_MUTABLE
126
1.10M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
168k
        Py_INCREF(str_obj);
129
168k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
168k
        count++;
131
168k
    } else
132
932k
#endif
133
932k
    if (i <= str_len) {
134
1.86M
        SPLIT_ADD(str, i, str_len);
135
1.86M
    }
136
1.10M
    FIX_PREALLOC_SIZE(list);
137
1.10M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.10M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
114k
{
107
114k
    Py_ssize_t i, j, count=0;
108
114k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
114k
    PyObject *sub;
110
111
114k
    if (list == NULL)
112
0
        return NULL;
113
114
114k
    i = j = 0;
115
4.04M
    while ((j < str_len) && (maxcount-- > 0)) {
116
35.2M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
35.1M
            if (str[j] == ch) {
119
3.84M
                SPLIT_ADD(str, i, j);
120
3.84M
                i = j = j + 1;
121
3.84M
                break;
122
3.84M
            }
123
35.1M
        }
124
3.92M
    }
125
114k
#if !STRINGLIB_MUTABLE
126
114k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
34.3k
        Py_INCREF(str_obj);
129
34.3k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
34.3k
        count++;
131
34.3k
    } else
132
80.1k
#endif
133
80.1k
    if (i <= str_len) {
134
160k
        SPLIT_ADD(str, i, str_len);
135
160k
    }
136
114k
    FIX_PREALLOC_SIZE(list);
137
114k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
114k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
15.8k
{
107
15.8k
    Py_ssize_t i, j, count=0;
108
15.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
15.8k
    PyObject *sub;
110
111
15.8k
    if (list == NULL)
112
0
        return NULL;
113
114
15.8k
    i = j = 0;
115
256k
    while ((j < str_len) && (maxcount-- > 0)) {
116
22.5M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
22.5M
            if (str[j] == ch) {
119
227k
                SPLIT_ADD(str, i, j);
120
227k
                i = j = j + 1;
121
227k
                break;
122
227k
            }
123
22.5M
        }
124
240k
    }
125
15.8k
#if !STRINGLIB_MUTABLE
126
15.8k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
885
        Py_INCREF(str_obj);
129
885
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
885
        count++;
131
885
    } else
132
14.9k
#endif
133
14.9k
    if (i <= str_len) {
134
29.8k
        SPLIT_ADD(str, i, str_len);
135
29.8k
    }
136
15.8k
    FIX_PREALLOC_SIZE(list);
137
15.8k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
15.8k
}
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
21.9M
{
150
21.9M
    Py_ssize_t i, j, pos, count=0;
151
21.9M
    PyObject *list, *sub;
152
153
21.9M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
21.9M
    else if (sep_len == 1)
158
21.7M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
211k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
211k
    if (list == NULL)
162
0
        return NULL;
163
164
211k
    i = j = 0;
165
375k
    while (maxcount-- > 0) {
166
211k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
211k
        if (pos < 0)
168
48.3k
            break;
169
163k
        j = i + pos;
170
326k
        SPLIT_ADD(str, i, j);
171
326k
        i = j + sep_len;
172
326k
    }
173
#if !STRINGLIB_MUTABLE
174
211k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
48.3k
        Py_INCREF(str_obj);
177
48.3k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
48.3k
        count++;
179
48.3k
    } else
180
163k
#endif
181
163k
    {
182
326k
        SPLIT_ADD(str, i, str_len);
183
326k
    }
184
211k
    FIX_PREALLOC_SIZE(list);
185
211k
    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.70M
{
150
2.70M
    Py_ssize_t i, j, pos, count=0;
151
2.70M
    PyObject *list, *sub;
152
153
2.70M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
2.70M
    else if (sep_len == 1)
158
2.70M
        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
17.8M
{
150
17.8M
    Py_ssize_t i, j, pos, count=0;
151
17.8M
    PyObject *list, *sub;
152
153
17.8M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
17.8M
    else if (sep_len == 1)
158
17.7M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
88.1k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
88.1k
    if (list == NULL)
162
0
        return NULL;
163
164
88.1k
    i = j = 0;
165
142k
    while (maxcount-- > 0) {
166
88.1k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
88.1k
        if (pos < 0)
168
34.0k
            break;
169
54.0k
        j = i + pos;
170
108k
        SPLIT_ADD(str, i, j);
171
108k
        i = j + sep_len;
172
108k
    }
173
88.1k
#if !STRINGLIB_MUTABLE
174
88.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
34.0k
        Py_INCREF(str_obj);
177
34.0k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
34.0k
        count++;
179
34.0k
    } else
180
54.0k
#endif
181
54.0k
    {
182
108k
        SPLIT_ADD(str, i, str_len);
183
108k
    }
184
88.1k
    FIX_PREALLOC_SIZE(list);
185
88.1k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
88.1k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.12M
{
150
1.12M
    Py_ssize_t i, j, pos, count=0;
151
1.12M
    PyObject *list, *sub;
152
153
1.12M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.12M
    else if (sep_len == 1)
158
1.10M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
22.1k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
22.1k
    if (list == NULL)
162
0
        return NULL;
163
164
22.1k
    i = j = 0;
165
42.2k
    while (maxcount-- > 0) {
166
22.1k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
22.1k
        if (pos < 0)
168
2.03k
            break;
169
20.1k
        j = i + pos;
170
40.2k
        SPLIT_ADD(str, i, j);
171
40.2k
        i = j + sep_len;
172
40.2k
    }
173
22.1k
#if !STRINGLIB_MUTABLE
174
22.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.03k
        Py_INCREF(str_obj);
177
2.03k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.03k
        count++;
179
2.03k
    } else
180
20.1k
#endif
181
20.1k
    {
182
40.2k
        SPLIT_ADD(str, i, str_len);
183
40.2k
    }
184
22.1k
    FIX_PREALLOC_SIZE(list);
185
22.1k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
22.1k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
195k
{
150
195k
    Py_ssize_t i, j, pos, count=0;
151
195k
    PyObject *list, *sub;
152
153
195k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
195k
    else if (sep_len == 1)
158
114k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
80.7k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
80.7k
    if (list == NULL)
162
0
        return NULL;
163
164
80.7k
    i = j = 0;
165
152k
    while (maxcount-- > 0) {
166
80.7k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
80.7k
        if (pos < 0)
168
9.28k
            break;
169
71.4k
        j = i + pos;
170
142k
        SPLIT_ADD(str, i, j);
171
142k
        i = j + sep_len;
172
142k
    }
173
80.7k
#if !STRINGLIB_MUTABLE
174
80.7k
    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
71.4k
#endif
181
71.4k
    {
182
142k
        SPLIT_ADD(str, i, str_len);
183
142k
    }
184
80.7k
    FIX_PREALLOC_SIZE(list);
185
80.7k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
80.7k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
36.5k
{
150
36.5k
    Py_ssize_t i, j, pos, count=0;
151
36.5k
    PyObject *list, *sub;
152
153
36.5k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
36.5k
    else if (sep_len == 1)
158
15.8k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
20.7k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
20.7k
    if (list == NULL)
162
0
        return NULL;
163
164
20.7k
    i = j = 0;
165
38.5k
    while (maxcount-- > 0) {
166
20.7k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
20.7k
        if (pos < 0)
168
2.98k
            break;
169
17.7k
        j = i + pos;
170
35.5k
        SPLIT_ADD(str, i, j);
171
35.5k
        i = j + sep_len;
172
35.5k
    }
173
20.7k
#if !STRINGLIB_MUTABLE
174
20.7k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.98k
        Py_INCREF(str_obj);
177
2.98k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.98k
        count++;
179
2.98k
    } else
180
17.7k
#endif
181
17.7k
    {
182
35.5k
        SPLIT_ADD(str, i, str_len);
183
35.5k
    }
184
20.7k
    FIX_PREALLOC_SIZE(list);
185
20.7k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
20.7k
}
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
78
{
248
78
    Py_ssize_t i, j, count=0;
249
78
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
78
    PyObject *sub;
251
252
78
    if (list == NULL)
253
0
        return NULL;
254
255
78
    i = j = str_len - 1;
256
156
    while ((i >= 0) && (maxcount-- > 0)) {
257
150
        for(; i >= 0; i--) {
258
150
            if (str[i] == ch) {
259
78
                SPLIT_ADD(str, i + 1, j + 1);
260
78
                j = i = i - 1;
261
78
                break;
262
78
            }
263
150
        }
264
78
    }
265
#if !STRINGLIB_MUTABLE
266
78
    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
78
#endif
273
78
    if (j >= -1) {
274
156
        SPLIT_ADD(str, 0, j + 1);
275
156
    }
276
78
    FIX_PREALLOC_SIZE(list);
277
78
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
78
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
0
    return NULL;
284
78
}
Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char
unicodeobject.c:asciilib_rsplit_char
Line
Count
Source
247
78
{
248
78
    Py_ssize_t i, j, count=0;
249
78
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
78
    PyObject *sub;
251
252
78
    if (list == NULL)
253
0
        return NULL;
254
255
78
    i = j = str_len - 1;
256
156
    while ((i >= 0) && (maxcount-- > 0)) {
257
150
        for(; i >= 0; i--) {
258
150
            if (str[i] == ch) {
259
78
                SPLIT_ADD(str, i + 1, j + 1);
260
78
                j = i = i - 1;
261
78
                break;
262
78
            }
263
150
        }
264
78
    }
265
78
#if !STRINGLIB_MUTABLE
266
78
    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
78
#endif
273
78
    if (j >= -1) {
274
156
        SPLIT_ADD(str, 0, j + 1);
275
156
    }
276
78
    FIX_PREALLOC_SIZE(list);
277
78
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
78
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
    return NULL;
284
78
}
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
78
{
292
78
    Py_ssize_t j, pos, count=0;
293
78
    PyObject *list, *sub;
294
295
78
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
78
    else if (sep_len == 1)
300
78
        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
78
{
292
78
    Py_ssize_t j, pos, count=0;
293
78
    PyObject *list, *sub;
294
295
78
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
78
    else if (sep_len == 1)
300
78
        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
14.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
14.3k
    Py_ssize_t i;
349
14.3k
    Py_ssize_t j;
350
14.3k
    PyObject *list = PyList_New(0);
351
14.3k
    PyObject *sub;
352
353
14.3k
    if (list == NULL)
354
0
        return NULL;
355
356
24.6M
    for (i = j = 0; i < str_len; ) {
357
24.6M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
115M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
90.9M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
24.6M
        eol = i;
365
24.6M
        if (i < str_len) {
366
24.6M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
39.6k
                i += 2;
368
24.6M
            else
369
24.6M
                i++;
370
24.6M
            if (keepends)
371
0
                eol = i;
372
24.6M
        }
373
#if !STRINGLIB_MUTABLE
374
24.6M
        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
5.88k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
5.88k
            break;
379
5.88k
        }
380
24.6M
#endif
381
49.3M
        SPLIT_APPEND(str, j, eol);
382
24.6M
        j = i;
383
24.6M
    }
384
14.3k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
14.3k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
2.88k
{
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
2.88k
    Py_ssize_t i;
349
2.88k
    Py_ssize_t j;
350
2.88k
    PyObject *list = PyList_New(0);
351
2.88k
    PyObject *sub;
352
353
2.88k
    if (list == NULL)
354
0
        return NULL;
355
356
5.97M
    for (i = j = 0; i < str_len; ) {
357
5.97M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
13.9M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
7.98M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
5.97M
        eol = i;
365
5.97M
        if (i < str_len) {
366
5.97M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
903
                i += 2;
368
5.97M
            else
369
5.97M
                i++;
370
5.97M
            if (keepends)
371
0
                eol = i;
372
5.97M
        }
373
5.97M
#if !STRINGLIB_MUTABLE
374
5.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
955
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
955
            break;
379
955
        }
380
5.97M
#endif
381
11.9M
        SPLIT_APPEND(str, j, eol);
382
5.97M
        j = i;
383
5.97M
    }
384
2.88k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.88k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
902
{
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
902
    Py_ssize_t i;
349
902
    Py_ssize_t j;
350
902
    PyObject *list = PyList_New(0);
351
902
    PyObject *sub;
352
353
902
    if (list == NULL)
354
0
        return NULL;
355
356
1.91M
    for (i = j = 0; i < str_len; ) {
357
1.91M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
8.05M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
6.14M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
1.91M
        eol = i;
365
1.91M
        if (i < str_len) {
366
1.91M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
1.09k
                i += 2;
368
1.91M
            else
369
1.91M
                i++;
370
1.91M
            if (keepends)
371
0
                eol = i;
372
1.91M
        }
373
1.91M
#if !STRINGLIB_MUTABLE
374
1.91M
        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
244
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
244
            break;
379
244
        }
380
1.91M
#endif
381
3.82M
        SPLIT_APPEND(str, j, eol);
382
1.91M
        j = i;
383
1.91M
    }
384
902
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
902
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
7.53k
{
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
7.53k
    Py_ssize_t i;
349
7.53k
    Py_ssize_t j;
350
7.53k
    PyObject *list = PyList_New(0);
351
7.53k
    PyObject *sub;
352
353
7.53k
    if (list == NULL)
354
0
        return NULL;
355
356
7.71M
    for (i = j = 0; i < str_len; ) {
357
7.71M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
40.3M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
32.6M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
7.71M
        eol = i;
365
7.71M
        if (i < str_len) {
366
7.70M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
11.1k
                i += 2;
368
7.69M
            else
369
7.69M
                i++;
370
7.70M
            if (keepends)
371
0
                eol = i;
372
7.70M
        }
373
7.71M
#if !STRINGLIB_MUTABLE
374
7.71M
        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
3.38k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
3.38k
            break;
379
3.38k
        }
380
7.70M
#endif
381
15.4M
        SPLIT_APPEND(str, j, eol);
382
7.70M
        j = i;
383
7.70M
    }
384
7.53k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
7.53k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
2.99k
{
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
2.99k
    Py_ssize_t i;
349
2.99k
    Py_ssize_t j;
350
2.99k
    PyObject *list = PyList_New(0);
351
2.99k
    PyObject *sub;
352
353
2.99k
    if (list == NULL)
354
0
        return NULL;
355
356
9.07M
    for (i = j = 0; i < str_len; ) {
357
9.07M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
53.3M
        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
9.07M
        eol = i;
365
9.07M
        if (i < str_len) {
366
9.07M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
26.4k
                i += 2;
368
9.04M
            else
369
9.04M
                i++;
370
9.07M
            if (keepends)
371
0
                eol = i;
372
9.07M
        }
373
9.07M
#if !STRINGLIB_MUTABLE
374
9.07M
        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.29k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.29k
            break;
379
1.29k
        }
380
9.07M
#endif
381
18.1M
        SPLIT_APPEND(str, j, eol);
382
9.07M
        j = i;
383
9.07M
    }
384
2.99k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.99k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390