Coverage Report

Created: 2025-11-30 06:38

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
118M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
24.3M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
26.9M
    sub = STRINGLIB_NEW((data) + (left),        \
22
26.9M
                        (right) - (left));      \
23
26.9M
    if (sub == NULL)                            \
24
26.9M
        goto onError;                           \
25
26.9M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
26.9M
    else                                        \
30
26.9M
        Py_DECREF(sub);
31
32
65.7M
#define SPLIT_ADD(data, left, right) {          \
33
65.7M
    sub = STRINGLIB_NEW((data) + (left),        \
34
65.7M
                        (right) - (left));      \
35
65.7M
    if (sub == NULL)                            \
36
65.7M
        goto onError;                           \
37
65.7M
    if (count < MAX_PREALLOC) {                 \
38
37.1M
        PyList_SET_ITEM(list, count, sub);      \
39
37.1M
    } else {                                    \
40
28.6M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
28.6M
        else                                    \
45
28.6M
            Py_DECREF(sub);                     \
46
28.6M
    }                                           \
47
65.7M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
24.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
183k
{
58
183k
    Py_ssize_t i, j, count=0;
59
183k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
183k
    PyObject *sub;
61
62
183k
    if (list == NULL)
63
0
        return NULL;
64
65
183k
    i = j = 0;
66
2.35M
    while (maxcount-- > 0) {
67
4.51M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
2.18M
            i++;
69
2.32M
        if (i == str_len) break;
70
2.21M
        j = i; i++;
71
119M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
117M
            i++;
73
#if !STRINGLIB_MUTABLE
74
2.21M
        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.4k
            Py_INCREF(str_obj);
77
46.4k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
46.4k
            count++;
79
46.4k
            break;
80
46.4k
        }
81
2.17M
#endif
82
6.51M
        SPLIT_ADD(str, j, i);
83
6.51M
    }
84
85
183k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
57.4k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
31.0k
            i++;
90
26.4k
        if (i != str_len)
91
26.4k
            SPLIT_ADD(str, i, str_len);
92
26.4k
    }
93
183k
    FIX_PREALLOC_SIZE(list);
94
183k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
183k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
89.5k
{
58
89.5k
    Py_ssize_t i, j, count=0;
59
89.5k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
89.5k
    PyObject *sub;
61
62
89.5k
    if (list == NULL)
63
0
        return NULL;
64
65
89.5k
    i = j = 0;
66
667k
    while (maxcount-- > 0) {
67
1.17M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
524k
            i++;
69
651k
        if (i == str_len) break;
70
603k
        j = i; i++;
71
39.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
38.9M
            i++;
73
603k
#if !STRINGLIB_MUTABLE
74
603k
        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
25.8k
            Py_INCREF(str_obj);
77
25.8k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
25.8k
            count++;
79
25.8k
            break;
80
25.8k
        }
81
578k
#endif
82
1.73M
        SPLIT_ADD(str, j, i);
83
1.73M
    }
84
85
89.5k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
28.3k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
14.5k
            i++;
90
13.7k
        if (i != str_len)
91
13.7k
            SPLIT_ADD(str, i, str_len);
92
13.7k
    }
93
89.5k
    FIX_PREALLOC_SIZE(list);
94
89.5k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
89.5k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
57
28.6k
{
58
28.6k
    Py_ssize_t i, j, count=0;
59
28.6k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
28.6k
    PyObject *sub;
61
62
28.6k
    if (list == NULL)
63
0
        return NULL;
64
65
28.6k
    i = j = 0;
66
703k
    while (maxcount-- > 0) {
67
1.35M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
659k
            i++;
69
691k
        if (i == str_len) break;
70
677k
        j = i; i++;
71
29.1M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
28.4M
            i++;
73
677k
#if !STRINGLIB_MUTABLE
74
677k
        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.87k
            Py_INCREF(str_obj);
77
2.87k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.87k
            count++;
79
2.87k
            break;
80
2.87k
        }
81
674k
#endif
82
2.02M
        SPLIT_ADD(str, j, i);
83
2.02M
    }
84
85
28.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.8k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
15.2k
            i++;
90
11.6k
        if (i != str_len)
91
11.6k
            SPLIT_ADD(str, i, str_len);
92
11.6k
    }
93
28.6k
    FIX_PREALLOC_SIZE(list);
94
28.6k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
28.6k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
53.9k
{
58
53.9k
    Py_ssize_t i, j, count=0;
59
53.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
53.9k
    PyObject *sub;
61
62
53.9k
    if (list == NULL)
63
0
        return NULL;
64
65
53.9k
    i = j = 0;
66
917k
    while (maxcount-- > 0) {
67
1.86M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
951k
            i++;
69
916k
        if (i == str_len) break;
70
878k
        j = i; i++;
71
41.9M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
41.1M
            i++;
73
878k
#if !STRINGLIB_MUTABLE
74
878k
        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
14.7k
            Py_INCREF(str_obj);
77
14.7k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
14.7k
            count++;
79
14.7k
            break;
80
14.7k
        }
81
863k
#endif
82
2.59M
        SPLIT_ADD(str, j, i);
83
2.59M
    }
84
85
53.9k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
2.32k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
1.16k
            i++;
90
1.16k
        if (i != str_len)
91
1.16k
            SPLIT_ADD(str, i, str_len);
92
1.16k
    }
93
53.9k
    FIX_PREALLOC_SIZE(list);
94
53.9k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
53.9k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
11.1k
{
58
11.1k
    Py_ssize_t i, j, count=0;
59
11.1k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
11.1k
    PyObject *sub;
61
62
11.1k
    if (list == NULL)
63
0
        return NULL;
64
65
11.1k
    i = j = 0;
66
67.2k
    while (maxcount-- > 0) {
67
121k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
54.9k
            i++;
69
66.9k
        if (i == str_len) break;
70
59.1k
        j = i; i++;
71
9.17M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
9.11M
            i++;
73
59.1k
#if !STRINGLIB_MUTABLE
74
59.1k
        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.03k
            Py_INCREF(str_obj);
77
3.03k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.03k
            count++;
79
3.03k
            break;
80
3.03k
        }
81
56.1k
#endif
82
168k
        SPLIT_ADD(str, j, i);
83
168k
    }
84
85
11.1k
    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.1k
    FIX_PREALLOC_SIZE(list);
94
11.1k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
11.1k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_split_whitespace
100
101
Py_LOCAL_INLINE(PyObject *)
102
STRINGLIB(split_char)(PyObject* str_obj,
103
                     const STRINGLIB_CHAR* str, Py_ssize_t str_len,
104
                     const STRINGLIB_CHAR ch,
105
                     Py_ssize_t maxcount)
106
23.8M
{
107
23.8M
    Py_ssize_t i, j, count=0;
108
23.8M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
23.8M
    PyObject *sub;
110
111
23.8M
    if (list == NULL)
112
0
        return NULL;
113
114
23.8M
    i = j = 0;
115
91.2M
    while ((j < str_len) && (maxcount-- > 0)) {
116
419M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
398M
            if (str[j] == ch) {
119
45.7M
                SPLIT_ADD(str, i, j);
120
45.7M
                i = j = j + 1;
121
45.7M
                break;
122
45.7M
            }
123
398M
        }
124
67.3M
    }
125
#if !STRINGLIB_MUTABLE
126
23.8M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
6.41M
        Py_INCREF(str_obj);
129
6.41M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
6.41M
        count++;
131
6.41M
    } else
132
17.4M
#endif
133
17.4M
    if (i <= str_len) {
134
34.9M
        SPLIT_ADD(str, i, str_len);
135
34.9M
    }
136
23.8M
    FIX_PREALLOC_SIZE(list);
137
23.8M
    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.37M
{
107
3.37M
    Py_ssize_t i, j, count=0;
108
3.37M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
3.37M
    PyObject *sub;
110
111
3.37M
    if (list == NULL)
112
0
        return NULL;
113
114
3.37M
    i = j = 0;
115
10.8M
    while ((j < str_len) && (maxcount-- > 0)) {
116
57.0M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
54.1M
            if (str[j] == ch) {
119
4.62M
                SPLIT_ADD(str, i, j);
120
4.62M
                i = j = j + 1;
121
4.62M
                break;
122
4.62M
            }
123
54.1M
        }
124
7.48M
    }
125
3.37M
#if !STRINGLIB_MUTABLE
126
3.37M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.76M
        Py_INCREF(str_obj);
129
2.76M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.76M
        count++;
131
2.76M
    } else
132
617k
#endif
133
617k
    if (i <= str_len) {
134
1.23M
        SPLIT_ADD(str, i, str_len);
135
1.23M
    }
136
3.37M
    FIX_PREALLOC_SIZE(list);
137
3.37M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
3.37M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
19.1M
{
107
19.1M
    Py_ssize_t i, j, count=0;
108
19.1M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
19.1M
    PyObject *sub;
110
111
19.1M
    if (list == NULL)
112
0
        return NULL;
113
114
19.1M
    i = j = 0;
115
59.6M
    while ((j < str_len) && (maxcount-- > 0)) {
116
235M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
217M
            if (str[j] == ch) {
119
22.0M
                SPLIT_ADD(str, i, j);
120
22.0M
                i = j = j + 1;
121
22.0M
                break;
122
22.0M
            }
123
217M
        }
124
40.4M
    }
125
19.1M
#if !STRINGLIB_MUTABLE
126
19.1M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
3.44M
        Py_INCREF(str_obj);
129
3.44M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
3.44M
        count++;
131
3.44M
    } 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
19.1M
    FIX_PREALLOC_SIZE(list);
137
19.1M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
19.1M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.22M
{
107
1.22M
    Py_ssize_t i, j, count=0;
108
1.22M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.22M
    PyObject *sub;
110
111
1.22M
    if (list == NULL)
112
0
        return NULL;
113
114
1.22M
    i = j = 0;
115
10.9M
    while ((j < str_len) && (maxcount-- > 0)) {
116
55.3M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
55.1M
            if (str[j] == ch) {
119
9.53M
                SPLIT_ADD(str, i, j);
120
9.53M
                i = j = j + 1;
121
9.53M
                break;
122
9.53M
            }
123
55.1M
        }
124
9.73M
    }
125
1.22M
#if !STRINGLIB_MUTABLE
126
1.22M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
175k
        Py_INCREF(str_obj);
129
175k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
175k
        count++;
131
175k
    } else
132
1.04M
#endif
133
1.04M
    if (i <= str_len) {
134
2.09M
        SPLIT_ADD(str, i, str_len);
135
2.09M
    }
136
1.22M
    FIX_PREALLOC_SIZE(list);
137
1.22M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.22M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
125k
{
107
125k
    Py_ssize_t i, j, count=0;
108
125k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
125k
    PyObject *sub;
110
111
125k
    if (list == NULL)
112
0
        return NULL;
113
114
125k
    i = j = 0;
115
9.25M
    while ((j < str_len) && (maxcount-- > 0)) {
116
50.2M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
50.1M
            if (str[j] == ch) {
119
9.03M
                SPLIT_ADD(str, i, j);
120
9.03M
                i = j = j + 1;
121
9.03M
                break;
122
9.03M
            }
123
50.1M
        }
124
9.13M
    }
125
125k
#if !STRINGLIB_MUTABLE
126
125k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
37.5k
        Py_INCREF(str_obj);
129
37.5k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
37.5k
        count++;
131
37.5k
    } else
132
87.8k
#endif
133
87.8k
    if (i <= str_len) {
134
175k
        SPLIT_ADD(str, i, str_len);
135
175k
    }
136
125k
    FIX_PREALLOC_SIZE(list);
137
125k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
125k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
15.4k
{
107
15.4k
    Py_ssize_t i, j, count=0;
108
15.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
15.4k
    PyObject *sub;
110
111
15.4k
    if (list == NULL)
112
0
        return NULL;
113
114
15.4k
    i = j = 0;
115
538k
    while ((j < str_len) && (maxcount-- > 0)) {
116
21.3M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
21.2M
            if (str[j] == ch) {
119
511k
                SPLIT_ADD(str, i, j);
120
511k
                i = j = j + 1;
121
511k
                break;
122
511k
            }
123
21.2M
        }
124
523k
    }
125
15.4k
#if !STRINGLIB_MUTABLE
126
15.4k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
661
        Py_INCREF(str_obj);
129
661
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
661
        count++;
131
661
    } else
132
14.8k
#endif
133
14.8k
    if (i <= str_len) {
134
29.6k
        SPLIT_ADD(str, i, str_len);
135
29.6k
    }
136
15.4k
    FIX_PREALLOC_SIZE(list);
137
15.4k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
15.4k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_split_char
143
144
Py_LOCAL_INLINE(PyObject *)
145
STRINGLIB(split)(PyObject* str_obj,
146
                const STRINGLIB_CHAR* str, Py_ssize_t str_len,
147
                const STRINGLIB_CHAR* sep, Py_ssize_t sep_len,
148
                Py_ssize_t maxcount)
149
24.1M
{
150
24.1M
    Py_ssize_t i, j, pos, count=0;
151
24.1M
    PyObject *list, *sub;
152
153
24.1M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
24.1M
    else if (sep_len == 1)
158
23.8M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
230k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
230k
    if (list == NULL)
162
0
        return NULL;
163
164
230k
    i = j = 0;
165
409k
    while (maxcount-- > 0) {
166
230k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
230k
        if (pos < 0)
168
51.7k
            break;
169
178k
        j = i + pos;
170
357k
        SPLIT_ADD(str, i, j);
171
357k
        i = j + sep_len;
172
357k
    }
173
#if !STRINGLIB_MUTABLE
174
230k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
51.7k
        Py_INCREF(str_obj);
177
51.7k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
51.7k
        count++;
179
51.7k
    } else
180
178k
#endif
181
178k
    {
182
357k
        SPLIT_ADD(str, i, str_len);
183
357k
    }
184
230k
    FIX_PREALLOC_SIZE(list);
185
230k
    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.37M
{
150
3.37M
    Py_ssize_t i, j, pos, count=0;
151
3.37M
    PyObject *list, *sub;
152
153
3.37M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
3.37M
    else if (sep_len == 1)
158
3.37M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
0
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
0
    if (list == NULL)
162
0
        return NULL;
163
164
0
    i = j = 0;
165
0
    while (maxcount-- > 0) {
166
0
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
0
        if (pos < 0)
168
0
            break;
169
0
        j = i + pos;
170
0
        SPLIT_ADD(str, i, j);
171
0
        i = j + sep_len;
172
0
    }
173
0
#if !STRINGLIB_MUTABLE
174
0
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
0
        Py_INCREF(str_obj);
177
0
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
0
        count++;
179
0
    } else
180
0
#endif
181
0
    {
182
0
        SPLIT_ADD(str, i, str_len);
183
0
    }
184
0
    FIX_PREALLOC_SIZE(list);
185
0
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
0
}
unicodeobject.c:asciilib_split
Line
Count
Source
149
19.2M
{
150
19.2M
    Py_ssize_t i, j, pos, count=0;
151
19.2M
    PyObject *list, *sub;
152
153
19.2M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
19.2M
    else if (sep_len == 1)
158
19.1M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
94.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
94.2k
    if (list == NULL)
162
0
        return NULL;
163
164
94.2k
    i = j = 0;
165
152k
    while (maxcount-- > 0) {
166
94.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
94.2k
        if (pos < 0)
168
35.6k
            break;
169
58.6k
        j = i + pos;
170
117k
        SPLIT_ADD(str, i, j);
171
117k
        i = j + sep_len;
172
117k
    }
173
94.2k
#if !STRINGLIB_MUTABLE
174
94.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
35.6k
        Py_INCREF(str_obj);
177
35.6k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
35.6k
        count++;
179
35.6k
    } else
180
58.6k
#endif
181
58.6k
    {
182
117k
        SPLIT_ADD(str, i, str_len);
183
117k
    }
184
94.2k
    FIX_PREALLOC_SIZE(list);
185
94.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
94.2k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.23M
{
150
1.23M
    Py_ssize_t i, j, pos, count=0;
151
1.23M
    PyObject *list, *sub;
152
153
1.23M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.23M
    else if (sep_len == 1)
158
1.22M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
16.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
16.2k
    if (list == NULL)
162
0
        return NULL;
163
164
16.2k
    i = j = 0;
165
30.3k
    while (maxcount-- > 0) {
166
16.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
16.2k
        if (pos < 0)
168
2.14k
            break;
169
14.0k
        j = i + pos;
170
28.1k
        SPLIT_ADD(str, i, j);
171
28.1k
        i = j + sep_len;
172
28.1k
    }
173
16.2k
#if !STRINGLIB_MUTABLE
174
16.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.14k
        Py_INCREF(str_obj);
177
2.14k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.14k
        count++;
179
2.14k
    } else
180
14.0k
#endif
181
14.0k
    {
182
28.1k
        SPLIT_ADD(str, i, str_len);
183
28.1k
    }
184
16.2k
    FIX_PREALLOC_SIZE(list);
185
16.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
16.2k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
225k
{
150
225k
    Py_ssize_t i, j, pos, count=0;
151
225k
    PyObject *list, *sub;
152
153
225k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
225k
    else if (sep_len == 1)
158
125k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
100k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
100k
    if (list == NULL)
162
0
        return NULL;
163
164
100k
    i = j = 0;
165
189k
    while (maxcount-- > 0) {
166
100k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
100k
        if (pos < 0)
168
11.3k
            break;
169
89.0k
        j = i + pos;
170
178k
        SPLIT_ADD(str, i, j);
171
178k
        i = j + sep_len;
172
178k
    }
173
100k
#if !STRINGLIB_MUTABLE
174
100k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
11.3k
        Py_INCREF(str_obj);
177
11.3k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
11.3k
        count++;
179
11.3k
    } else
180
89.0k
#endif
181
89.0k
    {
182
178k
        SPLIT_ADD(str, i, str_len);
183
178k
    }
184
100k
    FIX_PREALLOC_SIZE(list);
185
100k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
100k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
35.0k
{
150
35.0k
    Py_ssize_t i, j, pos, count=0;
151
35.0k
    PyObject *list, *sub;
152
153
35.0k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
35.0k
    else if (sep_len == 1)
158
15.4k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
19.5k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
19.5k
    if (list == NULL)
162
0
        return NULL;
163
164
19.5k
    i = j = 0;
165
36.4k
    while (maxcount-- > 0) {
166
19.5k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
19.5k
        if (pos < 0)
168
2.59k
            break;
169
16.9k
        j = i + pos;
170
33.8k
        SPLIT_ADD(str, i, j);
171
33.8k
        i = j + sep_len;
172
33.8k
    }
173
19.5k
#if !STRINGLIB_MUTABLE
174
19.5k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.59k
        Py_INCREF(str_obj);
177
2.59k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.59k
        count++;
179
2.59k
    } else
180
16.9k
#endif
181
16.9k
    {
182
33.8k
        SPLIT_ADD(str, i, str_len);
183
33.8k
    }
184
19.5k
    FIX_PREALLOC_SIZE(list);
185
19.5k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
19.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
50
{
248
50
    Py_ssize_t i, j, count=0;
249
50
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
50
    PyObject *sub;
251
252
50
    if (list == NULL)
253
0
        return NULL;
254
255
50
    i = j = str_len - 1;
256
100
    while ((i >= 0) && (maxcount-- > 0)) {
257
50
        for(; i >= 0; i--) {
258
50
            if (str[i] == ch) {
259
50
                SPLIT_ADD(str, i + 1, j + 1);
260
50
                j = i = i - 1;
261
50
                break;
262
50
            }
263
50
        }
264
50
    }
265
#if !STRINGLIB_MUTABLE
266
50
    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
50
#endif
273
50
    if (j >= -1) {
274
100
        SPLIT_ADD(str, 0, j + 1);
275
100
    }
276
50
    FIX_PREALLOC_SIZE(list);
277
50
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
50
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
0
    return NULL;
284
50
}
Unexecuted instantiation: bytesobject.c:stringlib_rsplit_char
unicodeobject.c:asciilib_rsplit_char
Line
Count
Source
247
50
{
248
50
    Py_ssize_t i, j, count=0;
249
50
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
250
50
    PyObject *sub;
251
252
50
    if (list == NULL)
253
0
        return NULL;
254
255
50
    i = j = str_len - 1;
256
100
    while ((i >= 0) && (maxcount-- > 0)) {
257
50
        for(; i >= 0; i--) {
258
50
            if (str[i] == ch) {
259
50
                SPLIT_ADD(str, i + 1, j + 1);
260
50
                j = i = i - 1;
261
50
                break;
262
50
            }
263
50
        }
264
50
    }
265
50
#if !STRINGLIB_MUTABLE
266
50
    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
50
#endif
273
50
    if (j >= -1) {
274
100
        SPLIT_ADD(str, 0, j + 1);
275
100
    }
276
50
    FIX_PREALLOC_SIZE(list);
277
50
    if (PyList_Reverse(list) < 0)
278
0
        goto onError;
279
50
    return list;
280
281
0
  onError:
282
0
    Py_DECREF(list);
283
    return NULL;
284
50
}
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
50
{
292
50
    Py_ssize_t j, pos, count=0;
293
50
    PyObject *list, *sub;
294
295
50
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
50
    else if (sep_len == 1)
300
50
        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
50
{
292
50
    Py_ssize_t j, pos, count=0;
293
50
    PyObject *list, *sub;
294
295
50
    if (sep_len == 0) {
296
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
297
0
        return NULL;
298
0
    }
299
50
    else if (sep_len == 1)
300
50
        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
13.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
13.3k
    Py_ssize_t i;
349
13.3k
    Py_ssize_t j;
350
13.3k
    PyObject *list = PyList_New(0);
351
13.3k
    PyObject *sub;
352
353
13.3k
    if (list == NULL)
354
0
        return NULL;
355
356
26.9M
    for (i = j = 0; i < str_len; ) {
357
26.9M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
250M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
223M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
26.9M
        eol = i;
365
26.9M
        if (i < str_len) {
366
26.9M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
70.9k
                i += 2;
368
26.9M
            else
369
26.9M
                i++;
370
26.9M
            if (keepends)
371
0
                eol = i;
372
26.9M
        }
373
#if !STRINGLIB_MUTABLE
374
26.9M
        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.21k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
5.21k
            break;
379
5.21k
        }
380
26.9M
#endif
381
53.9M
        SPLIT_APPEND(str, j, eol);
382
26.9M
        j = i;
383
26.9M
    }
384
13.3k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
13.3k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
2.69k
{
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.69k
    Py_ssize_t i;
349
2.69k
    Py_ssize_t j;
350
2.69k
    PyObject *list = PyList_New(0);
351
2.69k
    PyObject *sub;
352
353
2.69k
    if (list == NULL)
354
0
        return NULL;
355
356
7.35M
    for (i = j = 0; i < str_len; ) {
357
7.35M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
39.2M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
31.8M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
7.35M
        eol = i;
365
7.35M
        if (i < str_len) {
366
7.35M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
935
                i += 2;
368
7.35M
            else
369
7.35M
                i++;
370
7.35M
            if (keepends)
371
0
                eol = i;
372
7.35M
        }
373
7.35M
#if !STRINGLIB_MUTABLE
374
7.35M
        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
969
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
969
            break;
379
969
        }
380
7.35M
#endif
381
14.7M
        SPLIT_APPEND(str, j, eol);
382
7.35M
        j = i;
383
7.35M
    }
384
2.69k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.69k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
832
{
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
832
    Py_ssize_t i;
349
832
    Py_ssize_t j;
350
832
    PyObject *list = PyList_New(0);
351
832
    PyObject *sub;
352
353
832
    if (list == NULL)
354
0
        return NULL;
355
356
2.03M
    for (i = j = 0; i < str_len; ) {
357
2.03M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
11.4M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
9.38M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
2.03M
        eol = i;
365
2.03M
        if (i < str_len) {
366
2.03M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
1.87k
                i += 2;
368
2.03M
            else
369
2.03M
                i++;
370
2.03M
            if (keepends)
371
0
                eol = i;
372
2.03M
        }
373
2.03M
#if !STRINGLIB_MUTABLE
374
2.03M
        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
209
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
209
            break;
379
209
        }
380
2.03M
#endif
381
4.06M
        SPLIT_APPEND(str, j, eol);
382
2.03M
        j = i;
383
2.03M
    }
384
832
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
832
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
6.91k
{
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
6.91k
    Py_ssize_t i;
349
6.91k
    Py_ssize_t j;
350
6.91k
    PyObject *list = PyList_New(0);
351
6.91k
    PyObject *sub;
352
353
6.91k
    if (list == NULL)
354
0
        return NULL;
355
356
7.76M
    for (i = j = 0; i < str_len; ) {
357
7.75M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
92.1M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
84.4M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
7.75M
        eol = i;
365
7.75M
        if (i < str_len) {
366
7.75M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
19.9k
                i += 2;
368
7.73M
            else
369
7.73M
                i++;
370
7.75M
            if (keepends)
371
0
                eol = i;
372
7.75M
        }
373
7.75M
#if !STRINGLIB_MUTABLE
374
7.75M
        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
2.91k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
2.91k
            break;
379
2.91k
        }
380
7.75M
#endif
381
15.5M
        SPLIT_APPEND(str, j, eol);
382
7.75M
        j = i;
383
7.75M
    }
384
6.91k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
6.91k
}
unicodeobject.c:ucs4lib_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
9.84M
    for (i = j = 0; i < str_len; ) {
357
9.84M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
107M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
98.0M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
9.84M
        eol = i;
365
9.84M
        if (i < str_len) {
366
9.83M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
48.1k
                i += 2;
368
9.79M
            else
369
9.79M
                i++;
370
9.83M
            if (keepends)
371
0
                eol = i;
372
9.83M
        }
373
9.84M
#if !STRINGLIB_MUTABLE
374
9.84M
        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.12k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.12k
            break;
379
1.12k
        }
380
9.83M
#endif
381
19.6M
        SPLIT_APPEND(str, j, eol);
382
9.83M
        j = i;
383
9.83M
    }
384
2.88k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.88k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390