Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/count.h @ 58765:2ba7677bfa95 legacy-trunk
testCopysign was defined twice in test_math; combine the definitions
| author | Mark Dickinson <dickinsm@gmail.com> |
|---|---|
| date | Sat, 06 Feb 2010 23:11:25 +0000 |
| parents | 66f1d4a4c799 |
| children |
| rev | line source |
|---|---|
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
1 /* stringlib: count implementation */ |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
2 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
3 #ifndef STRINGLIB_COUNT_H |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
4 #define STRINGLIB_COUNT_H |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
5 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
6 #ifndef STRINGLIB_FASTSEARCH_H |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
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:
diff
changeset
|
8 #endif |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
9 |
|
38440
5b0753b9d16a
needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents:
38400
diff
changeset
|
10 Py_LOCAL_INLINE(Py_ssize_t) |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
11 stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
49308
diff
changeset
|
12 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
|
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
49308
diff
changeset
|
13 Py_ssize_t maxcount) |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
14 { |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
15 Py_ssize_t count; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
16 |
|
49308
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38516
diff
changeset
|
17 if (str_len < 0) |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38516
diff
changeset
|
18 return 0; /* start > len(str) */ |
|
304bea8731d2
#3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38516
diff
changeset
|
19 if (sub_len == 0) |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
49308
diff
changeset
|
20 return (str_len < maxcount) ? str_len + 1 : maxcount; |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
21 |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
49308
diff
changeset
|
22 count = fastsearch(str, str_len, sub, sub_len, maxcount, FAST_COUNT); |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
23 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
24 if (count < 0) |
|
58288
66f1d4a4c799
Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents:
49308
diff
changeset
|
25 return 0; /* no match */ |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
26 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 return count; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
28 } |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
29 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
30 #endif |
