annotate Objects/stringlib/partition.h @ 39042:c02fa187e0f4 legacy-trunk

Part of SF patch #1484695. This removes dead code. The chksum was already verified in .frombuf() on the lines above. If there was a problem an exception is raised, so there was no way this condition could have been true.
author Neal Norwitz <nnorwitz@gmail.com>
date Mon, 10 Jul 2006 00:23:17 +0000
parents 5b0753b9d16a
children cfb77fff0240
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38383
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1 /* stringlib: partition implementation */
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
2
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
3 #ifndef STRINGLIB_PARTITION_H
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
4 #define STRINGLIB_PARTITION_H
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
5
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
6 #ifndef STRINGLIB_FASTSEARCH_H
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
7 #error must include "stringlib/fastsearch.h" before including this module
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
8 #endif
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
9
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38421
diff changeset
10 Py_LOCAL_INLINE(PyObject*)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
11 stringlib_partition(
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
12 PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
13 PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
14 )
38383
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
15 {
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
16 PyObject* out;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
17 Py_ssize_t pos;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
18
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
19 if (sep_len == 0) {
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
20 PyErr_SetString(PyExc_ValueError, "empty separator");
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
21 return NULL;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
22 }
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
23
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
24 out = PyTuple_New(3);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
25 if (!out)
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
26 return NULL;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
27
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
28 pos = fastsearch(str, str_len, sep, sep_len, FAST_SEARCH);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
29
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
30 if (pos < 0) {
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
31 Py_INCREF(str_obj);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
32 PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
33 Py_INCREF(STRINGLIB_EMPTY);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
34 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
35 Py_INCREF(STRINGLIB_EMPTY);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
36 PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
37 return out;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
38 }
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
39
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
40 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
41 Py_INCREF(sep_obj);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
42 PyTuple_SET_ITEM(out, 1, sep_obj);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
43 pos += sep_len;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
44 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
45
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
46 if (PyErr_Occurred()) {
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
47 Py_DECREF(out);
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
48 return NULL;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
49 }
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
50
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
51 return out;
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
52 }
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
53
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38421
diff changeset
54 Py_LOCAL_INLINE(PyObject*)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
55 stringlib_rpartition(
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
56 PyObject* str_obj, const STRINGLIB_CHAR* str, Py_ssize_t str_len,
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
57 PyObject* sep_obj, const STRINGLIB_CHAR* sep, Py_ssize_t sep_len
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents: 38390
diff changeset
58 )
38390
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
59 {
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
60 PyObject* out;
38421
4209a3d295e3 Fix Coverity warnings.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38400
diff changeset
61 Py_ssize_t pos, j;
38390
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
62
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
63 if (sep_len == 0) {
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
64 PyErr_SetString(PyExc_ValueError, "empty separator");
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
65 return NULL;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
66 }
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
67
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
68 out = PyTuple_New(3);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
69 if (!out)
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
70 return NULL;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
71
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
72 /* XXX - create reversefastsearch helper! */
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
73 pos = -1;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
74 for (j = str_len - sep_len; j >= 0; --j)
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
75 if (STRINGLIB_CMP(str+j, sep, sep_len) == 0) {
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
76 pos = j;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
77 break;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
78 }
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
79
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
80 if (pos < 0) {
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
81 Py_INCREF(str_obj);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
82 PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
83 Py_INCREF(STRINGLIB_EMPTY);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
84 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
85 Py_INCREF(STRINGLIB_EMPTY);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
86 PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
87 return out;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
88 }
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
89
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
90 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos));
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
91 Py_INCREF(sep_obj);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
92 PyTuple_SET_ITEM(out, 1, sep_obj);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
93 pos += sep_len;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
94 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos));
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
95
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
96 if (PyErr_Occurred()) {
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
97 Py_DECREF(out);
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
98 return NULL;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
99 }
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
100
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
101 return out;
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
102 }
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
103
38383
05744917b7c3 needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
104 #endif
38390
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
105
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
106 /*
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
107 Local variables:
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
108 c-basic-offset: 4
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
109 indent-tabs-mode: nil
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
110 End:
76807902a2f5 needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents: 38389
diff changeset
111 */