/home/mdboom/Work/builds/cpython/Objects/stringlib/replace.h
Line | Count | Source |
1 | /* stringlib: replace implementation */ |
2 | |
3 | #ifndef STRINGLIB_FASTSEARCH_H |
4 | #error must include "stringlib/fastsearch.h" before including this module |
5 | #endif |
6 | |
7 | Py_LOCAL_INLINE(void) |
8 | STRINGLIB(replace_1char_inplace)(STRINGLIB_CHAR* s, STRINGLIB_CHAR* end, |
9 | Py_UCS4 u1, Py_UCS4 u2, Py_ssize_t maxcount) |
10 | { |
11 | *s = u2; |
12 | while (--maxcount && ++s != end48.6k ) { Branch (12:12): [True: 48.5k, False: 17]
Branch (12:26): [True: 48.1k, False: 473]
Branch (12:12): [True: 64, False: 0]
Branch (12:26): [True: 64, False: 0]
Branch (12:12): [True: 19, False: 0]
Branch (12:26): [True: 19, False: 0]
|
13 | /* Find the next character to be replaced. |
14 | |
15 | If it occurs often, it is faster to scan for it using an inline |
16 | loop. If it occurs seldom, it is faster to scan for it using a |
17 | function call; the overhead of the function call is amortized |
18 | across the many characters that call covers. We start with an |
19 | inline loop and use a heuristic to determine whether to fall back |
20 | to a function call. */ |
21 | if (*s != u1) { Branch (21:13): [True: 36.1k, False: 11.9k]
Branch (21:13): [True: 51, False: 13]
Branch (21:13): [True: 19, False: 0]
|
22 | int attempts = 10; |
23 | /* search u1 in a dummy loop */ |
24 | while (1) { Branch (24:20): [Folded - Ignored]
Branch (24:20): [Folded - Ignored]
Branch (24:20): [Folded - Ignored]
|
25 | if (++s == end) Branch (25:21): [True: 16.2k, False: 232k]
Branch (25:21): [True: 12, False: 294]
Branch (25:21): [True: 19, False: 152]
|
26 | return; |
27 | if (*s == u1) Branch (27:21): [True: 11.3k, False: 220k]
Branch (27:21): [True: 35, False: 259]
Branch (27:21): [True: 0, False: 152]
|
28 | break; |
29 | if (!--attempts) { Branch (29:21): [True: 8.64k, False: 212k]
Branch (29:21): [True: 4, False: 255]
Branch (29:21): [True: 0, False: 152]
|
30 | /* if u1 was not found for attempts iterations, |
31 | use FASTSEARCH() or memchr() */ |
32 | #ifdef STRINGLIB_FAST_MEMCHR |
33 | s++; |
34 | s = STRINGLIB_FAST_MEMCHR(s, u1, end - s); |
35 | if (s == NULL) Branch (35:25): [True: 6.82k, False: 1.82k]
Branch (35:25): [True: 0, False: 0]
|
36 | return; |
37 | #else |
38 | Py_ssize_t i; |
39 | STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1; |
40 | s++; |
41 | i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH); |
42 | if (i < 0) Branch (42:25): [True: 2, False: 2]
|
43 | return; |
44 | s += i; |
45 | #endif |
46 | /* restart the dummy loop */ |
47 | break; |
48 | } |
49 | } |
50 | } |
51 | *s = u2; |
52 | } |
53 | } unicodeobject.c:ucs1lib_replace_1char_inplace Line | Count | Source | 10 | { | 11 | *s = u2; | 12 | while (--maxcount && ++s != end48.5k ) { Branch (12:12): [True: 48.5k, False: 17]
Branch (12:26): [True: 48.1k, False: 473]
| 13 | /* Find the next character to be replaced. | 14 | | 15 | If it occurs often, it is faster to scan for it using an inline | 16 | loop. If it occurs seldom, it is faster to scan for it using a | 17 | function call; the overhead of the function call is amortized | 18 | across the many characters that call covers. We start with an | 19 | inline loop and use a heuristic to determine whether to fall back | 20 | to a function call. */ | 21 | if (*s != u1) { Branch (21:13): [True: 36.1k, False: 11.9k]
| 22 | int attempts = 10; | 23 | /* search u1 in a dummy loop */ | 24 | while (1) { Branch (24:20): [Folded - Ignored]
| 25 | if (++s == end) Branch (25:21): [True: 16.2k, False: 232k]
| 26 | return; | 27 | if (*s == u1) Branch (27:21): [True: 11.3k, False: 220k]
| 28 | break; | 29 | if (!--attempts) { Branch (29:21): [True: 8.64k, False: 212k]
| 30 | /* if u1 was not found for attempts iterations, | 31 | use FASTSEARCH() or memchr() */ | 32 | #ifdef STRINGLIB_FAST_MEMCHR | 33 | s++; | 34 | s = STRINGLIB_FAST_MEMCHR(s, u1, end - s); | 35 | if (s == NULL) Branch (35:25): [True: 6.82k, False: 1.82k]
| 36 | return; | 37 | #else | 38 | Py_ssize_t i; | 39 | STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1; | 40 | s++; | 41 | i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH); | 42 | if (i < 0) | 43 | return; | 44 | s += i; | 45 | #endif | 46 | /* restart the dummy loop */ | 47 | break; | 48 | } | 49 | } | 50 | } | 51 | *s = u2; | 52 | } | 53 | } |
unicodeobject.c:ucs2lib_replace_1char_inplace Line | Count | Source | 10 | { | 11 | *s = u2; | 12 | while (--maxcount && ++s != end) { Branch (12:12): [True: 64, False: 0]
Branch (12:26): [True: 64, False: 0]
| 13 | /* Find the next character to be replaced. | 14 | | 15 | If it occurs often, it is faster to scan for it using an inline | 16 | loop. If it occurs seldom, it is faster to scan for it using a | 17 | function call; the overhead of the function call is amortized | 18 | across the many characters that call covers. We start with an | 19 | inline loop and use a heuristic to determine whether to fall back | 20 | to a function call. */ | 21 | if (*s != u1) { Branch (21:13): [True: 51, False: 13]
| 22 | int attempts = 10; | 23 | /* search u1 in a dummy loop */ | 24 | while (1) { Branch (24:20): [Folded - Ignored]
| 25 | if (++s == end) Branch (25:21): [True: 12, False: 294]
| 26 | return; | 27 | if (*s == u1) Branch (27:21): [True: 35, False: 259]
| 28 | break; | 29 | if (!--attempts) { Branch (29:21): [True: 4, False: 255]
| 30 | /* if u1 was not found for attempts iterations, | 31 | use FASTSEARCH() or memchr() */ | 32 | #ifdef STRINGLIB_FAST_MEMCHR | 33 | s++; | 34 | s = STRINGLIB_FAST_MEMCHR(s, u1, end - s); | 35 | if (s == NULL) | 36 | return; | 37 | #else | 38 | Py_ssize_t i; | 39 | STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1; | 40 | s++; | 41 | i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH); | 42 | if (i < 0) Branch (42:25): [True: 2, False: 2]
| 43 | return; | 44 | s += i; | 45 | #endif | 46 | /* restart the dummy loop */ | 47 | break; | 48 | } | 49 | } | 50 | } | 51 | *s = u2; | 52 | } | 53 | } |
unicodeobject.c:ucs4lib_replace_1char_inplace Line | Count | Source | 10 | { | 11 | *s = u2; | 12 | while (--maxcount && ++s != end) { Branch (12:12): [True: 19, False: 0]
Branch (12:26): [True: 19, False: 0]
| 13 | /* Find the next character to be replaced. | 14 | | 15 | If it occurs often, it is faster to scan for it using an inline | 16 | loop. If it occurs seldom, it is faster to scan for it using a | 17 | function call; the overhead of the function call is amortized | 18 | across the many characters that call covers. We start with an | 19 | inline loop and use a heuristic to determine whether to fall back | 20 | to a function call. */ | 21 | if (*s != u1) { Branch (21:13): [True: 19, False: 0]
| 22 | int attempts = 10; | 23 | /* search u1 in a dummy loop */ | 24 | while (1) { Branch (24:20): [Folded - Ignored]
| 25 | if (++s == end) Branch (25:21): [True: 19, False: 152]
| 26 | return; | 27 | if (*s == u1) Branch (27:21): [True: 0, False: 152]
| 28 | break; | 29 | if (!--attempts) { Branch (29:21): [True: 0, False: 152]
| 30 | /* if u1 was not found for attempts iterations, | 31 | use FASTSEARCH() or memchr() */ | 32 | #ifdef STRINGLIB_FAST_MEMCHR | 33 | s++; | 34 | s = STRINGLIB_FAST_MEMCHR(s, u1, end - s); | 35 | if (s == NULL) Branch (35:25): [True: 0, False: 0]
| 36 | return; | 37 | #else | 38 | Py_ssize_t i; | 39 | STRINGLIB_CHAR ch1 = (STRINGLIB_CHAR) u1; | 40 | s++; | 41 | i = FASTSEARCH(s, end - s, &ch1, 1, 0, FAST_SEARCH); | 42 | if (i < 0) | 43 | return; | 44 | s += i; | 45 | #endif | 46 | /* restart the dummy loop */ | 47 | break; | 48 | } | 49 | } | 50 | } | 51 | *s = u2; | 52 | } | 53 | } |
|