Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/count.h @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 304bea8731d2 |
| children | 66f1d4a4c799 |
| 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, |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
12 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len) |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
13 { |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
14 Py_ssize_t count; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
15 |
|
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
|
16 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
|
17 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
|
18 if (sub_len == 0) |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
19 return str_len + 1; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
20 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
21 count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT); |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
22 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
23 if (count < 0) |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
24 count = 0; /* no match */ |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
25 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
26 return count; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
27 } |
|
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 #endif |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
30 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
31 /* |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
32 Local variables: |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
33 c-basic-offset: 4 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
34 indent-tabs-mode: nil |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
35 End: |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
36 */ |
