Coverage Report

Created: 2025-12-07 07:03

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
114M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
24.1M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
30.2M
    sub = STRINGLIB_NEW((data) + (left),        \
22
30.2M
                        (right) - (left));      \
23
30.2M
    if (sub == NULL)                            \
24
30.2M
        goto onError;                           \
25
30.2M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
30.2M
    else                                        \
30
30.2M
        Py_DECREF(sub);
31
32
63.0M
#define SPLIT_ADD(data, left, right) {          \
33
63.0M
    sub = STRINGLIB_NEW((data) + (left),        \
34
63.0M
                        (right) - (left));      \
35
63.0M
    if (sub == NULL)                            \
36
63.0M
        goto onError;                           \
37
63.0M
    if (count < MAX_PREALLOC) {                 \
38
37.7M
        PyList_SET_ITEM(list, count, sub);      \
39
37.7M
    } else {                                    \
40
25.3M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
25.3M
        else                                    \
45
25.3M
            Py_DECREF(sub);                     \
46
25.3M
    }                                           \
47
63.0M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
24.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
191k
{
58
191k
    Py_ssize_t i, j, count=0;
59
191k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
191k
    PyObject *sub;
61
62
191k
    if (list == NULL)
63
0
        return NULL;
64
65
191k
    i = j = 0;
66
2.20M
    while (maxcount-- > 0) {
67
4.23M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
2.06M
            i++;
69
2.17M
        if (i == str_len) break;
70
2.06M
        j = i; i++;
71
109M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
107M
            i++;
73
#if !STRINGLIB_MUTABLE
74
2.06M
        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
51.8k
            Py_INCREF(str_obj);
77
51.8k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
51.8k
            count++;
79
51.8k
            break;
80
51.8k
        }
81
2.01M
#endif
82
6.04M
        SPLIT_ADD(str, j, i);
83
6.04M
    }
84
85
191k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
87.9k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
62.1k
            i++;
90
25.8k
        if (i != str_len)
91
25.8k
            SPLIT_ADD(str, i, str_len);
92
25.8k
    }
93
191k
    FIX_PREALLOC_SIZE(list);
94
191k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
191k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
97.9k
{
58
97.9k
    Py_ssize_t i, j, count=0;
59
97.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
97.9k
    PyObject *sub;
61
62
97.9k
    if (list == NULL)
63
0
        return NULL;
64
65
97.9k
    i = j = 0;
66
670k
    while (maxcount-- > 0) {
67
1.20M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
548k
            i++;
69
654k
        if (i == str_len) break;
70
605k
        j = i; i++;
71
39.0M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
38.4M
            i++;
73
605k
#if !STRINGLIB_MUTABLE
74
605k
        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
33.1k
            Py_INCREF(str_obj);
77
33.1k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
33.1k
            count++;
79
33.1k
            break;
80
33.1k
        }
81
572k
#endif
82
1.71M
        SPLIT_ADD(str, j, i);
83
1.71M
    }
84
85
97.9k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
59.6k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
46.1k
            i++;
90
13.5k
        if (i != str_len)
91
13.5k
            SPLIT_ADD(str, i, str_len);
92
13.5k
    }
93
97.9k
    FIX_PREALLOC_SIZE(list);
94
97.9k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
97.9k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
57
33.3k
{
58
33.3k
    Py_ssize_t i, j, count=0;
59
33.3k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
33.3k
    PyObject *sub;
61
62
33.3k
    if (list == NULL)
63
0
        return NULL;
64
65
33.3k
    i = j = 0;
66
729k
    while (maxcount-- > 0) {
67
1.39M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
677k
            i++;
69
715k
        if (i == str_len) break;
70
699k
        j = i; i++;
71
29.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
28.8M
            i++;
73
699k
#if !STRINGLIB_MUTABLE
74
699k
        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.81k
            Py_INCREF(str_obj);
77
2.81k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.81k
            count++;
79
2.81k
            break;
80
2.81k
        }
81
696k
#endif
82
2.08M
        SPLIT_ADD(str, j, i);
83
2.08M
    }
84
85
33.3k
    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
14.9k
            i++;
90
11.2k
        if (i != str_len)
91
11.2k
            SPLIT_ADD(str, i, str_len);
92
11.2k
    }
93
33.3k
    FIX_PREALLOC_SIZE(list);
94
33.3k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
33.3k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
48.9k
{
58
48.9k
    Py_ssize_t i, j, count=0;
59
48.9k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
48.9k
    PyObject *sub;
61
62
48.9k
    if (list == NULL)
63
0
        return NULL;
64
65
48.9k
    i = j = 0;
66
723k
    while (maxcount-- > 0) {
67
1.48M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
764k
            i++;
69
722k
        if (i == str_len) break;
70
688k
        j = i; i++;
71
31.6M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
30.9M
            i++;
73
688k
#if !STRINGLIB_MUTABLE
74
688k
        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
674k
#endif
82
2.02M
        SPLIT_ADD(str, j, i);
83
2.02M
    }
84
85
48.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.08k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
1.04k
            i++;
90
1.04k
        if (i != str_len)
91
1.04k
            SPLIT_ADD(str, i, str_len);
92
1.04k
    }
93
48.9k
    FIX_PREALLOC_SIZE(list);
94
48.9k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
48.9k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
10.7k
{
58
10.7k
    Py_ssize_t i, j, count=0;
59
10.7k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
10.7k
    PyObject *sub;
61
62
10.7k
    if (list == NULL)
63
0
        return NULL;
64
65
10.7k
    i = j = 0;
66
81.2k
    while (maxcount-- > 0) {
67
151k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
70.6k
            i++;
69
80.9k
        if (i == str_len) break;
70
73.0k
        j = i; i++;
71
9.53M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
9.46M
            i++;
73
73.0k
#if !STRINGLIB_MUTABLE
74
73.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
2.60k
            Py_INCREF(str_obj);
77
2.60k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.60k
            count++;
79
2.60k
            break;
80
2.60k
        }
81
70.4k
#endif
82
211k
        SPLIT_ADD(str, j, i);
83
211k
    }
84
85
10.7k
    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.7k
    FIX_PREALLOC_SIZE(list);
94
10.7k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
10.7k
}
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.7M
{
107
23.7M
    Py_ssize_t i, j, count=0;
108
23.7M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
23.7M
    PyObject *sub;
110
111
23.7M
    if (list == NULL)
112
0
        return NULL;
113
114
23.7M
    i = j = 0;
115
88.1M
    while ((j < str_len) && (maxcount-- > 0)) {
116
410M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
388M
            if (str[j] == ch) {
119
42.8M
                SPLIT_ADD(str, i, j);
120
42.8M
                i = j = j + 1;
121
42.8M
                break;
122
42.8M
            }
123
388M
        }
124
64.3M
    }
125
#if !STRINGLIB_MUTABLE
126
23.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.94M
        Py_INCREF(str_obj);
129
5.94M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
5.94M
        count++;
131
5.94M
    } else
132
17.7M
#endif
133
17.7M
    if (i <= str_len) {
134
35.5M
        SPLIT_ADD(str, i, str_len);
135
35.5M
    }
136
23.7M
    FIX_PREALLOC_SIZE(list);
137
23.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
3.13M
{
107
3.13M
    Py_ssize_t i, j, count=0;
108
3.13M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
3.13M
    PyObject *sub;
110
111
3.13M
    if (list == NULL)
112
0
        return NULL;
113
114
3.13M
    i = j = 0;
115
9.71M
    while ((j < str_len) && (maxcount-- > 0)) {
116
56.2M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
53.6M
            if (str[j] == ch) {
119
3.93M
                SPLIT_ADD(str, i, j);
120
3.93M
                i = j = j + 1;
121
3.93M
                break;
122
3.93M
            }
123
53.6M
        }
124
6.58M
    }
125
3.13M
#if !STRINGLIB_MUTABLE
126
3.13M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.55M
        Py_INCREF(str_obj);
129
2.55M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.55M
        count++;
131
2.55M
    } else
132
577k
#endif
133
577k
    if (i <= str_len) {
134
1.15M
        SPLIT_ADD(str, i, str_len);
135
1.15M
    }
136
3.13M
    FIX_PREALLOC_SIZE(list);
137
3.13M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
3.13M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
19.2M
{
107
19.2M
    Py_ssize_t i, j, count=0;
108
19.2M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
19.2M
    PyObject *sub;
110
111
19.2M
    if (list == NULL)
112
0
        return NULL;
113
114
19.2M
    i = j = 0;
115
60.1M
    while ((j < str_len) && (maxcount-- > 0)) {
116
238M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
220M
            if (str[j] == ch) {
119
22.3M
                SPLIT_ADD(str, i, j);
120
22.3M
                i = j = j + 1;
121
22.3M
                break;
122
22.3M
            }
123
220M
        }
124
40.9M
    }
125
19.2M
#if !STRINGLIB_MUTABLE
126
19.2M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
3.18M
        Py_INCREF(str_obj);
129
3.18M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
3.18M
        count++;
131
3.18M
    } else
132
16.0M
#endif
133
16.0M
    if (i <= str_len) {
134
32.1M
        SPLIT_ADD(str, i, str_len);
135
32.1M
    }
136
19.2M
    FIX_PREALLOC_SIZE(list);
137
19.2M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
19.2M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.18M
{
107
1.18M
    Py_ssize_t i, j, count=0;
108
1.18M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.18M
    PyObject *sub;
110
111
1.18M
    if (list == NULL)
112
0
        return NULL;
113
114
1.18M
    i = j = 0;
115
11.0M
    while ((j < str_len) && (maxcount-- > 0)) {
116
54.7M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
54.5M
            if (str[j] == ch) {
119
9.68M
                SPLIT_ADD(str, i, j);
120
9.68M
                i = j = j + 1;
121
9.68M
                break;
122
9.68M
            }
123
54.5M
        }
124
9.88M
    }
125
1.18M
#if !STRINGLIB_MUTABLE
126
1.18M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
172k
        Py_INCREF(str_obj);
129
172k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
172k
        count++;
131
172k
    } else
132
1.01M
#endif
133
1.01M
    if (i <= str_len) {
134
2.03M
        SPLIT_ADD(str, i, str_len);
135
2.03M
    }
136
1.18M
    FIX_PREALLOC_SIZE(list);
137
1.18M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.18M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
113k
{
107
113k
    Py_ssize_t i, j, count=0;
108
113k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
113k
    PyObject *sub;
110
111
113k
    if (list == NULL)
112
0
        return NULL;
113
114
113k
    i = j = 0;
115
6.55M
    while ((j < str_len) && (maxcount-- > 0)) {
116
39.3M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
39.3M
            if (str[j] == ch) {
119
6.36M
                SPLIT_ADD(str, i, j);
120
6.36M
                i = j = j + 1;
121
6.36M
                break;
122
6.36M
            }
123
39.3M
        }
124
6.44M
    }
125
113k
#if !STRINGLIB_MUTABLE
126
113k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
30.1k
        Py_INCREF(str_obj);
129
30.1k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
30.1k
        count++;
131
30.1k
    } else
132
83.6k
#endif
133
83.6k
    if (i <= str_len) {
134
167k
        SPLIT_ADD(str, i, str_len);
135
167k
    }
136
113k
    FIX_PREALLOC_SIZE(list);
137
113k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
113k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
14.5k
{
107
14.5k
    Py_ssize_t i, j, count=0;
108
14.5k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
14.5k
    PyObject *sub;
110
111
14.5k
    if (list == NULL)
112
0
        return NULL;
113
114
14.5k
    i = j = 0;
115
573k
    while ((j < str_len) && (maxcount-- > 0)) {
116
21.0M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
21.0M
            if (str[j] == ch) {
119
547k
                SPLIT_ADD(str, i, j);
120
547k
                i = j = j + 1;
121
547k
                break;
122
547k
            }
123
21.0M
        }
124
559k
    }
125
14.5k
#if !STRINGLIB_MUTABLE
126
14.5k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
641
        Py_INCREF(str_obj);
129
641
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
641
        count++;
131
641
    } else
132
13.8k
#endif
133
13.8k
    if (i <= str_len) {
134
27.7k
        SPLIT_ADD(str, i, str_len);
135
27.7k
    }
136
14.5k
    FIX_PREALLOC_SIZE(list);
137
14.5k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
14.5k
}
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.9M
{
150
23.9M
    Py_ssize_t i, j, pos, count=0;
151
23.9M
    PyObject *list, *sub;
152
153
23.9M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
23.9M
    else if (sep_len == 1)
158
23.7M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
246k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
246k
    if (list == NULL)
162
0
        return NULL;
163
164
246k
    i = j = 0;
165
434k
    while (maxcount-- > 0) {
166
246k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
246k
        if (pos < 0)
168
58.6k
            break;
169
187k
        j = i + pos;
170
375k
        SPLIT_ADD(str, i, j);
171
375k
        i = j + sep_len;
172
375k
    }
173
#if !STRINGLIB_MUTABLE
174
246k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
58.6k
        Py_INCREF(str_obj);
177
58.6k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
58.6k
        count++;
179
58.6k
    } else
180
187k
#endif
181
187k
    {
182
375k
        SPLIT_ADD(str, i, str_len);
183
375k
    }
184
246k
    FIX_PREALLOC_SIZE(list);
185
246k
    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.13M
{
150
3.13M
    Py_ssize_t i, j, pos, count=0;
151
3.13M
    PyObject *list, *sub;
152
153
3.13M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
3.13M
    else if (sep_len == 1)
158
3.13M
        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.3M
{
150
19.3M
    Py_ssize_t i, j, pos, count=0;
151
19.3M
    PyObject *list, *sub;
152
153
19.3M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
19.3M
    else if (sep_len == 1)
158
19.2M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
109k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
109k
    if (list == NULL)
162
0
        return NULL;
163
164
109k
    i = j = 0;
165
177k
    while (maxcount-- > 0) {
166
109k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
109k
        if (pos < 0)
168
42.3k
            break;
169
67.6k
        j = i + pos;
170
135k
        SPLIT_ADD(str, i, j);
171
135k
        i = j + sep_len;
172
135k
    }
173
109k
#if !STRINGLIB_MUTABLE
174
109k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
42.3k
        Py_INCREF(str_obj);
177
42.3k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
42.3k
        count++;
179
42.3k
    } else
180
67.6k
#endif
181
67.6k
    {
182
135k
        SPLIT_ADD(str, i, str_len);
183
135k
    }
184
109k
    FIX_PREALLOC_SIZE(list);
185
109k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
109k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.21M
{
150
1.21M
    Py_ssize_t i, j, pos, count=0;
151
1.21M
    PyObject *list, *sub;
152
153
1.21M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.21M
    else if (sep_len == 1)
158
1.18M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
24.1k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
24.1k
    if (list == NULL)
162
0
        return NULL;
163
164
24.1k
    i = j = 0;
165
45.8k
    while (maxcount-- > 0) {
166
24.1k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
24.1k
        if (pos < 0)
168
2.32k
            break;
169
21.7k
        j = i + pos;
170
43.5k
        SPLIT_ADD(str, i, j);
171
43.5k
        i = j + sep_len;
172
43.5k
    }
173
24.1k
#if !STRINGLIB_MUTABLE
174
24.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.32k
        Py_INCREF(str_obj);
177
2.32k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.32k
        count++;
179
2.32k
    } else
180
21.7k
#endif
181
21.7k
    {
182
43.5k
        SPLIT_ADD(str, i, str_len);
183
43.5k
    }
184
24.1k
    FIX_PREALLOC_SIZE(list);
185
24.1k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
24.1k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
207k
{
150
207k
    Py_ssize_t i, j, pos, count=0;
151
207k
    PyObject *list, *sub;
152
153
207k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
207k
    else if (sep_len == 1)
158
113k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
93.4k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
93.4k
    if (list == NULL)
162
0
        return NULL;
163
164
93.4k
    i = j = 0;
165
175k
    while (maxcount-- > 0) {
166
93.4k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
93.4k
        if (pos < 0)
168
11.3k
            break;
169
82.1k
        j = i + pos;
170
164k
        SPLIT_ADD(str, i, j);
171
164k
        i = j + sep_len;
172
164k
    }
173
93.4k
#if !STRINGLIB_MUTABLE
174
93.4k
    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
82.1k
#endif
181
82.1k
    {
182
164k
        SPLIT_ADD(str, i, str_len);
183
164k
    }
184
93.4k
    FIX_PREALLOC_SIZE(list);
185
93.4k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
93.4k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
33.4k
{
150
33.4k
    Py_ssize_t i, j, pos, count=0;
151
33.4k
    PyObject *list, *sub;
152
153
33.4k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
33.4k
    else if (sep_len == 1)
158
14.5k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
18.9k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
18.9k
    if (list == NULL)
162
0
        return NULL;
163
164
18.9k
    i = j = 0;
165
35.2k
    while (maxcount-- > 0) {
166
18.9k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
18.9k
        if (pos < 0)
168
2.67k
            break;
169
16.2k
        j = i + pos;
170
32.5k
        SPLIT_ADD(str, i, j);
171
32.5k
        i = j + sep_len;
172
32.5k
    }
173
18.9k
#if !STRINGLIB_MUTABLE
174
18.9k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.67k
        Py_INCREF(str_obj);
177
2.67k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.67k
        count++;
179
2.67k
    } else
180
16.2k
#endif
181
16.2k
    {
182
32.5k
        SPLIT_ADD(str, i, str_len);
183
32.5k
    }
184
18.9k
    FIX_PREALLOC_SIZE(list);
185
18.9k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
18.9k
}
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
30.2M
    for (i = j = 0; i < str_len; ) {
357
30.2M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
256M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
226M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
30.2M
        eol = i;
365
30.2M
        if (i < str_len) {
366
30.2M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
71.4k
                i += 2;
368
30.1M
            else
369
30.1M
                i++;
370
30.2M
            if (keepends)
371
0
                eol = i;
372
30.2M
        }
373
#if !STRINGLIB_MUTABLE
374
30.2M
        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.15k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
5.15k
            break;
379
5.15k
        }
380
30.2M
#endif
381
60.4M
        SPLIT_APPEND(str, j, eol);
382
30.2M
        j = i;
383
30.2M
    }
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.64k
{
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.64k
    Py_ssize_t i;
349
2.64k
    Py_ssize_t j;
350
2.64k
    PyObject *list = PyList_New(0);
351
2.64k
    PyObject *sub;
352
353
2.64k
    if (list == NULL)
354
0
        return NULL;
355
356
6.72M
    for (i = j = 0; i < str_len; ) {
357
6.72M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
36.3M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
29.5M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
6.72M
        eol = i;
365
6.72M
        if (i < str_len) {
366
6.72M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
912
                i += 2;
368
6.72M
            else
369
6.72M
                i++;
370
6.72M
            if (keepends)
371
0
                eol = i;
372
6.72M
        }
373
6.72M
#if !STRINGLIB_MUTABLE
374
6.72M
        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
958
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
958
            break;
379
958
        }
380
6.72M
#endif
381
13.4M
        SPLIT_APPEND(str, j, eol);
382
6.72M
        j = i;
383
6.72M
    }
384
2.64k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.64k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
849
{
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
849
    Py_ssize_t i;
349
849
    Py_ssize_t j;
350
849
    PyObject *list = PyList_New(0);
351
849
    PyObject *sub;
352
353
849
    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
14.4M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
12.4M
            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.62k
                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
216
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
216
            break;
379
216
        }
380
2.03M
#endif
381
4.06M
        SPLIT_APPEND(str, j, eol);
382
2.03M
        j = i;
383
2.03M
    }
384
849
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
849
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
6.89k
{
340
    /* This does not use the preallocated list because splitlines is
341
       usually run with hundreds of newlines.  The overhead of
342
       switching between PyList_SET_ITEM and append causes about a
343
       2-3% slowdown for that common case.  A smarter implementation
344
       could move the if check out, so the SET_ITEMs are done first
345
       and the appends only done when the prealloc buffer is full.
346
       That's too much work for little gain.*/
347
348
6.89k
    Py_ssize_t i;
349
6.89k
    Py_ssize_t j;
350
6.89k
    PyObject *list = PyList_New(0);
351
6.89k
    PyObject *sub;
352
353
6.89k
    if (list == NULL)
354
0
        return NULL;
355
356
10.7M
    for (i = j = 0; i < str_len; ) {
357
10.7M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
92.0M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
81.2M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
10.7M
        eol = i;
365
10.7M
        if (i < str_len) {
366
10.7M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
20.9k
                i += 2;
368
10.7M
            else
369
10.7M
                i++;
370
10.7M
            if (keepends)
371
0
                eol = i;
372
10.7M
        }
373
10.7M
#if !STRINGLIB_MUTABLE
374
10.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
2.87k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
2.87k
            break;
379
2.87k
        }
380
10.7M
#endif
381
21.5M
        SPLIT_APPEND(str, j, eol);
382
10.7M
        j = i;
383
10.7M
    }
384
6.89k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
6.89k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
2.92k
{
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.92k
    Py_ssize_t i;
349
2.92k
    Py_ssize_t j;
350
2.92k
    PyObject *list = PyList_New(0);
351
2.92k
    PyObject *sub;
352
353
2.92k
    if (list == NULL)
354
0
        return NULL;
355
356
10.6M
    for (i = j = 0; i < str_len; ) {
357
10.6M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
113M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
103M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
10.6M
        eol = i;
365
10.6M
        if (i < str_len) {
366
10.6M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
47.9k
                i += 2;
368
10.6M
            else
369
10.6M
                i++;
370
10.6M
            if (keepends)
371
0
                eol = i;
372
10.6M
        }
373
10.6M
#if !STRINGLIB_MUTABLE
374
10.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
1.11k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.11k
            break;
379
1.11k
        }
380
10.6M
#endif
381
21.3M
        SPLIT_APPEND(str, j, eol);
382
10.6M
        j = i;
383
10.6M
    }
384
2.92k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.92k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390