Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/partition.h @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | b36cb4602e21 |
| children |
| 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*) |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
11 stringlib_partition(PyObject* str_obj, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
12 const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
13 PyObject* sep_obj, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
14 const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
|
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"); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
21 return NULL; |
|
38383
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) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
26 return NULL; |
|
38383
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
28 pos = fastsearch(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
|
38383
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) { |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
31 #if STRINGLIB_MUTABLE |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
32 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
33 PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
34 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
35 #else |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
36 Py_INCREF(str_obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
37 PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
38 Py_INCREF(STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
39 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
40 Py_INCREF(STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
41 PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY); |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
42 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
43 return out; |
|
38383
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
44 } |
|
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 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
47 Py_INCREF(sep_obj); |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
48 PyTuple_SET_ITEM(out, 1, sep_obj); |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
49 pos += sep_len; |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
50 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
|
51 |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
52 if (PyErr_Occurred()) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
53 Py_DECREF(out); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
54 return NULL; |
|
38383
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
55 } |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
56 |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
57 return out; |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
58 } |
|
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
59 |
|
38440
5b0753b9d16a
needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents:
38421
diff
changeset
|
60 Py_LOCAL_INLINE(PyObject*) |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
61 stringlib_rpartition(PyObject* str_obj, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
62 const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
63 PyObject* sep_obj, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
64 const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
|
38390
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
65 { |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
66 PyObject* out; |
|
58090
ddf61cd775e0
Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
67 Py_ssize_t pos; |
|
38390
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
68 |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
69 if (sep_len == 0) { |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
70 PyErr_SetString(PyExc_ValueError, "empty separator"); |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
71 return NULL; |
|
38390
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
72 } |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
73 |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
74 out = PyTuple_New(3); |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
75 if (!out) |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
76 return NULL; |
|
38390
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
77 |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
78 pos = fastsearch(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
|
38390
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) { |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
81 #if STRINGLIB_MUTABLE |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
82 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
83 PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
84 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
85 #else |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
86 Py_INCREF(STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
87 PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
88 Py_INCREF(STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
89 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
90 Py_INCREF(str_obj); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
91 PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
58090
diff
changeset
|
92 #endif |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
93 return out; |
|
38390
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
94 } |
|
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 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
97 Py_INCREF(sep_obj); |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
98 PyTuple_SET_ITEM(out, 1, sep_obj); |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
99 pos += sep_len; |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
100 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
|
101 |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
102 if (PyErr_Occurred()) { |
|
61465
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
103 Py_DECREF(out); |
|
e38335d4df91
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
39734
diff
changeset
|
104 return NULL; |
|
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 return out; |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
108 } |
|
76807902a2f5
needforspeed: added rpartition implementation
Fredrik Lundh <fredrik@pythonware.com>
parents:
38389
diff
changeset
|
109 |
|
38383
05744917b7c3
needforspeed: stringlib refactoring (in progress)
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
110 #endif |
