Coverage Report

Created: 2025-10-12 06:48

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
110M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
20.2M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
31.1M
    sub = STRINGLIB_NEW((data) + (left),        \
22
31.1M
                        (right) - (left));      \
23
31.1M
    if (sub == NULL)                            \
24
31.1M
        goto onError;                           \
25
31.1M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
31.1M
    else                                        \
30
31.1M
        Py_DECREF(sub);
31
32
66.3M
#define SPLIT_ADD(data, left, right) {          \
33
66.3M
    sub = STRINGLIB_NEW((data) + (left),        \
34
66.3M
                        (right) - (left));      \
35
66.3M
    if (sub == NULL)                            \
36
66.3M
        goto onError;                           \
37
66.3M
    if (count < MAX_PREALLOC) {                 \
38
29.0M
        PyList_SET_ITEM(list, count, sub);      \
39
37.3M
    } else {                                    \
40
37.3M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
37.3M
        else                                    \
45
37.3M
            Py_DECREF(sub);                     \
46
37.3M
    }                                           \
47
66.3M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
20.2M
#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
181k
{
58
181k
    Py_ssize_t i, j, count=0;
59
181k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
181k
    PyObject *sub;
61
62
181k
    if (list == NULL)
63
0
        return NULL;
64
65
181k
    i = j = 0;
66
3.20M
    while (maxcount-- > 0) {
67
6.20M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
3.03M
            i++;
69
3.17M
        if (i == str_len) break;
70
3.06M
        j = i; i++;
71
164M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
161M
            i++;
73
#if !STRINGLIB_MUTABLE
74
3.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
38.4k
            Py_INCREF(str_obj);
77
38.4k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
38.4k
            count++;
79
38.4k
            break;
80
38.4k
        }
81
3.02M
#endif
82
9.07M
        SPLIT_ADD(str, j, i);
83
9.07M
    }
84
85
181k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
58.8k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
31.8k
            i++;
90
27.0k
        if (i != str_len)
91
27.0k
            SPLIT_ADD(str, i, str_len);
92
27.0k
    }
93
181k
    FIX_PREALLOC_SIZE(list);
94
181k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
181k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
86.3k
{
58
86.3k
    Py_ssize_t i, j, count=0;
59
86.3k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
86.3k
    PyObject *sub;
61
62
86.3k
    if (list == NULL)
63
0
        return NULL;
64
65
86.3k
    i = j = 0;
66
969k
    while (maxcount-- > 0) {
67
1.78M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
827k
            i++;
69
953k
        if (i == str_len) break;
70
902k
        j = i; i++;
71
53.7M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
52.8M
            i++;
73
902k
#if !STRINGLIB_MUTABLE
74
902k
        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
19.2k
            Py_INCREF(str_obj);
77
19.2k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
19.2k
            count++;
79
19.2k
            break;
80
19.2k
        }
81
883k
#endif
82
2.65M
        SPLIT_ADD(str, j, i);
83
2.65M
    }
84
85
86.3k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
27.4k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
14.1k
            i++;
90
13.2k
        if (i != str_len)
91
13.2k
            SPLIT_ADD(str, i, str_len);
92
13.2k
    }
93
86.3k
    FIX_PREALLOC_SIZE(list);
94
86.3k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
86.3k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
57
32.1k
{
58
32.1k
    Py_ssize_t i, j, count=0;
59
32.1k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
32.1k
    PyObject *sub;
61
62
32.1k
    if (list == NULL)
63
0
        return NULL;
64
65
32.1k
    i = j = 0;
66
1.12M
    while (maxcount-- > 0) {
67
2.18M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
1.07M
            i++;
69
1.11M
        if (i == str_len) break;
70
1.09M
        j = i; i++;
71
46.4M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
45.3M
            i++;
73
1.09M
#if !STRINGLIB_MUTABLE
74
1.09M
        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.10k
            Py_INCREF(str_obj);
77
3.10k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.10k
            count++;
79
3.10k
            break;
80
3.10k
        }
81
1.09M
#endif
82
3.27M
        SPLIT_ADD(str, j, i);
83
3.27M
    }
84
85
32.1k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
29.8k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
16.8k
            i++;
90
13.0k
        if (i != str_len)
91
13.0k
            SPLIT_ADD(str, i, str_len);
92
13.0k
    }
93
32.1k
    FIX_PREALLOC_SIZE(list);
94
32.1k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
32.1k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
51.4k
{
58
51.4k
    Py_ssize_t i, j, count=0;
59
51.4k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
51.4k
    PyObject *sub;
61
62
51.4k
    if (list == NULL)
63
0
        return NULL;
64
65
51.4k
    i = j = 0;
66
997k
    while (maxcount-- > 0) {
67
2.02M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
1.03M
            i++;
69
996k
        if (i == str_len) break;
70
959k
        j = i; i++;
71
52.4M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
51.4M
            i++;
73
959k
#if !STRINGLIB_MUTABLE
74
959k
        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.1k
            Py_INCREF(str_obj);
77
13.1k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
13.1k
            count++;
79
13.1k
            break;
80
13.1k
        }
81
945k
#endif
82
2.83M
        SPLIT_ADD(str, j, i);
83
2.83M
    }
84
85
51.4k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
1.58k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
791
            i++;
90
791
        if (i != str_len)
91
791
            SPLIT_ADD(str, i, str_len);
92
791
    }
93
51.4k
    FIX_PREALLOC_SIZE(list);
94
51.4k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
51.4k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
12.0k
{
58
12.0k
    Py_ssize_t i, j, count=0;
59
12.0k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
12.0k
    PyObject *sub;
61
62
12.0k
    if (list == NULL)
63
0
        return NULL;
64
65
12.0k
    i = j = 0;
66
114k
    while (maxcount-- > 0) {
67
215k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
102k
            i++;
69
113k
        if (i == str_len) break;
70
105k
        j = i; i++;
71
12.2M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
12.1M
            i++;
73
105k
#if !STRINGLIB_MUTABLE
74
105k
        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.93k
            Py_INCREF(str_obj);
77
2.93k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
2.93k
            count++;
79
2.93k
            break;
80
2.93k
        }
81
102k
#endif
82
306k
        SPLIT_ADD(str, j, i);
83
306k
    }
84
85
12.0k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
0
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
0
            i++;
90
0
        if (i != str_len)
91
0
            SPLIT_ADD(str, i, str_len);
92
0
    }
93
12.0k
    FIX_PREALLOC_SIZE(list);
94
12.0k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
    return NULL;
99
12.0k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_split_whitespace
100
101
Py_LOCAL_INLINE(PyObject *)
102
STRINGLIB(split_char)(PyObject* str_obj,
103
                     const STRINGLIB_CHAR* str, Py_ssize_t str_len,
104
                     const STRINGLIB_CHAR ch,
105
                     Py_ssize_t maxcount)
106
19.8M
{
107
19.8M
    Py_ssize_t i, j, count=0;
108
19.8M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
19.8M
    PyObject *sub;
110
111
19.8M
    if (list == NULL)
112
0
        return NULL;
113
114
19.8M
    i = j = 0;
115
87.2M
    while ((j < str_len) && (maxcount-- > 0)) {
116
421M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
403M
            if (str[j] == ch) {
119
49.5M
                SPLIT_ADD(str, i, j);
120
49.5M
                i = j = j + 1;
121
49.5M
                break;
122
49.5M
            }
123
403M
        }
124
67.3M
    }
125
#if !STRINGLIB_MUTABLE
126
19.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.47M
        Py_INCREF(str_obj);
129
6.47M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
6.47M
        count++;
131
6.47M
    } else
132
13.4M
#endif
133
13.4M
    if (i <= str_len) {
134
26.8M
        SPLIT_ADD(str, i, str_len);
135
26.8M
    }
136
19.8M
    FIX_PREALLOC_SIZE(list);
137
19.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.23M
{
107
3.23M
    Py_ssize_t i, j, count=0;
108
3.23M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
3.23M
    PyObject *sub;
110
111
3.23M
    if (list == NULL)
112
0
        return NULL;
113
114
3.23M
    i = j = 0;
115
10.7M
    while ((j < str_len) && (maxcount-- > 0)) {
116
59.6M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
56.9M
            if (str[j] == ch) {
119
4.79M
                SPLIT_ADD(str, i, j);
120
4.79M
                i = j = j + 1;
121
4.79M
                break;
122
4.79M
            }
123
56.9M
        }
124
7.49M
    }
125
3.23M
#if !STRINGLIB_MUTABLE
126
3.23M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.61M
        Py_INCREF(str_obj);
129
2.61M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.61M
        count++;
131
2.61M
    } else
132
619k
#endif
133
619k
    if (i <= str_len) {
134
1.23M
        SPLIT_ADD(str, i, str_len);
135
1.23M
    }
136
3.23M
    FIX_PREALLOC_SIZE(list);
137
3.23M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
3.23M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
15.4M
{
107
15.4M
    Py_ssize_t i, j, count=0;
108
15.4M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
15.4M
    PyObject *sub;
110
111
15.4M
    if (list == NULL)
112
0
        return NULL;
113
114
15.4M
    i = j = 0;
115
52.3M
    while ((j < str_len) && (maxcount-- > 0)) {
116
207M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
192M
            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
192M
        }
124
36.8M
    }
125
15.4M
#if !STRINGLIB_MUTABLE
126
15.4M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
3.70M
        Py_INCREF(str_obj);
129
3.70M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
3.70M
        count++;
131
3.70M
    } else
132
11.7M
#endif
133
11.7M
    if (i <= str_len) {
134
23.5M
        SPLIT_ADD(str, i, str_len);
135
23.5M
    }
136
15.4M
    FIX_PREALLOC_SIZE(list);
137
15.4M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
15.4M
}
unicodeobject.c:ucs1lib_split_char
Line
Count
Source
106
1.07M
{
107
1.07M
    Py_ssize_t i, j, count=0;
108
1.07M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
1.07M
    PyObject *sub;
110
111
1.07M
    if (list == NULL)
112
0
        return NULL;
113
114
1.07M
    i = j = 0;
115
16.0M
    while ((j < str_len) && (maxcount-- > 0)) {
116
70.1M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
69.9M
            if (str[j] == ch) {
119
14.7M
                SPLIT_ADD(str, i, j);
120
14.7M
                i = j = j + 1;
121
14.7M
                break;
122
14.7M
            }
123
69.9M
        }
124
14.9M
    }
125
1.07M
#if !STRINGLIB_MUTABLE
126
1.07M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
141k
        Py_INCREF(str_obj);
129
141k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
141k
        count++;
131
141k
    } else
132
936k
#endif
133
936k
    if (i <= str_len) {
134
1.87M
        SPLIT_ADD(str, i, str_len);
135
1.87M
    }
136
1.07M
    FIX_PREALLOC_SIZE(list);
137
1.07M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
1.07M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
91.8k
{
107
91.8k
    Py_ssize_t i, j, count=0;
108
91.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
91.8k
    PyObject *sub;
110
111
91.8k
    if (list == NULL)
112
0
        return NULL;
113
114
91.8k
    i = j = 0;
115
7.42M
    while ((j < str_len) && (maxcount-- > 0)) {
116
59.6M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
59.6M
            if (str[j] == ch) {
119
7.27M
                SPLIT_ADD(str, i, j);
120
7.27M
                i = j = j + 1;
121
7.27M
                break;
122
7.27M
            }
123
59.6M
        }
124
7.33M
    }
125
91.8k
#if !STRINGLIB_MUTABLE
126
91.8k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
7.08k
        Py_INCREF(str_obj);
129
7.08k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
7.08k
        count++;
131
7.08k
    } else
132
84.7k
#endif
133
84.7k
    if (i <= str_len) {
134
169k
        SPLIT_ADD(str, i, str_len);
135
169k
    }
136
91.8k
    FIX_PREALLOC_SIZE(list);
137
91.8k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
91.8k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
16.1k
{
107
16.1k
    Py_ssize_t i, j, count=0;
108
16.1k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
16.1k
    PyObject *sub;
110
111
16.1k
    if (list == NULL)
112
0
        return NULL;
113
114
16.1k
    i = j = 0;
115
723k
    while ((j < str_len) && (maxcount-- > 0)) {
116
24.7M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
24.7M
            if (str[j] == ch) {
119
694k
                SPLIT_ADD(str, i, j);
120
694k
                i = j = j + 1;
121
694k
                break;
122
694k
            }
123
24.7M
        }
124
706k
    }
125
16.1k
#if !STRINGLIB_MUTABLE
126
16.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
372
        Py_INCREF(str_obj);
129
372
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
372
        count++;
131
372
    } else
132
15.7k
#endif
133
15.7k
    if (i <= str_len) {
134
31.5k
        SPLIT_ADD(str, i, str_len);
135
31.5k
    }
136
16.1k
    FIX_PREALLOC_SIZE(list);
137
16.1k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
    return NULL;
142
16.1k
}
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
20.1M
{
150
20.1M
    Py_ssize_t i, j, pos, count=0;
151
20.1M
    PyObject *list, *sub;
152
153
20.1M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
20.1M
    else if (sep_len == 1)
158
19.8M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
220k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
220k
    if (list == NULL)
162
0
        return NULL;
163
164
220k
    i = j = 0;
165
398k
    while (maxcount-- > 0) {
166
220k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
220k
        if (pos < 0)
168
42.1k
            break;
169
178k
        j = i + pos;
170
356k
        SPLIT_ADD(str, i, j);
171
356k
        i = j + sep_len;
172
356k
    }
173
#if !STRINGLIB_MUTABLE
174
220k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
42.1k
        Py_INCREF(str_obj);
177
42.1k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
42.1k
        count++;
179
42.1k
    } else
180
178k
#endif
181
178k
    {
182
356k
        SPLIT_ADD(str, i, str_len);
183
356k
    }
184
220k
    FIX_PREALLOC_SIZE(list);
185
220k
    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.23M
{
150
3.23M
    Py_ssize_t i, j, pos, count=0;
151
3.23M
    PyObject *list, *sub;
152
153
3.23M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
3.23M
    else if (sep_len == 1)
158
3.23M
        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
15.5M
{
150
15.5M
    Py_ssize_t i, j, pos, count=0;
151
15.5M
    PyObject *list, *sub;
152
153
15.5M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
15.5M
    else if (sep_len == 1)
158
15.4M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
85.4k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
85.4k
    if (list == NULL)
162
0
        return NULL;
163
164
85.4k
    i = j = 0;
165
142k
    while (maxcount-- > 0) {
166
85.4k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
85.4k
        if (pos < 0)
168
27.9k
            break;
169
57.5k
        j = i + pos;
170
115k
        SPLIT_ADD(str, i, j);
171
115k
        i = j + sep_len;
172
115k
    }
173
85.4k
#if !STRINGLIB_MUTABLE
174
85.4k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
27.9k
        Py_INCREF(str_obj);
177
27.9k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
27.9k
        count++;
179
27.9k
    } else
180
57.5k
#endif
181
57.5k
    {
182
115k
        SPLIT_ADD(str, i, str_len);
183
115k
    }
184
85.4k
    FIX_PREALLOC_SIZE(list);
185
85.4k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
85.4k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.09M
{
150
1.09M
    Py_ssize_t i, j, pos, count=0;
151
1.09M
    PyObject *list, *sub;
152
153
1.09M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.09M
    else if (sep_len == 1)
158
1.07M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
21.6k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
21.6k
    if (list == NULL)
162
0
        return NULL;
163
164
21.6k
    i = j = 0;
165
41.7k
    while (maxcount-- > 0) {
166
21.6k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
21.6k
        if (pos < 0)
168
1.50k
            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
21.6k
#if !STRINGLIB_MUTABLE
174
21.6k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
1.50k
        Py_INCREF(str_obj);
177
1.50k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
1.50k
        count++;
179
1.50k
    } else
180
20.1k
#endif
181
20.1k
    {
182
40.2k
        SPLIT_ADD(str, i, str_len);
183
40.2k
    }
184
21.6k
    FIX_PREALLOC_SIZE(list);
185
21.6k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
21.6k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
182k
{
150
182k
    Py_ssize_t i, j, pos, count=0;
151
182k
    PyObject *list, *sub;
152
153
182k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
182k
    else if (sep_len == 1)
158
91.8k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
91.1k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
91.1k
    if (list == NULL)
162
0
        return NULL;
163
164
91.1k
    i = j = 0;
165
172k
    while (maxcount-- > 0) {
166
91.1k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
91.1k
        if (pos < 0)
168
9.39k
            break;
169
81.7k
        j = i + pos;
170
163k
        SPLIT_ADD(str, i, j);
171
163k
        i = j + sep_len;
172
163k
    }
173
91.1k
#if !STRINGLIB_MUTABLE
174
91.1k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
9.39k
        Py_INCREF(str_obj);
177
9.39k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
9.39k
        count++;
179
9.39k
    } else
180
81.7k
#endif
181
81.7k
    {
182
163k
        SPLIT_ADD(str, i, str_len);
183
163k
    }
184
91.1k
    FIX_PREALLOC_SIZE(list);
185
91.1k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
91.1k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
38.4k
{
150
38.4k
    Py_ssize_t i, j, pos, count=0;
151
38.4k
    PyObject *list, *sub;
152
153
38.4k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
38.4k
    else if (sep_len == 1)
158
16.1k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
22.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
22.2k
    if (list == NULL)
162
0
        return NULL;
163
164
22.2k
    i = j = 0;
165
41.2k
    while (maxcount-- > 0) {
166
22.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
22.2k
        if (pos < 0)
168
3.33k
            break;
169
18.9k
        j = i + pos;
170
37.8k
        SPLIT_ADD(str, i, j);
171
37.8k
        i = j + sep_len;
172
37.8k
    }
173
22.2k
#if !STRINGLIB_MUTABLE
174
22.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
3.33k
        Py_INCREF(str_obj);
177
3.33k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
3.33k
        count++;
179
3.33k
    } else
180
18.9k
#endif
181
18.9k
    {
182
37.8k
        SPLIT_ADD(str, i, str_len);
183
37.8k
    }
184
22.2k
    FIX_PREALLOC_SIZE(list);
185
22.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
    return NULL;
190
22.2k
}
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.8k
{
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.8k
    Py_ssize_t i;
349
13.8k
    Py_ssize_t j;
350
13.8k
    PyObject *list = PyList_New(0);
351
13.8k
    PyObject *sub;
352
353
13.8k
    if (list == NULL)
354
0
        return NULL;
355
356
31.1M
    for (i = j = 0; i < str_len; ) {
357
31.1M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
246M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
215M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
31.1M
        eol = i;
365
31.1M
        if (i < str_len) {
366
31.1M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
60.8k
                i += 2;
368
31.1M
            else
369
31.1M
                i++;
370
31.1M
            if (keepends)
371
0
                eol = i;
372
31.1M
        }
373
#if !STRINGLIB_MUTABLE
374
31.1M
        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.41k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
5.41k
            break;
379
5.41k
        }
380
31.1M
#endif
381
62.3M
        SPLIT_APPEND(str, j, eol);
382
31.1M
        j = i;
383
31.1M
    }
384
13.8k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
13.8k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
2.73k
{
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.73k
    Py_ssize_t i;
349
2.73k
    Py_ssize_t j;
350
2.73k
    PyObject *list = PyList_New(0);
351
2.73k
    PyObject *sub;
352
353
2.73k
    if (list == NULL)
354
0
        return NULL;
355
356
7.59M
    for (i = j = 0; i < str_len; ) {
357
7.59M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
44.7M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
37.1M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
7.59M
        eol = i;
365
7.59M
        if (i < str_len) {
366
7.59M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
929
                i += 2;
368
7.59M
            else
369
7.59M
                i++;
370
7.59M
            if (keepends)
371
0
                eol = i;
372
7.59M
        }
373
7.59M
#if !STRINGLIB_MUTABLE
374
7.59M
        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
970
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
970
            break;
379
970
        }
380
7.59M
#endif
381
15.1M
        SPLIT_APPEND(str, j, eol);
382
7.59M
        j = i;
383
7.59M
    }
384
2.73k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
2.73k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
843
{
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
843
    Py_ssize_t i;
349
843
    Py_ssize_t j;
350
843
    PyObject *list = PyList_New(0);
351
843
    PyObject *sub;
352
353
843
    if (list == NULL)
354
0
        return NULL;
355
356
2.10M
    for (i = j = 0; i < str_len; ) {
357
2.10M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
9.75M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
7.65M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
2.10M
        eol = i;
365
2.10M
        if (i < str_len) {
366
2.10M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
1.51k
                i += 2;
368
2.10M
            else
369
2.10M
                i++;
370
2.10M
            if (keepends)
371
0
                eol = i;
372
2.10M
        }
373
2.10M
#if !STRINGLIB_MUTABLE
374
2.10M
        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
217
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
217
            break;
379
217
        }
380
2.10M
#endif
381
4.20M
        SPLIT_APPEND(str, j, eol);
382
2.10M
        j = i;
383
2.10M
    }
384
843
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
843
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
7.26k
{
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.26k
    Py_ssize_t i;
349
7.26k
    Py_ssize_t j;
350
7.26k
    PyObject *list = PyList_New(0);
351
7.26k
    PyObject *sub;
352
353
7.26k
    if (list == NULL)
354
0
        return NULL;
355
356
11.5M
    for (i = j = 0; i < str_len; ) {
357
11.5M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
87.1M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
75.6M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
11.5M
        eol = i;
365
11.5M
        if (i < str_len) {
366
11.5M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
13.1k
                i += 2;
368
11.4M
            else
369
11.4M
                i++;
370
11.5M
            if (keepends)
371
0
                eol = i;
372
11.5M
        }
373
11.5M
#if !STRINGLIB_MUTABLE
374
11.5M
        if (j == 0 && eol == str_len && STRINGLIB_CHECK_EXACT(str_obj)) {
375
            /* No linebreak in str_obj, so just use it as list[0] */
376
3.03k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
3.03k
            break;
379
3.03k
        }
380
11.5M
#endif
381
23.0M
        SPLIT_APPEND(str, j, eol);
382
11.5M
        j = i;
383
11.5M
    }
384
7.26k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
7.26k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
3.06k
{
340
    /* This does not use the preallocated list because splitlines is
341
       usually run with hundreds of newlines.  The overhead of
342
       switching between PyList_SET_ITEM and append causes about a
343
       2-3% slowdown for that common case.  A smarter implementation
344
       could move the if check out, so the SET_ITEMs are done first
345
       and the appends only done when the prealloc buffer is full.
346
       That's too much work for little gain.*/
347
348
3.06k
    Py_ssize_t i;
349
3.06k
    Py_ssize_t j;
350
3.06k
    PyObject *list = PyList_New(0);
351
3.06k
    PyObject *sub;
352
353
3.06k
    if (list == NULL)
354
0
        return NULL;
355
356
9.96M
    for (i = j = 0; i < str_len; ) {
357
9.96M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
104M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
94.9M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
9.96M
        eol = i;
365
9.96M
        if (i < str_len) {
366
9.96M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
45.3k
                i += 2;
368
9.91M
            else
369
9.91M
                i++;
370
9.96M
            if (keepends)
371
0
                eol = i;
372
9.96M
        }
373
9.96M
#if !STRINGLIB_MUTABLE
374
9.96M
        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.19k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.19k
            break;
379
1.19k
        }
380
9.96M
#endif
381
19.9M
        SPLIT_APPEND(str, j, eol);
382
9.96M
        j = i;
383
9.96M
    }
384
3.06k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
    return NULL;
389
3.06k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390