Coverage Report

Created: 2025-08-29 06:15

/src/cpython/Objects/stringlib/split.h
Line
Count
Source (jump to first uncovered line)
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
88.2M
#define MAX_PREALLOC 12
15
16
/* 5 splits gives 6 elements */
17
#define PREALLOC_SIZE(maxsplit) \
18
19.1M
    (maxsplit >= MAX_PREALLOC ? MAX_PREALLOC : maxsplit+1)
19
20
#define SPLIT_APPEND(data, left, right)         \
21
31.3M
    sub = STRINGLIB_NEW((data) + (left),        \
22
31.3M
                        (right) - (left));      \
23
31.3M
    if (sub == NULL)                            \
24
31.3M
        goto onError;                           \
25
31.3M
    if (PyList_Append(list, sub)) {             \
26
0
        Py_DECREF(sub);                         \
27
0
        goto onError;                           \
28
0
    }                                           \
29
31.3M
    else                                        \
30
31.3M
        Py_DECREF(sub);
31
32
46.9M
#define SPLIT_ADD(data, left, right) {          \
33
46.9M
    sub = STRINGLIB_NEW((data) + (left),        \
34
46.9M
                        (right) - (left));      \
35
46.9M
    if (sub == NULL)                            \
36
46.9M
        goto onError;                           \
37
46.9M
    if (count < MAX_PREALLOC) {                 \
38
27.4M
        PyList_SET_ITEM(list, count, sub);      \
39
27.4M
    } else {                                    \
40
19.4M
        if (PyList_Append(list, sub)) {         \
41
0
            Py_DECREF(sub);                     \
42
0
            goto onError;                       \
43
0
        }                                       \
44
19.4M
        else                                    \
45
19.4M
            Py_DECREF(sub);                     \
46
19.4M
    }                                           \
47
46.9M
    count++; }
48
49
50
/* Always force the list to the expected size. */
51
19.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
146k
{
58
146k
    Py_ssize_t i, j, count=0;
59
146k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
146k
    PyObject *sub;
61
62
146k
    if (list == NULL)
63
0
        return NULL;
64
65
146k
    i = j = 0;
66
1.84M
    while (maxcount-- > 0) {
67
3.58M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
1.76M
            i++;
69
1.81M
        if (i == str_len) break;
70
1.72M
        j = i; i++;
71
106M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
104M
            i++;
73
#if !STRINGLIB_MUTABLE
74
1.72M
        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.7k
            Py_INCREF(str_obj);
77
33.7k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
33.7k
            count++;
79
33.7k
            break;
80
33.7k
        }
81
1.69M
#endif
82
5.08M
        SPLIT_ADD(str, j, i);
83
5.08M
    }
84
85
146k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
55.2k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
29.8k
            i++;
90
25.4k
        if (i != str_len)
91
25.4k
            SPLIT_ADD(str, i, str_len);
92
25.4k
    }
93
146k
    FIX_PREALLOC_SIZE(list);
94
146k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
146k
}
Unexecuted instantiation: bytesobject.c:stringlib_split_whitespace
unicodeobject.c:asciilib_split_whitespace
Line
Count
Source
57
65.8k
{
58
65.8k
    Py_ssize_t i, j, count=0;
59
65.8k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
65.8k
    PyObject *sub;
61
62
65.8k
    if (list == NULL)
63
0
        return NULL;
64
65
65.8k
    i = j = 0;
66
566k
    while (maxcount-- > 0) {
67
1.00M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
458k
            i++;
69
549k
        if (i == str_len) break;
70
515k
        j = i; i++;
71
37.3M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
36.8M
            i++;
73
515k
#if !STRINGLIB_MUTABLE
74
515k
        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
15.1k
            Py_INCREF(str_obj);
77
15.1k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
15.1k
            count++;
79
15.1k
            break;
80
15.1k
        }
81
500k
#endif
82
1.50M
        SPLIT_ADD(str, j, i);
83
1.50M
    }
84
85
65.8k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
27.6k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
14.3k
            i++;
90
13.3k
        if (i != str_len)
91
13.3k
            SPLIT_ADD(str, i, str_len);
92
13.3k
    }
93
65.8k
    FIX_PREALLOC_SIZE(list);
94
65.8k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
65.8k
}
unicodeobject.c:ucs1lib_split_whitespace
Line
Count
Source
57
25.2k
{
58
25.2k
    Py_ssize_t i, j, count=0;
59
25.2k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
25.2k
    PyObject *sub;
61
62
25.2k
    if (list == NULL)
63
0
        return NULL;
64
65
25.2k
    i = j = 0;
66
514k
    while (maxcount-- > 0) {
67
978k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
476k
            i++;
69
502k
        if (i == str_len) break;
70
492k
        j = i; i++;
71
21.5M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
21.0M
            i++;
73
492k
#if !STRINGLIB_MUTABLE
74
492k
        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.65k
            Py_INCREF(str_obj);
77
3.65k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.65k
            count++;
79
3.65k
            break;
80
3.65k
        }
81
489k
#endif
82
1.46M
        SPLIT_ADD(str, j, i);
83
1.46M
    }
84
85
25.2k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
26.0k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
14.7k
            i++;
90
11.3k
        if (i != str_len)
91
11.3k
            SPLIT_ADD(str, i, str_len);
92
11.3k
    }
93
25.2k
    FIX_PREALLOC_SIZE(list);
94
25.2k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
25.2k
}
unicodeobject.c:ucs2lib_split_whitespace
Line
Count
Source
57
44.5k
{
58
44.5k
    Py_ssize_t i, j, count=0;
59
44.5k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
44.5k
    PyObject *sub;
61
62
44.5k
    if (list == NULL)
63
0
        return NULL;
64
65
44.5k
    i = j = 0;
66
646k
    while (maxcount-- > 0) {
67
1.37M
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
729k
            i++;
69
645k
        if (i == str_len) break;
70
613k
        j = i; i++;
71
36.7M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
36.1M
            i++;
73
613k
#if !STRINGLIB_MUTABLE
74
613k
        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
11.8k
            Py_INCREF(str_obj);
77
11.8k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
11.8k
            count++;
79
11.8k
            break;
80
11.8k
        }
81
602k
#endif
82
1.80M
        SPLIT_ADD(str, j, i);
83
1.80M
    }
84
85
44.5k
    if (i < str_len) {
86
        /* Only occurs when maxcount was reached */
87
        /* Skip any remaining whitespace and copy to end of string */
88
1.53k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
89
768
            i++;
90
768
        if (i != str_len)
91
768
            SPLIT_ADD(str, i, str_len);
92
768
    }
93
44.5k
    FIX_PREALLOC_SIZE(list);
94
44.5k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
44.5k
}
unicodeobject.c:ucs4lib_split_whitespace
Line
Count
Source
57
11.2k
{
58
11.2k
    Py_ssize_t i, j, count=0;
59
11.2k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
60
11.2k
    PyObject *sub;
61
62
11.2k
    if (list == NULL)
63
0
        return NULL;
64
65
11.2k
    i = j = 0;
66
113k
    while (maxcount-- > 0) {
67
218k
        while (i < str_len && STRINGLIB_ISSPACE(str[i]))
68
105k
            i++;
69
112k
        if (i == str_len) break;
70
105k
        j = i; i++;
71
10.3M
        while (i < str_len && !STRINGLIB_ISSPACE(str[i]))
72
10.2M
            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
3.00k
            Py_INCREF(str_obj);
77
3.00k
            PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
78
3.00k
            count++;
79
3.00k
            break;
80
3.00k
        }
81
102k
#endif
82
307k
        SPLIT_ADD(str, j, i);
83
307k
    }
84
85
11.2k
    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.2k
    FIX_PREALLOC_SIZE(list);
94
11.2k
    return list;
95
96
0
  onError:
97
0
    Py_DECREF(list);
98
0
    return NULL;
99
11.2k
}
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
18.7M
{
107
18.7M
    Py_ssize_t i, j, count=0;
108
18.7M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
18.7M
    PyObject *sub;
110
111
18.7M
    if (list == NULL)
112
0
        return NULL;
113
114
18.7M
    i = j = 0;
115
67.4M
    while ((j < str_len) && (maxcount-- > 0)) {
116
350M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
333M
            if (str[j] == ch) {
119
32.0M
                SPLIT_ADD(str, i, j);
120
32.0M
                i = j = j + 1;
121
32.0M
                break;
122
32.0M
            }
123
333M
        }
124
48.6M
    }
125
#if !STRINGLIB_MUTABLE
126
18.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.87M
        Py_INCREF(str_obj);
129
5.87M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
5.87M
        count++;
131
5.87M
    } else
132
12.9M
#endif
133
12.9M
    if (i <= str_len) {
134
25.8M
        SPLIT_ADD(str, i, str_len);
135
25.8M
    }
136
18.7M
    FIX_PREALLOC_SIZE(list);
137
18.7M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
0
}
bytesobject.c:stringlib_split_char
Line
Count
Source
106
2.89M
{
107
2.89M
    Py_ssize_t i, j, count=0;
108
2.89M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
2.89M
    PyObject *sub;
110
111
2.89M
    if (list == NULL)
112
0
        return NULL;
113
114
2.89M
    i = j = 0;
115
10.1M
    while ((j < str_len) && (maxcount-- > 0)) {
116
55.0M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
52.6M
            if (str[j] == ch) {
119
4.84M
                SPLIT_ADD(str, i, j);
120
4.84M
                i = j = j + 1;
121
4.84M
                break;
122
4.84M
            }
123
52.6M
        }
124
7.22M
    }
125
2.89M
#if !STRINGLIB_MUTABLE
126
2.89M
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
2.29M
        Py_INCREF(str_obj);
129
2.29M
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
2.29M
        count++;
131
2.29M
    } else
132
603k
#endif
133
603k
    if (i <= str_len) {
134
1.20M
        SPLIT_ADD(str, i, str_len);
135
1.20M
    }
136
2.89M
    FIX_PREALLOC_SIZE(list);
137
2.89M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
2.89M
}
unicodeobject.c:asciilib_split_char
Line
Count
Source
106
14.7M
{
107
14.7M
    Py_ssize_t i, j, count=0;
108
14.7M
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
14.7M
    PyObject *sub;
110
111
14.7M
    if (list == NULL)
112
0
        return NULL;
113
114
14.7M
    i = j = 0;
115
45.5M
    while ((j < str_len) && (maxcount-- > 0)) {
116
184M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
170M
            if (str[j] == ch) {
119
16.8M
                SPLIT_ADD(str, i, j);
120
16.8M
                i = j = j + 1;
121
16.8M
                break;
122
16.8M
            }
123
170M
        }
124
30.8M
    }
125
14.7M
#if !STRINGLIB_MUTABLE
126
14.7M
    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
11.2M
#endif
133
11.2M
    if (i <= str_len) {
134
22.5M
        SPLIT_ADD(str, i, str_len);
135
22.5M
    }
136
14.7M
    FIX_PREALLOC_SIZE(list);
137
14.7M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
14.7M
}
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
8.26M
    while ((j < str_len) && (maxcount-- > 0)) {
116
44.3M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
44.1M
            if (str[j] == ch) {
119
7.03M
                SPLIT_ADD(str, i, j);
120
7.03M
                i = j = j + 1;
121
7.03M
                break;
122
7.03M
            }
123
44.1M
        }
124
7.19M
    }
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
128k
        Py_INCREF(str_obj);
129
128k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
128k
        count++;
131
128k
    } else
132
949k
#endif
133
949k
    if (i <= str_len) {
134
1.89M
        SPLIT_ADD(str, i, str_len);
135
1.89M
    }
136
1.07M
    FIX_PREALLOC_SIZE(list);
137
1.07M
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
1.07M
}
unicodeobject.c:ucs2lib_split_char
Line
Count
Source
106
84.0k
{
107
84.0k
    Py_ssize_t i, j, count=0;
108
84.0k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
84.0k
    PyObject *sub;
110
111
84.0k
    if (list == NULL)
112
0
        return NULL;
113
114
84.0k
    i = j = 0;
115
3.09M
    while ((j < str_len) && (maxcount-- > 0)) {
116
43.8M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
43.7M
            if (str[j] == ch) {
119
2.96M
                SPLIT_ADD(str, i, j);
120
2.96M
                i = j = j + 1;
121
2.96M
                break;
122
2.96M
            }
123
43.7M
        }
124
3.01M
    }
125
84.0k
#if !STRINGLIB_MUTABLE
126
84.0k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
7.02k
        Py_INCREF(str_obj);
129
7.02k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
7.02k
        count++;
131
7.02k
    } else
132
77.0k
#endif
133
77.0k
    if (i <= str_len) {
134
154k
        SPLIT_ADD(str, i, str_len);
135
154k
    }
136
84.0k
    FIX_PREALLOC_SIZE(list);
137
84.0k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
84.0k
}
unicodeobject.c:ucs4lib_split_char
Line
Count
Source
106
15.6k
{
107
15.6k
    Py_ssize_t i, j, count=0;
108
15.6k
    PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
109
15.6k
    PyObject *sub;
110
111
15.6k
    if (list == NULL)
112
0
        return NULL;
113
114
15.6k
    i = j = 0;
115
393k
    while ((j < str_len) && (maxcount-- > 0)) {
116
22.8M
        for(; j < str_len; j++) {
117
            /* I found that using memchr makes no difference */
118
22.7M
            if (str[j] == ch) {
119
365k
                SPLIT_ADD(str, i, j);
120
365k
                i = j = j + 1;
121
365k
                break;
122
365k
            }
123
22.7M
        }
124
377k
    }
125
15.6k
#if !STRINGLIB_MUTABLE
126
15.6k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
127
        /* ch not in str_obj, so just use str_obj as list[0] */
128
391
        Py_INCREF(str_obj);
129
391
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
130
391
        count++;
131
391
    } else
132
15.2k
#endif
133
15.2k
    if (i <= str_len) {
134
30.4k
        SPLIT_ADD(str, i, str_len);
135
30.4k
    }
136
15.6k
    FIX_PREALLOC_SIZE(list);
137
15.6k
    return list;
138
139
0
  onError:
140
0
    Py_DECREF(list);
141
0
    return NULL;
142
15.6k
}
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
18.9M
{
150
18.9M
    Py_ssize_t i, j, pos, count=0;
151
18.9M
    PyObject *list, *sub;
152
153
18.9M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
18.9M
    else if (sep_len == 1)
158
18.7M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
173k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
173k
    if (list == NULL)
162
0
        return NULL;
163
164
173k
    i = j = 0;
165
313k
    while (maxcount-- > 0) {
166
173k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
173k
        if (pos < 0)
168
33.7k
            break;
169
140k
        j = i + pos;
170
280k
        SPLIT_ADD(str, i, j);
171
280k
        i = j + sep_len;
172
280k
    }
173
#if !STRINGLIB_MUTABLE
174
173k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
33.7k
        Py_INCREF(str_obj);
177
33.7k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
33.7k
        count++;
179
33.7k
    } else
180
140k
#endif
181
140k
    {
182
280k
        SPLIT_ADD(str, i, str_len);
183
280k
    }
184
173k
    FIX_PREALLOC_SIZE(list);
185
173k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
0
    return NULL;
190
0
}
bytesobject.c:stringlib_split
Line
Count
Source
149
2.89M
{
150
2.89M
    Py_ssize_t i, j, pos, count=0;
151
2.89M
    PyObject *list, *sub;
152
153
2.89M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
2.89M
    else if (sep_len == 1)
158
2.89M
        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
0
    return NULL;
190
0
}
unicodeobject.c:asciilib_split
Line
Count
Source
149
14.7M
{
150
14.7M
    Py_ssize_t i, j, pos, count=0;
151
14.7M
    PyObject *list, *sub;
152
153
14.7M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
14.7M
    else if (sep_len == 1)
158
14.7M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
66.2k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
66.2k
    if (list == NULL)
162
0
        return NULL;
163
164
66.2k
    i = j = 0;
165
108k
    while (maxcount-- > 0) {
166
66.2k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
66.2k
        if (pos < 0)
168
23.6k
            break;
169
42.6k
        j = i + pos;
170
85.2k
        SPLIT_ADD(str, i, j);
171
85.2k
        i = j + sep_len;
172
85.2k
    }
173
66.2k
#if !STRINGLIB_MUTABLE
174
66.2k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
23.6k
        Py_INCREF(str_obj);
177
23.6k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
23.6k
        count++;
179
23.6k
    } else
180
42.6k
#endif
181
42.6k
    {
182
85.2k
        SPLIT_ADD(str, i, str_len);
183
85.2k
    }
184
66.2k
    FIX_PREALLOC_SIZE(list);
185
66.2k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
0
    return NULL;
190
66.2k
}
unicodeobject.c:ucs1lib_split
Line
Count
Source
149
1.08M
{
150
1.08M
    Py_ssize_t i, j, pos, count=0;
151
1.08M
    PyObject *list, *sub;
152
153
1.08M
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
1.08M
    else if (sep_len == 1)
158
1.07M
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
11.6k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
11.6k
    if (list == NULL)
162
0
        return NULL;
163
164
11.6k
    i = j = 0;
165
22.5k
    while (maxcount-- > 0) {
166
11.6k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
11.6k
        if (pos < 0)
168
782
            break;
169
10.8k
        j = i + pos;
170
21.7k
        SPLIT_ADD(str, i, j);
171
21.7k
        i = j + sep_len;
172
21.7k
    }
173
11.6k
#if !STRINGLIB_MUTABLE
174
11.6k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
782
        Py_INCREF(str_obj);
177
782
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
782
        count++;
179
782
    } else
180
10.8k
#endif
181
10.8k
    {
182
21.7k
        SPLIT_ADD(str, i, str_len);
183
21.7k
    }
184
11.6k
    FIX_PREALLOC_SIZE(list);
185
11.6k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
0
    return NULL;
190
11.6k
}
unicodeobject.c:ucs2lib_split
Line
Count
Source
149
161k
{
150
161k
    Py_ssize_t i, j, pos, count=0;
151
161k
    PyObject *list, *sub;
152
153
161k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
161k
    else if (sep_len == 1)
158
84.0k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
77.4k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
77.4k
    if (list == NULL)
162
0
        return NULL;
163
164
77.4k
    i = j = 0;
165
147k
    while (maxcount-- > 0) {
166
77.4k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
77.4k
        if (pos < 0)
168
7.26k
            break;
169
70.1k
        j = i + pos;
170
140k
        SPLIT_ADD(str, i, j);
171
140k
        i = j + sep_len;
172
140k
    }
173
77.4k
#if !STRINGLIB_MUTABLE
174
77.4k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
7.26k
        Py_INCREF(str_obj);
177
7.26k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
7.26k
        count++;
179
7.26k
    } else
180
70.1k
#endif
181
70.1k
    {
182
140k
        SPLIT_ADD(str, i, str_len);
183
140k
    }
184
77.4k
    FIX_PREALLOC_SIZE(list);
185
77.4k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
0
    return NULL;
190
77.4k
}
unicodeobject.c:ucs4lib_split
Line
Count
Source
149
34.1k
{
150
34.1k
    Py_ssize_t i, j, pos, count=0;
151
34.1k
    PyObject *list, *sub;
152
153
34.1k
    if (sep_len == 0) {
154
0
        PyErr_SetString(PyExc_ValueError, "empty separator");
155
0
        return NULL;
156
0
    }
157
34.1k
    else if (sep_len == 1)
158
15.6k
        return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount);
159
160
18.5k
    list = PyList_New(PREALLOC_SIZE(maxcount));
161
18.5k
    if (list == NULL)
162
0
        return NULL;
163
164
18.5k
    i = j = 0;
165
34.8k
    while (maxcount-- > 0) {
166
18.5k
        pos = FASTSEARCH(str+i, str_len-i, sep, sep_len, -1, FAST_SEARCH);
167
18.5k
        if (pos < 0)
168
2.10k
            break;
169
16.3k
        j = i + pos;
170
32.7k
        SPLIT_ADD(str, i, j);
171
32.7k
        i = j + sep_len;
172
32.7k
    }
173
18.5k
#if !STRINGLIB_MUTABLE
174
18.5k
    if (count == 0 && STRINGLIB_CHECK_EXACT(str_obj)) {
175
        /* No match in str_obj, so just use it as list[0] */
176
2.10k
        Py_INCREF(str_obj);
177
2.10k
        PyList_SET_ITEM(list, 0, (PyObject *)str_obj);
178
2.10k
        count++;
179
2.10k
    } else
180
16.3k
#endif
181
16.3k
    {
182
32.7k
        SPLIT_ADD(str, i, str_len);
183
32.7k
    }
184
18.5k
    FIX_PREALLOC_SIZE(list);
185
18.5k
    return list;
186
187
0
  onError:
188
0
    Py_DECREF(list);
189
0
    return NULL;
190
18.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
0
    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
0
    return NULL;
333
0
}
Unexecuted instantiation: unicodeobject.c:ucs1lib_rsplit
Unexecuted instantiation: unicodeobject.c:ucs2lib_rsplit
Unexecuted instantiation: unicodeobject.c:ucs4lib_rsplit
Unexecuted instantiation: bytearrayobject.c:stringlib_rsplit
334
335
Py_LOCAL_INLINE(PyObject *)
336
STRINGLIB(splitlines)(PyObject* str_obj,
337
                     const STRINGLIB_CHAR* str, Py_ssize_t str_len,
338
                     int keepends)
339
14.0k
{
340
    /* This does not use the preallocated list because splitlines is
341
       usually run with hundreds of newlines.  The overhead of
342
       switching between PyList_SET_ITEM and append causes about a
343
       2-3% slowdown for that common case.  A smarter implementation
344
       could move the if check out, so the SET_ITEMs are done first
345
       and the appends only done when the prealloc buffer is full.
346
       That's too much work for little gain.*/
347
348
14.0k
    Py_ssize_t i;
349
14.0k
    Py_ssize_t j;
350
14.0k
    PyObject *list = PyList_New(0);
351
14.0k
    PyObject *sub;
352
353
14.0k
    if (list == NULL)
354
0
        return NULL;
355
356
31.3M
    for (i = j = 0; i < str_len; ) {
357
31.3M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
274M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
243M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
31.3M
        eol = i;
365
31.3M
        if (i < str_len) {
366
31.3M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
64.9k
                i += 2;
368
31.2M
            else
369
31.2M
                i++;
370
31.3M
            if (keepends)
371
0
                eol = i;
372
31.3M
        }
373
#if !STRINGLIB_MUTABLE
374
31.3M
        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.38k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
5.38k
            break;
379
5.38k
        }
380
31.3M
#endif
381
62.7M
        SPLIT_APPEND(str, j, eol);
382
31.3M
        j = i;
383
31.3M
    }
384
14.0k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
0
    return NULL;
389
14.0k
}
Unexecuted instantiation: bytesobject.c:stringlib_splitlines
unicodeobject.c:asciilib_splitlines
Line
Count
Source
339
2.74k
{
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.74k
    Py_ssize_t i;
349
2.74k
    Py_ssize_t j;
350
2.74k
    PyObject *list = PyList_New(0);
351
2.74k
    PyObject *sub;
352
353
2.74k
    if (list == NULL)
354
0
        return NULL;
355
356
8.96M
    for (i = j = 0; i < str_len; ) {
357
8.96M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
46.1M
        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
8.96M
        eol = i;
365
8.96M
        if (i < str_len) {
366
8.96M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
3.71k
                i += 2;
368
8.95M
            else
369
8.95M
                i++;
370
8.96M
            if (keepends)
371
0
                eol = i;
372
8.96M
        }
373
8.96M
#if !STRINGLIB_MUTABLE
374
8.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.02k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.02k
            break;
379
1.02k
        }
380
8.96M
#endif
381
17.9M
        SPLIT_APPEND(str, j, eol);
382
8.96M
        j = i;
383
8.96M
    }
384
2.74k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
0
    return NULL;
389
2.74k
}
unicodeobject.c:ucs1lib_splitlines
Line
Count
Source
339
837
{
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
837
    Py_ssize_t i;
349
837
    Py_ssize_t j;
350
837
    PyObject *list = PyList_New(0);
351
837
    PyObject *sub;
352
353
837
    if (list == NULL)
354
0
        return NULL;
355
356
1.04M
    for (i = j = 0; i < str_len; ) {
357
1.04M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
9.29M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
8.24M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
1.04M
        eol = i;
365
1.04M
        if (i < str_len) {
366
1.04M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
1.34k
                i += 2;
368
1.04M
            else
369
1.04M
                i++;
370
1.04M
            if (keepends)
371
0
                eol = i;
372
1.04M
        }
373
1.04M
#if !STRINGLIB_MUTABLE
374
1.04M
        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
208
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
208
            break;
379
208
        }
380
1.04M
#endif
381
2.09M
        SPLIT_APPEND(str, j, eol);
382
1.04M
        j = i;
383
1.04M
    }
384
837
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
0
    return NULL;
389
837
}
unicodeobject.c:ucs2lib_splitlines
Line
Count
Source
339
7.25k
{
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.25k
    Py_ssize_t i;
349
7.25k
    Py_ssize_t j;
350
7.25k
    PyObject *list = PyList_New(0);
351
7.25k
    PyObject *sub;
352
353
7.25k
    if (list == NULL)
354
0
        return NULL;
355
356
9.79M
    for (i = j = 0; i < str_len; ) {
357
9.78M
        Py_ssize_t eol;
358
359
        /* Find a line and append it */
360
100M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
90.5M
            i++;
362
363
        /* Skip the line break reading CRLF as one line break */
364
9.78M
        eol = i;
365
9.78M
        if (i < str_len) {
366
9.78M
            if (str[i] == '\r' && i + 1 < str_len && str[i+1] == '\n')
367
24.4k
                i += 2;
368
9.75M
            else
369
9.75M
                i++;
370
9.78M
            if (keepends)
371
0
                eol = i;
372
9.78M
        }
373
9.78M
#if !STRINGLIB_MUTABLE
374
9.78M
        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.99k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
2.99k
            break;
379
2.99k
        }
380
9.78M
#endif
381
19.5M
        SPLIT_APPEND(str, j, eol);
382
9.78M
        j = i;
383
9.78M
    }
384
7.25k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
0
    return NULL;
389
7.25k
}
unicodeobject.c:ucs4lib_splitlines
Line
Count
Source
339
3.18k
{
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.18k
    Py_ssize_t i;
349
3.18k
    Py_ssize_t j;
350
3.18k
    PyObject *list = PyList_New(0);
351
3.18k
    PyObject *sub;
352
353
3.18k
    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
118M
        while (i < str_len && !STRINGLIB_ISLINEBREAK(str[i]))
361
107M
            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
35.4k
                i += 2;
368
11.5M
            else
369
11.5M
                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
1.16k
            if (PyList_Append(list, str_obj))
377
0
                goto onError;
378
1.16k
            break;
379
1.16k
        }
380
11.5M
#endif
381
23.1M
        SPLIT_APPEND(str, j, eol);
382
11.5M
        j = i;
383
11.5M
    }
384
3.18k
    return list;
385
386
0
  onError:
387
0
    Py_DECREF(list);
388
0
    return NULL;
389
3.18k
}
Unexecuted instantiation: bytearrayobject.c:stringlib_splitlines
390