11//! Implementation of the python bytearray object.
2+ use bstr:: ByteSlice ;
23use crossbeam_utils:: atomic:: AtomicCell ;
34use std:: convert:: TryFrom ;
5+ use std:: mem:: size_of;
6+ use std:: str:: FromStr ;
47use std:: sync:: { RwLock , RwLockReadGuard , RwLockWriteGuard } ;
58
69use super :: objbyteinner:: {
@@ -21,8 +24,6 @@ use crate::pyobject::{
2124 PyValue , ThreadSafe , TryFromObject , TypeProtocol ,
2225} ;
2326use crate :: vm:: VirtualMachine ;
24- use std:: mem:: size_of;
25- use std:: str:: FromStr ;
2627
2728/// "bytearray(iterable_of_ints) -> bytearray\n\
2829/// bytearray(string, encoding[, errors]) -> bytearray\n\
@@ -327,25 +328,25 @@ impl PyByteArray {
327328
328329 #[ pymethod( name = "find" ) ]
329330 fn find ( & self , options : ByteInnerFindOptions , vm : & VirtualMachine ) -> PyResult < isize > {
330- let index = self . borrow_value ( ) . find ( options, false , vm) ?;
331+ let index = self . borrow_value ( ) . find ( options, |h , n| h . find ( n ) , vm) ?;
331332 Ok ( index. map_or ( -1 , |v| v as isize ) )
332333 }
333334
334335 #[ pymethod( name = "index" ) ]
335336 fn index ( & self , options : ByteInnerFindOptions , vm : & VirtualMachine ) -> PyResult < usize > {
336- let index = self . borrow_value ( ) . find ( options, false , vm) ?;
337+ let index = self . borrow_value ( ) . find ( options, |h , n| h . find ( n ) , vm) ?;
337338 index. ok_or_else ( || vm. new_value_error ( "substring not found" . to_owned ( ) ) )
338339 }
339340
340341 #[ pymethod( name = "rfind" ) ]
341342 fn rfind ( & self , options : ByteInnerFindOptions , vm : & VirtualMachine ) -> PyResult < isize > {
342- let index = self . borrow_value ( ) . find ( options, true , vm) ?;
343+ let index = self . borrow_value ( ) . find ( options, |h , n| h . rfind ( n ) , vm) ?;
343344 Ok ( index. map_or ( -1 , |v| v as isize ) )
344345 }
345346
346347 #[ pymethod( name = "rindex" ) ]
347348 fn rindex ( & self , options : ByteInnerFindOptions , vm : & VirtualMachine ) -> PyResult < usize > {
348- let index = self . borrow_value ( ) . find ( options, true , vm) ?;
349+ let index = self . borrow_value ( ) . find ( options, |h , n| h . rfind ( n ) , vm) ?;
349350 index. ok_or_else ( || vm. new_value_error ( "substring not found" . to_owned ( ) ) )
350351 }
351352
0 commit comments