Optimize unicode_subtype_new(): don't encode to wchar_t and decode from wchar_t

Rewrite unicode_subtype_new(): allocate directly the right type.
This commit is contained in:
Victor Stinner 2011-10-01 16:16:43 +02:00
parent e90fe6a8f4
commit 07ac3ebd7b
2 changed files with 81 additions and 43 deletions

View file

@ -1010,10 +1010,13 @@ class UnicodeTest(string_tests.CommonTest,
class UnicodeSubclass(str):
pass
self.assertEqual(
str(UnicodeSubclass('unicode subclass becomes unicode')),
'unicode subclass becomes unicode'
)
for text in ('ascii', '\xe9', '\u20ac', '\U0010FFFF'):
subclass = UnicodeSubclass(text)
self.assertEqual(str(subclass), text)
self.assertEqual(len(subclass), len(text))
if text == 'ascii':
self.assertEqual(subclass.encode('ascii'), b'ascii')
self.assertEqual(subclass.encode('utf-8'), b'ascii')
self.assertEqual(
str('strings are converted to unicode'),