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
bf4e2663
Commit
bf4e2663
authored
May 03, 2012
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #14687: Remove redundant length attribute of unicode_write_t
The length can be read directly from the buffer
parent
7989157e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
12 deletions
+8
-12
Objects/unicodeobject.c
Objects/unicodeobject.c
+8
-12
No files found.
Objects/unicodeobject.c
View file @
bf4e2663
...
@@ -13661,7 +13661,6 @@ struct unicode_writer_t {
...
@@ -13661,7 +13661,6 @@ struct unicode_writer_t {
void
*
data
;
void
*
data
;
enum
PyUnicode_Kind
kind
;
enum
PyUnicode_Kind
kind
;
Py_UCS4
maxchar
;
Py_UCS4
maxchar
;
Py_ssize_t
length
;
Py_ssize_t
pos
;
Py_ssize_t
pos
;
};
};
...
@@ -13678,8 +13677,7 @@ unicode_writer_init(struct unicode_writer_t *writer,
...
@@ -13678,8 +13677,7 @@ unicode_writer_init(struct unicode_writer_t *writer,
Py_ssize_t
length
,
Py_UCS4
maxchar
)
Py_ssize_t
length
,
Py_UCS4
maxchar
)
{
{
writer
->
pos
=
0
;
writer
->
pos
=
0
;
writer
->
length
=
length
;
writer
->
buffer
=
PyUnicode_New
(
length
,
maxchar
);
writer
->
buffer
=
PyUnicode_New
(
writer
->
length
,
maxchar
);
if
(
writer
->
buffer
==
NULL
)
if
(
writer
->
buffer
==
NULL
)
return
-
1
;
return
-
1
;
unicode_writer_update
(
writer
);
unicode_writer_update
(
writer
);
...
@@ -13699,16 +13697,14 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
...
@@ -13699,16 +13697,14 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
}
}
newlen
=
writer
->
pos
+
length
;
newlen
=
writer
->
pos
+
length
;
if
(
newlen
>
writer
->
length
)
{
if
(
newlen
>
PyUnicode_GET_LENGTH
(
writer
->
buffer
)
)
{
/* 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
;
newlen
+=
newlen
/
4
;
else
writer
->
length
=
newlen
+
newlen
/
4
;
if
(
maxchar
>
writer
->
maxchar
)
{
if
(
maxchar
>
writer
->
maxchar
)
{
/* resize + widen */
/* resize + widen */
newbuffer
=
PyUnicode_New
(
writer
->
length
,
maxchar
);
newbuffer
=
PyUnicode_New
(
newlen
,
maxchar
);
if
(
newbuffer
==
NULL
)
if
(
newbuffer
==
NULL
)
return
-
1
;
return
-
1
;
PyUnicode_CopyCharacters
(
newbuffer
,
0
,
PyUnicode_CopyCharacters
(
newbuffer
,
0
,
...
@@ -13716,7 +13712,7 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
...
@@ -13716,7 +13712,7 @@ unicode_writer_prepare(struct unicode_writer_t *writer,
Py_DECREF
(
writer
->
buffer
);
Py_DECREF
(
writer
->
buffer
);
}
}
else
{
else
{
newbuffer
=
resize_compact
(
writer
->
buffer
,
writer
->
length
);
newbuffer
=
resize_compact
(
writer
->
buffer
,
newlen
);
if
(
newbuffer
==
NULL
)
if
(
newbuffer
==
NULL
)
return
-
1
;
return
-
1
;
}
}
...
@@ -13740,7 +13736,7 @@ unicode_writer_write_str(
...
@@ -13740,7 +13736,7 @@ unicode_writer_write_str(
maxchar
=
_PyUnicode_FindMaxChar
(
str
,
start
,
start
+
length
);
maxchar
=
_PyUnicode_FindMaxChar
(
str
,
start
,
start
+
length
);
if
(
unicode_writer_prepare
(
writer
,
length
,
maxchar
)
==
-
1
)
if
(
unicode_writer_prepare
(
writer
,
length
,
maxchar
)
==
-
1
)
return
-
1
;
return
-
1
;
assert
((
writer
->
pos
+
length
)
<=
writer
->
length
);
assert
((
writer
->
pos
+
length
)
<=
PyUnicode_GET_LENGTH
(
writer
->
buffer
)
);
copy_characters
(
writer
->
buffer
,
writer
->
pos
,
copy_characters
(
writer
->
buffer
,
writer
->
pos
,
str
,
start
,
length
);
str
,
start
,
length
);
writer
->
pos
+=
length
;
writer
->
pos
+=
length
;
...
@@ -13754,7 +13750,7 @@ unicode_writer_write_char(
...
@@ -13754,7 +13750,7 @@ unicode_writer_write_char(
{
{
if
(
unicode_writer_prepare
(
writer
,
1
,
ch
)
==
-
1
)
if
(
unicode_writer_prepare
(
writer
,
1
,
ch
)
==
-
1
)
return
-
1
;
return
-
1
;
assert
((
writer
->
pos
+
1
)
<=
writer
->
length
);
assert
((
writer
->
pos
+
1
)
<=
PyUnicode_GET_LENGTH
(
writer
->
buffer
)
);
PyUnicode_WRITE
(
writer
->
kind
,
writer
->
data
,
writer
->
pos
,
ch
);
PyUnicode_WRITE
(
writer
->
kind
,
writer
->
data
,
writer
->
pos
,
ch
);
writer
->
pos
+=
1
;
writer
->
pos
+=
1
;
return
0
;
return
0
;
...
...
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