@@ -453,31 +453,21 @@ stringlib_parse_args_finds().
453
453
*/
454
454
455
455
Py_LOCAL_INLINE (int )
456
- parse_args_finds_byte (const char * function_name , PyObject * args ,
457
- PyObject * * subobj , char * byte ,
458
- Py_ssize_t * start , Py_ssize_t * end )
456
+ parse_args_finds_byte (const char * function_name , PyObject * * subobj , char * byte )
459
457
{
460
- PyObject * tmp_subobj ;
461
- Py_ssize_t ival ;
462
-
463
- if (!stringlib_parse_args_finds (function_name , args , & tmp_subobj ,
464
- start , end ))
465
- return 0 ;
466
-
467
- if (PyObject_CheckBuffer (tmp_subobj )) {
468
- * subobj = tmp_subobj ;
458
+ if (PyObject_CheckBuffer (* subobj )) {
469
459
return 1 ;
470
460
}
471
461
472
- if (!_PyIndex_Check (tmp_subobj )) {
462
+ if (!_PyIndex_Check (* subobj )) {
473
463
PyErr_Format (PyExc_TypeError ,
474
464
"argument should be integer or bytes-like object, "
475
465
"not '%.200s'" ,
476
- Py_TYPE (tmp_subobj )-> tp_name );
466
+ Py_TYPE (* subobj )-> tp_name );
477
467
return 0 ;
478
468
}
479
469
480
- ival = PyNumber_AsSsize_t (tmp_subobj , NULL );
470
+ Py_ssize_t ival = PyNumber_AsSsize_t (* subobj , NULL );
481
471
if (ival == -1 && PyErr_Occurred ()) {
482
472
return 0 ;
483
473
}
@@ -508,19 +498,19 @@ parse_args_finds_byte(const char *function_name, PyObject *args,
508
498
509
499
Py_LOCAL_INLINE (Py_ssize_t )
510
500
find_internal (const char * str , Py_ssize_t len ,
511
- const char * function_name , PyObject * args , int dir )
501
+ const char * function_name , PyObject * subobj ,
502
+ Py_ssize_t start , Py_ssize_t end ,
503
+ int dir )
512
504
{
513
- PyObject * subobj ;
514
505
char byte ;
515
506
Py_buffer subbuf ;
516
507
const char * sub ;
517
508
Py_ssize_t sub_len ;
518
- Py_ssize_t start = 0 , end = PY_SSIZE_T_MAX ;
519
509
Py_ssize_t res ;
520
510
521
- if (!parse_args_finds_byte (function_name , args ,
522
- & subobj , & byte , & start , & end ))
511
+ if (!parse_args_finds_byte (function_name , & subobj , & byte )) {
523
512
return -2 ;
513
+ }
524
514
525
515
if (subobj ) {
526
516
if (PyObject_GetBuffer (subobj , & subbuf , PyBUF_SIMPLE ) != 0 )
@@ -566,37 +556,21 @@ find_internal(const char *str, Py_ssize_t len,
566
556
return res ;
567
557
}
568
558
569
- PyDoc_STRVAR_shared (_Py_find__doc__ ,
570
- "B.find(sub[, start[, end]]) -> int\n\
571
- \n\
572
- Return the lowest index in B where subsection sub is found,\n\
573
- such that sub is contained within B[start,end]. Optional\n\
574
- arguments start and end are interpreted as in slice notation.\n\
575
- \n\
576
- Return -1 on failure." );
577
-
578
559
PyObject *
579
- _Py_bytes_find (const char * str , Py_ssize_t len , PyObject * args )
560
+ _Py_bytes_find (const char * str , Py_ssize_t len , PyObject * sub ,
561
+ Py_ssize_t start , Py_ssize_t end )
580
562
{
581
- Py_ssize_t result = find_internal (str , len , "find" , args , +1 );
563
+ Py_ssize_t result = find_internal (str , len , "find" , sub , start , end , +1 );
582
564
if (result == -2 )
583
565
return NULL ;
584
566
return PyLong_FromSsize_t (result );
585
567
}
586
568
587
- PyDoc_STRVAR_shared (_Py_index__doc__ ,
588
- "B.index(sub[, start[, end]]) -> int\n\
589
- \n\
590
- Return the lowest index in B where subsection sub is found,\n\
591
- such that sub is contained within B[start,end]. Optional\n\
592
- arguments start and end are interpreted as in slice notation.\n\
593
- \n\
594
- Raises ValueError when the subsection is not found." );
595
-
596
569
PyObject *
597
- _Py_bytes_index (const char * str , Py_ssize_t len , PyObject * args )
570
+ _Py_bytes_index (const char * str , Py_ssize_t len , PyObject * sub ,
571
+ Py_ssize_t start , Py_ssize_t end )
598
572
{
599
- Py_ssize_t result = find_internal (str , len , "index" , args , +1 );
573
+ Py_ssize_t result = find_internal (str , len , "index" , sub , start , end , +1 );
600
574
if (result == -2 )
601
575
return NULL ;
602
576
if (result == -1 ) {
@@ -607,37 +581,21 @@ _Py_bytes_index(const char *str, Py_ssize_t len, PyObject *args)
607
581
return PyLong_FromSsize_t (result );
608
582
}
609
583
610
- PyDoc_STRVAR_shared (_Py_rfind__doc__ ,
611
- "B.rfind(sub[, start[, end]]) -> int\n\
612
- \n\
613
- Return the highest index in B where subsection sub is found,\n\
614
- such that sub is contained within B[start,end]. Optional\n\
615
- arguments start and end are interpreted as in slice notation.\n\
616
- \n\
617
- Return -1 on failure." );
618
-
619
584
PyObject *
620
- _Py_bytes_rfind (const char * str , Py_ssize_t len , PyObject * args )
585
+ _Py_bytes_rfind (const char * str , Py_ssize_t len , PyObject * sub ,
586
+ Py_ssize_t start , Py_ssize_t end )
621
587
{
622
- Py_ssize_t result = find_internal (str , len , "rfind" , args , -1 );
588
+ Py_ssize_t result = find_internal (str , len , "rfind" , sub , start , end , -1 );
623
589
if (result == -2 )
624
590
return NULL ;
625
591
return PyLong_FromSsize_t (result );
626
592
}
627
593
628
- PyDoc_STRVAR_shared (_Py_rindex__doc__ ,
629
- "B.rindex(sub[, start[, end]]) -> int\n\
630
- \n\
631
- Return the highest index in B where subsection sub is found,\n\
632
- such that sub is contained within B[start,end]. Optional\n\
633
- arguments start and end are interpreted as in slice notation.\n\
634
- \n\
635
- Raise ValueError when the subsection is not found." );
636
-
637
594
PyObject *
638
- _Py_bytes_rindex (const char * str , Py_ssize_t len , PyObject * args )
595
+ _Py_bytes_rindex (const char * str , Py_ssize_t len , PyObject * sub ,
596
+ Py_ssize_t start , Py_ssize_t end )
639
597
{
640
- Py_ssize_t result = find_internal (str , len , "rindex" , args , -1 );
598
+ Py_ssize_t result = find_internal (str , len , "rindex" , sub , start , end , -1 );
641
599
if (result == -2 )
642
600
return NULL ;
643
601
if (result == -1 ) {
@@ -648,28 +606,20 @@ _Py_bytes_rindex(const char *str, Py_ssize_t len, PyObject *args)
648
606
return PyLong_FromSsize_t (result );
649
607
}
650
608
651
- PyDoc_STRVAR_shared (_Py_count__doc__ ,
652
- "B.count(sub[, start[, end]]) -> int\n\
653
- \n\
654
- Return the number of non-overlapping occurrences of subsection sub in\n\
655
- bytes B[start:end]. Optional arguments start and end are interpreted\n\
656
- as in slice notation." );
657
-
658
609
PyObject *
659
- _Py_bytes_count (const char * str , Py_ssize_t len , PyObject * args )
610
+ _Py_bytes_count (const char * str , Py_ssize_t len , PyObject * sub_obj ,
611
+ Py_ssize_t start , Py_ssize_t end )
660
612
{
661
- PyObject * sub_obj ;
662
613
const char * sub ;
663
614
Py_ssize_t sub_len ;
664
615
char byte ;
665
- Py_ssize_t start = 0 , end = PY_SSIZE_T_MAX ;
666
616
667
617
Py_buffer vsub ;
668
618
PyObject * count_obj ;
669
619
670
- if (!parse_args_finds_byte ("count" , args ,
671
- & sub_obj , & byte , & start , & end ))
620
+ if (!parse_args_finds_byte ("count" , & sub_obj , & byte )) {
672
621
return NULL ;
622
+ }
673
623
674
624
if (sub_obj ) {
675
625
if (PyObject_GetBuffer (sub_obj , & vsub , PyBUF_SIMPLE ) != 0 )
0 commit comments