]> granicus.if.org Git - python/commit
SF patch 549375: Compromise PyUnicode_EncodeUTF8
authorTim Peters <tim.peters@gmail.com>
Sat, 27 Apr 2002 18:03:26 +0000 (18:03 +0000)
committerTim Peters <tim.peters@gmail.com>
Sat, 27 Apr 2002 18:03:26 +0000 (18:03 +0000)
commit602f740bc2da44ce25c22b7b4b5a7a4fb3435a5a
tree9c9f5c81767cd3ea9701ade84fea16144f2b56cd
parent73364e64e5db0a0c79102471ebbd81d2607ec706
SF patch 549375:  Compromise PyUnicode_EncodeUTF8
This implements ideas from Marc-Andre, Martin, Guido and me on Python-Dev.

"Short" Unicode strings are encoded into a "big enough" stack buffer,
then exactly as much string space as they turn out to need is allocated
at the end.  This should have speed benefits akin to Martin's "measure
once, allocate once" strategy, but without needing a distinct measuring
pass.

"Long" Unicode strings allocate as much heap space as they could possibly
need (4 x # Unicode chars), and do a realloc at the end to return the
untouched excess.  Since the overallocation is likely to be substantial,
this shouldn't burden the platform realloc with unusably small excess
blocks.

Also simplified uses of the PyString_xyz functions.  Also added a release-
build check that 4*size doesn't overflow a C int.  Sooner or later, that's
going to happen.
Objects/unicodeobject.c