FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Objects/stringlib/replace.h at main · python/cpython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
python
/
cpython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
35.3k
Star
74.9k
Code
Issues
5k+
Pull requests
2.6k
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Objects
/
stringlib
/
replace.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
53 lines (50 loc) · 1.82 KB
Breadcrumbs
cpython
/
Objects
/
stringlib
/
replace.h
Copy path
File metadata and controls
53 lines (50 loc) · 1.82 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* stringlib: replace implementation */
#ifndef
STRINGLIB_FASTSEARCH_H
#error
must include "stringlib/fastsearch.h" before including this module
#endif
Py_LOCAL_INLINE
(
void
)
STRINGLIB
(
replace_1char_inplace
)(
STRINGLIB_CHAR
*
s
,
STRINGLIB_CHAR
*
end
,
Py_UCS4
u1
,
Py_UCS4
u2
,
Py_ssize_t
maxcount
)
{
*
s
=
u2
;
while
(
--
maxcount
&&
++
s
!=
end
) {
/* Find the next character to be replaced.
If it occurs often, it is faster to scan for it using an inline
loop. If it occurs seldom, it is faster to scan for it using a
function call; the overhead of the function call is amortized
across the many characters that call covers. We start with an
inline loop and use a heuristic to determine whether to fall back
to a function call. */
if
(
*
s
!=
u1
) {
int
attempts
=
10
;
/* search u1 in a dummy loop */
while
(
1
) {
if
(
++
s
==
end
)
return
;
if
(
*
s
==
u1
)
break
;
if
(!
--
attempts
) {
/* if u1 was not found for attempts iterations,
use FASTSEARCH() or memchr() */
#ifdef
STRINGLIB_FAST_MEMCHR
s
++
;
s
=
STRINGLIB_FAST_MEMCHR
(
s
,
u1
,
end
-
s
);
if
(
s
==
NULL
)
return
;
#else
Py_ssize_t
i
;
STRINGLIB_CHAR
ch1
=
(
STRINGLIB_CHAR
)
u1
;
s
++
;
i
=
FASTSEARCH
(
s
,
end
-
s
,
&
ch1
,
1
,
0
,
FAST_SEARCH
);
if
(
i
<
0
)
return
;
s
+=
i
;
#endif
/* restart the dummy loop */
break
;
}
}
}
*
s
=
u2
;
}
}
Back
|
FazBrowse Home
|
New Git URL