Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/count.h @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | 8beaa9a37387 |
| children |
| rev | line source |
|---|---|
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
1 /* stringlib: count implementation */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
2 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
3 #ifndef STRINGLIB_FASTSEARCH_H |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
4 #error must include "stringlib/fastsearch.h" before including this module |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
5 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
6 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
7 Py_LOCAL_INLINE(Py_ssize_t) |
| 72475 | 8 STRINGLIB(count)(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49310
diff
changeset
|
9 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49310
diff
changeset
|
10 Py_ssize_t maxcount) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
11 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
12 Py_ssize_t count; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
13 |
|
49310
6403f1edecc1
Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38669
diff
changeset
|
14 if (str_len < 0) |
|
6403f1edecc1
Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38669
diff
changeset
|
15 return 0; /* start > len(str) */ |
|
6403f1edecc1
Merged revisions 66631 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
38669
diff
changeset
|
16 if (sub_len == 0) |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49310
diff
changeset
|
17 return (str_len < maxcount) ? str_len + 1 : maxcount; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
18 |
| 72475 | 19 count = FASTSEARCH(str, str_len, sub, sub_len, maxcount, FAST_COUNT); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
20 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
21 if (count < 0) |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
49310
diff
changeset
|
22 return 0; /* no match */ |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
23 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
24 return count; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
25 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
26 |
| 72475 | 27 |
