@@ -126,7 +126,7 @@ _multidict_extend(MultiDictObject *self, PyObject *arg,
126
126
}
127
127
128
128
129
- static inline int
129
+ static inline Py_ssize_t
130
130
_multidict_extend_parse_args (PyObject * args , PyObject * kwds ,
131
131
const char * name , PyObject * * parg )
132
132
{
@@ -344,85 +344,13 @@ multidict_reduce(MultiDictObject *self)
344
344
return result ;
345
345
}
346
346
347
- static inline PyObject *
348
- _do_multidict_repr (MultiDictObject * md , PyObject * name ,
349
- bool show_keys , bool show_values )
350
- {
351
- PyObject * key = NULL ,
352
- * value = NULL ;
353
- bool comma = false;
354
-
355
- PyUnicodeWriter * writer = PyUnicodeWriter_Create (1024 );
356
- if (writer == NULL )
357
- return NULL ;
358
-
359
- if (PyUnicodeWriter_WriteChar (writer , '<' ) < 0 )
360
- goto fail ;
361
- if (PyUnicodeWriter_WriteStr (writer , name ) < 0 )
362
- goto fail ;
363
- if (PyUnicodeWriter_WriteChar (writer , '(' ) < 0 )
364
- goto fail ;
365
-
366
- pair_list_pos_t pos ;
367
- pair_list_init_pos (& md -> pairs , & pos );
368
-
369
- for (;;) {
370
- int res = pair_list_next (& md -> pairs , & pos , & key , & value );
371
- if (res < 0 ) {
372
- goto fail ;
373
- }
374
- if (res == 0 ) {
375
- break ;
376
- }
377
-
378
- if (comma ) {
379
- if (PyUnicodeWriter_WriteChar (writer , ',' ) < 0 )
380
- goto fail ;
381
- if (PyUnicodeWriter_WriteChar (writer , ' ' ) < 0 )
382
- goto fail ;
383
- }
384
- if (show_keys ) {
385
- if (PyUnicodeWriter_WriteChar (writer , '\'' ) < 0 )
386
- goto fail ;
387
- if (PyUnicodeWriter_WriteStr (writer , key ) < 0 )
388
- goto fail ;
389
- if (PyUnicodeWriter_WriteChar (writer , '\'' ) < 0 )
390
- goto fail ;
391
- }
392
- if (show_keys && show_values ) {
393
- if (PyUnicodeWriter_WriteChar (writer , ':' ) < 0 )
394
- goto fail ;
395
- if (PyUnicodeWriter_WriteChar (writer , ' ' ) < 0 )
396
- goto fail ;
397
- }
398
- if (show_values ) {
399
- if (PyUnicodeWriter_WriteRepr (writer , value ) < 0 )
400
- goto fail ;
401
- }
402
-
403
- Py_CLEAR (key );
404
- Py_CLEAR (value );
405
- comma = true;
406
- }
407
-
408
- if (PyUnicodeWriter_WriteChar (writer , ')' ) < 0 )
409
- goto fail ;
410
- if (PyUnicodeWriter_WriteChar (writer , '>' ) < 0 )
411
- goto fail ;
412
- return PyUnicodeWriter_Finish (writer );
413
- fail :
414
- Py_CLEAR (key );
415
- Py_CLEAR (value );
416
- PyUnicodeWriter_Discard (writer );
417
- }
418
-
419
347
static inline PyObject *
420
348
multidict_repr (MultiDictObject * self )
421
349
{
422
350
PyObject * name = PyObject_GetAttrString ((PyObject * )Py_TYPE (self ), "__name__" );
423
351
if (name == NULL )
424
352
return NULL ;
425
- PyObject * ret = _do_multidict_repr ( self , name , true, true);
353
+ PyObject * ret = pair_list_repr ( & self -> pairs , name , true, true);
426
354
Py_CLEAR (name );
427
355
return ret ;
428
356
}
@@ -604,9 +532,11 @@ static inline PyObject *
604
532
multidict_extend (MultiDictObject * self , PyObject * args , PyObject * kwds )
605
533
{
606
534
PyObject * arg = NULL ;
607
- if (_multidict_extend_parse_args (args , kwds , "extend" , & arg ) < 0 ) {
535
+ Py_ssize_t size = _multidict_extend_parse_args (args , kwds , "extend" , & arg );
536
+ if (size < 0 ) {
608
537
return NULL ;
609
538
}
539
+ pair_list_grow (& self -> pairs , size );
610
540
if (_multidict_extend (self , arg , kwds , "extend" , 1 ) < 0 ) {
611
541
return NULL ;
612
542
}
@@ -1200,7 +1130,7 @@ multidict_proxy_repr(MultiDictProxyObject *self)
1200
1130
PyObject * name = PyObject_GetAttrString ((PyObject * )Py_TYPE (self ), "__name__" );
1201
1131
if (name == NULL )
1202
1132
return NULL ;
1203
- PyObject * ret = _do_multidict_repr ( self -> md , name , true, true);
1133
+ PyObject * ret = pair_list_repr ( & self -> md -> pairs , name , true, true);
1204
1134
Py_CLEAR (name );
1205
1135
return ret ;
1206
1136
}
@@ -1412,6 +1342,7 @@ static inline void
1412
1342
module_free (void * m )
1413
1343
{
1414
1344
Py_CLEAR (multidict_str_lower );
1345
+ Py_CLEAR (multidict_str_canonical );
1415
1346
Py_CLEAR (viewbaseset_and_func );
1416
1347
Py_CLEAR (viewbaseset_or_func );
1417
1348
Py_CLEAR (viewbaseset_sub_func );
@@ -1438,6 +1369,10 @@ PyInit__multidict(void)
1438
1369
if (multidict_str_lower == NULL ) {
1439
1370
goto fail ;
1440
1371
}
1372
+ multidict_str_canonical = PyUnicode_InternFromString ("_canonical" );
1373
+ if (multidict_str_canonical == NULL ) {
1374
+ goto fail ;
1375
+ }
1441
1376
1442
1377
PyObject * module = NULL ;
1443
1378
@@ -1531,6 +1466,7 @@ PyInit__multidict(void)
1531
1466
1532
1467
fail :
1533
1468
Py_XDECREF (multidict_str_lower );
1469
+ Py_XDECREF (multidict_str_canonical );
1534
1470
1535
1471
return NULL ;
1536
1472
}
0 commit comments