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
e19aa388
Commit
e19aa388
authored
Oct 04, 2011
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When expandtabs() would be a no-op, don't create a duplicate string
parent
87a484ca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
0 deletions
+11
-0
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+4
-0
Objects/unicodeobject.c
Objects/unicodeobject.c
+7
-0
No files found.
Lib/test/test_unicode.py
View file @
e19aa388
...
@@ -1585,6 +1585,10 @@ class UnicodeTest(string_tests.CommonTest,
...
@@ -1585,6 +1585,10 @@ class UnicodeTest(string_tests.CommonTest,
return
return
self
.
assertRaises
(
OverflowError
,
't
\
t
t
\
t
'
.
expandtabs
,
sys
.
maxsize
)
self
.
assertRaises
(
OverflowError
,
't
\
t
t
\
t
'
.
expandtabs
,
sys
.
maxsize
)
def
test_expandtabs_optimization
(
self
):
s
=
'abc'
self
.
assertIs
(
s
.
expandtabs
(),
s
)
def
test_raiseMemError
(
self
):
def
test_raiseMemError
(
self
):
if
struct
.
calcsize
(
'P'
)
==
8
:
if
struct
.
calcsize
(
'P'
)
==
8
:
# 64 bits pointers
# 64 bits pointers
...
...
Objects/unicodeobject.c
View file @
e19aa388
...
@@ -10196,6 +10196,7 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
...
@@ -10196,6 +10196,7 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
void
*
src_data
,
*
dest_data
;
void
*
src_data
,
*
dest_data
;
int
tabsize
=
8
;
int
tabsize
=
8
;
int
kind
;
int
kind
;
int
found
;
if
(
!
PyArg_ParseTuple
(
args
,
"|i:expandtabs"
,
&
tabsize
))
if
(
!
PyArg_ParseTuple
(
args
,
"|i:expandtabs"
,
&
tabsize
))
return
NULL
;
return
NULL
;
...
@@ -10205,9 +10206,11 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
...
@@ -10205,9 +10206,11 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
i
=
j
=
line_pos
=
0
;
i
=
j
=
line_pos
=
0
;
kind
=
PyUnicode_KIND
(
self
);
kind
=
PyUnicode_KIND
(
self
);
src_data
=
PyUnicode_DATA
(
self
);
src_data
=
PyUnicode_DATA
(
self
);
found
=
0
;
for
(;
i
<
src_len
;
i
++
)
{
for
(;
i
<
src_len
;
i
++
)
{
ch
=
PyUnicode_READ
(
kind
,
src_data
,
i
);
ch
=
PyUnicode_READ
(
kind
,
src_data
,
i
);
if
(
ch
==
'\t'
)
{
if
(
ch
==
'\t'
)
{
found
=
1
;
if
(
tabsize
>
0
)
{
if
(
tabsize
>
0
)
{
incr
=
tabsize
-
(
line_pos
%
tabsize
);
/* cannot overflow */
incr
=
tabsize
-
(
line_pos
%
tabsize
);
/* cannot overflow */
if
(
j
>
PY_SSIZE_T_MAX
-
incr
)
if
(
j
>
PY_SSIZE_T_MAX
-
incr
)
...
@@ -10225,6 +10228,10 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
...
@@ -10225,6 +10228,10 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args)
line_pos
=
0
;
line_pos
=
0
;
}
}
}
}
if
(
!
found
&&
PyUnicode_CheckExact
(
self
))
{
Py_INCREF
((
PyObject
*
)
self
);
return
(
PyObject
*
)
self
;
}
/* Second pass: create output string and fill it */
/* Second pass: create output string and fill it */
u
=
PyUnicode_New
(
j
,
PyUnicode_MAX_CHAR_VALUE
(
self
));
u
=
PyUnicode_New
(
j
,
PyUnicode_MAX_CHAR_VALUE
(
self
));
...
...
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