@@ -389,24 +389,38 @@ impl PyByteArray {
389389 self . borrow_value ( ) . rstrip ( chars) . into ( )
390390 }
391391
392+ /// removeprefix($self, prefix, /)
393+ ///
394+ ///
395+ /// Return a bytearray object with the given prefix string removed if present.
396+ ///
397+ /// If the bytearray starts with the prefix string, return string[len(prefix):]
398+ /// Otherwise, return a copy of the original bytearray.
392399 #[ pymethod( name = "removeprefix" ) ]
393400 fn removeprefix ( & self , prefix : PyByteInner ) -> PyByteArray {
394- let value = self . borrow_value ( ) ;
395- if value. elements . starts_with ( & prefix. elements ) {
396- return value. elements [ prefix. elements . len ( ) ..] . to_vec ( ) . into ( ) ;
397- }
398- value. elements . to_vec ( ) . into ( )
401+ self . borrow_value ( ) . elements [ ..]
402+ . py_removeprefix ( & prefix. elements , prefix. elements . len ( ) , |s, p| {
403+ s. starts_with ( p)
404+ } )
405+ . to_vec ( )
406+ . into ( )
399407 }
400408
409+ /// removesuffix(self, prefix, /)
410+ ///
411+ ///
412+ /// Return a bytearray object with the given suffix string removed if present.
413+ ///
414+ /// If the bytearray ends with the suffix string, return string[:len(suffix)]
415+ /// Otherwise, return a copy of the original bytearray.
401416 #[ pymethod( name = "removesuffix" ) ]
402417 fn removesuffix ( & self , suffix : PyByteInner ) -> PyByteArray {
403- let value = self . borrow_value ( ) ;
404- if value. elements . ends_with ( & suffix. elements ) {
405- return value. elements [ ..value. elements . len ( ) - suffix. elements . len ( ) ]
406- . to_vec ( )
407- . into ( ) ;
408- }
409- value. elements . to_vec ( ) . into ( )
418+ self . borrow_value ( ) . elements [ ..]
419+ . py_removesuffix ( & suffix. elements , suffix. elements . len ( ) , |s, p| {
420+ s. ends_with ( p)
421+ } )
422+ . to_vec ( )
423+ . into ( )
410424 }
411425
412426 #[ pymethod( name = "split" ) ]
0 commit comments