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
7989157e
Commit
7989157e
authored
May 03, 2012
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #14687: Cleanup unicode_writer_prepare()
"Inline" PyUnicode_Resize(): call directly resize_compact()
parent
f2c76aa6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
23 deletions
+19
-23
Objects/unicodeobject.c
Objects/unicodeobject.c
+19
-23
No files found.
Objects/unicodeobject.c
View file @
7989157e
...
@@ -654,6 +654,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
...
@@ -654,6 +654,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
Py_ssize_t
new_size
;
Py_ssize_t
new_size
;
int
share_wstr
;
int
share_wstr
;
PyObject
*
new_unicode
;
PyObject
*
new_unicode
;
assert
(
unicode_modifiable
(
unicode
));
assert
(
PyUnicode_IS_READY
(
unicode
));
assert
(
PyUnicode_IS_READY
(
unicode
));
assert
(
PyUnicode_IS_COMPACT
(
unicode
));
assert
(
PyUnicode_IS_COMPACT
(
unicode
));
...
@@ -690,6 +691,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
...
@@ -690,6 +691,7 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
}
}
PyUnicode_WRITE
(
PyUnicode_KIND
(
unicode
),
PyUnicode_DATA
(
unicode
),
PyUnicode_WRITE
(
PyUnicode_KIND
(
unicode
),
PyUnicode_DATA
(
unicode
),
length
,
0
);
length
,
0
);
assert
(
_PyUnicode_CheckConsistency
(
unicode
,
0
));
return
unicode
;
return
unicode
;
}
}
...
@@ -1603,7 +1605,6 @@ unicode_resize(PyObject **p_unicode, Py_ssize_t length)
...
@@ -1603,7 +1605,6 @@ unicode_resize(PyObject **p_unicode, Py_ssize_t length)
if
(
new_unicode
==
NULL
)
if
(
new_unicode
==
NULL
)
return
-
1
;
return
-
1
;
*
p_unicode
=
new_unicode
;
*
p_unicode
=
new_unicode
;
assert
(
_PyUnicode_CheckConsistency
(
*
p_unicode
,
0
));
return
0
;
return
0
;
}
}
return
resize_inplace
(
unicode
,
length
);
return
resize_inplace
(
unicode
,
length
);
...
@@ -13690,6 +13691,7 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
...
@@ -13690,6 +13691,7 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
Py_ssize_t
length
,
Py_UCS4
maxchar
)
Py_ssize_t
length
,
Py_UCS4
maxchar
)
{
{
Py_ssize_t
newlen
;
Py_ssize_t
newlen
;
PyObject
*
newbuffer
;
if
(
length
>
PY_SSIZE_T_MAX
-
writer
->
pos
)
{
if
(
length
>
PY_SSIZE_T_MAX
-
writer
->
pos
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
...
@@ -13697,37 +13699,31 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
...
@@ -13697,37 +13699,31 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
}
}
newlen
=
writer
->
pos
+
length
;
newlen
=
writer
->
pos
+
length
;
if
(
newlen
>
writer
->
length
&&
maxchar
>
writer
->
maxchar
)
{
if
(
newlen
>
writer
->
length
)
{
PyObject
*
newbuffer
;
/* overallocate 25% to limit the number of resize */
/* overallocate 25% to limit the number of resize */
if
(
newlen
>
PY_SSIZE_T_MAX
-
newlen
/
4
)
if
(
newlen
>
PY_SSIZE_T_MAX
-
newlen
/
4
)
writer
->
length
=
newlen
;
writer
->
length
=
newlen
;
else
else
writer
->
length
=
newlen
+
newlen
/
4
;
writer
->
length
=
newlen
+
newlen
/
4
;
/* resize + widen */
if
(
maxchar
>
writer
->
maxchar
)
{
newbuffer
=
PyUnicode_New
(
writer
->
length
,
maxchar
);
/* resize + widen */
if
(
newbuffer
==
NULL
)
newbuffer
=
PyUnicode_New
(
writer
->
length
,
maxchar
);
return
-
1
;
if
(
newbuffer
==
NULL
)
PyUnicode_CopyCharacters
(
newbuffer
,
0
,
return
-
1
;
writer
->
buffer
,
0
,
writer
->
pos
);
PyUnicode_CopyCharacters
(
newbuffer
,
0
,
Py_DECREF
(
writer
->
buffer
);
writer
->
buffer
,
0
,
writer
->
pos
);
Py_DECREF
(
writer
->
buffer
);
}
else
{
newbuffer
=
resize_compact
(
writer
->
buffer
,
writer
->
length
);
if
(
newbuffer
==
NULL
)
return
-
1
;
}
writer
->
buffer
=
newbuffer
;
writer
->
buffer
=
newbuffer
;
unicode_writer_update
(
writer
);
unicode_writer_update
(
writer
);
return
0
;
}
if
(
newlen
>
writer
->
length
)
{
/* overallocate 25% to limit the number of resize */
if
(
newlen
>
PY_SSIZE_T_MAX
-
newlen
/
4
)
writer
->
length
=
newlen
;
else
writer
->
length
=
newlen
+
newlen
/
4
;
if
(
PyUnicode_Resize
(
&
writer
->
buffer
,
writer
->
length
)
<
0
)
return
-
1
;
unicode_writer_update
(
writer
);
}
}
if
(
maxchar
>
writer
->
maxchar
)
{
else
if
(
maxchar
>
writer
->
maxchar
)
{
if
(
unicode_widen
(
&
writer
->
buffer
,
writer
->
pos
,
maxchar
)
<
0
)
if
(
unicode_widen
(
&
writer
->
buffer
,
writer
->
pos
,
maxchar
)
<
0
)
return
-
1
;
return
-
1
;
unicode_writer_update
(
writer
);
unicode_writer_update
(
writer
);
...
...
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