Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cc7af721
Commit
cc7af721
authored
Apr 09, 2013
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Write super-fast version of str.strip(), str.lstrip() and str.rstrip() for pure ASCII
parent
f50a4e9b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
19 deletions
+45
-19
Objects/unicodeobject.c
Objects/unicodeobject.c
+45
-19
No files found.
Objects/unicodeobject.c
View file @
cc7af721
...
...
@@ -11722,37 +11722,63 @@ PyUnicode_Substring(PyObject *self, Py_ssize_t start, Py_ssize_t end)
static
PyObject
*
do_strip
(
PyObject
*
self
,
int
striptype
)
{
int
kind
;
void
*
data
;
Py_ssize_t
len
,
i
,
j
;
if
(
PyUnicode_READY
(
self
)
==
-
1
)
return
NULL
;
kind
=
PyUnicode_KIND
(
self
);
data
=
PyUnicode_DATA
(
self
);
len
=
PyUnicode_GET_LENGTH
(
self
);
i
=
0
;
if
(
striptype
!=
RIGHTSTRIP
)
{
while
(
i
<
len
)
{
Py_UCS4
ch
=
PyUnicode_READ
(
kind
,
data
,
i
);
if
(
!
Py_UNICODE_ISSPACE
(
ch
))
break
;
i
++
;
if
(
PyUnicode_IS_ASCII
(
self
))
{
Py_UCS1
*
data
=
PyUnicode_1BYTE_DATA
(
self
);
i
=
0
;
if
(
striptype
!=
RIGHTSTRIP
)
{
while
(
i
<
len
)
{
Py_UCS4
ch
=
data
[
i
];
if
(
!
_Py_ascii_whitespace
[
ch
])
break
;
i
++
;
}
}
j
=
len
;
if
(
striptype
!=
LEFTSTRIP
)
{
j
--
;
while
(
j
>=
i
)
{
Py_UCS4
ch
=
data
[
j
];
if
(
!
_Py_ascii_whitespace
[
ch
])
break
;
j
--
;
}
j
++
;
}
}
else
{
int
kind
=
PyUnicode_KIND
(
self
);
void
*
data
=
PyUnicode_DATA
(
self
);
j
=
len
;
if
(
striptype
!=
LEFTSTRIP
)
{
j
--
;
while
(
j
>=
i
)
{
Py_UCS4
ch
=
PyUnicode_READ
(
kind
,
data
,
j
);
if
(
!
Py_UNICODE_ISSPACE
(
ch
))
break
;
i
=
0
;
if
(
striptype
!=
RIGHTSTRIP
)
{
while
(
i
<
len
)
{
Py_UCS4
ch
=
PyUnicode_READ
(
kind
,
data
,
i
);
if
(
!
Py_UNICODE_ISSPACE
(
ch
))
break
;
i
++
;
}
}
j
=
len
;
if
(
striptype
!=
LEFTSTRIP
)
{
j
--
;
while
(
j
>=
i
)
{
Py_UCS4
ch
=
PyUnicode_READ
(
kind
,
data
,
j
);
if
(
!
Py_UNICODE_ISSPACE
(
ch
))
break
;
j
--
;
}
j
++
;
}
j
++
;
}
return
PyUnicode_Substring
(
self
,
i
,
j
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment