@@ -91,7 +91,7 @@ pub trait CodeUnitWidth: std::fmt::Debug + 'static {
91
91
type PCRE2_CHAR : Default + Copy + TryInto < Self :: SubjectChar > ;
92
92
type PCRE2_SPTR ;
93
93
type name_table_entry : NameTableEntry ;
94
- type SubjectChar : Copy ;
94
+ type SubjectChar : Copy + Default ;
95
95
type Pattern : Clone + std:: fmt:: Debug ;
96
96
97
97
fn escape_subject ( subject : & [ Self :: SubjectChar ] ) -> String ;
@@ -973,7 +973,7 @@ impl<W: CodeUnitWidth> MatchData<W> {
973
973
pub ( crate ) unsafe fn find (
974
974
& mut self ,
975
975
code : & Code < W > ,
976
- mut subject : & [ W :: SubjectChar ] ,
976
+ subject : & [ W :: SubjectChar ] ,
977
977
start : usize ,
978
978
options : u32 ,
979
979
) -> Result < bool , Error > {
@@ -996,17 +996,18 @@ impl<W: CodeUnitWidth> MatchData<W> {
996
996
// explode if you try to dereference it.
997
997
//
998
998
// [1]: https://github.com/BurntSushi/rust-pcre2/issues/42
999
- static SINGLETON : & [ u8 ] = & [ 0 ] ;
1000
- let len = subject. len ( ) ;
1001
- if subject. is_empty ( ) {
1002
- subject = SINGLETON ;
1003
- }
1004
- let ( subj_ptr, subj_len) = W :: subject_to_sptr_len ( subject) ;
999
+ let singleton: W :: SubjectChar = Default :: default ( ) ;
1000
+ let ( subj_ptr, subj_len) = if subject. is_empty ( ) {
1001
+ let ptr = W :: subject_to_sptr_len ( slice:: from_ref ( & singleton) ) . 0 ;
1002
+ ( ptr, 0 )
1003
+ } else {
1004
+ W :: subject_to_sptr_len ( subject)
1005
+ } ;
1005
1006
1006
1007
let rc = W :: pcre2_match (
1007
1008
code. as_ptr ( ) ,
1008
- subject . as_ptr ( ) ,
1009
- len ,
1009
+ subj_ptr ,
1010
+ subj_len ,
1010
1011
start,
1011
1012
options,
1012
1013
self . match_data ,
0 commit comments