@@ -41,6 +41,7 @@ use unicode_casing::CharExt;
41
41
pub ( crate ) enum PyStrKind {
42
42
Ascii ,
43
43
Utf8 ,
44
+ U32 ,
44
45
}
45
46
46
47
impl std:: ops:: BitOr for PyStrKind {
@@ -58,6 +59,7 @@ impl PyStrKind {
58
59
match self {
59
60
PyStrKind :: Ascii => PyStrKindData :: Ascii ,
60
61
PyStrKind :: Utf8 => PyStrKindData :: Utf8 ( Radium :: new ( usize:: MAX ) ) ,
62
+ PyStrKind :: U32 => PyStrKindData :: U32 ,
61
63
}
62
64
}
63
65
}
@@ -67,13 +69,15 @@ enum PyStrKindData {
67
69
Ascii ,
68
70
// uses usize::MAX as a sentinel for "uncomputed"
69
71
Utf8 ( PyAtomic < usize > ) ,
72
+ U32 ,
70
73
}
71
74
72
75
impl PyStrKindData {
73
76
fn kind ( & self ) -> PyStrKind {
74
77
match self {
75
78
PyStrKindData :: Ascii => PyStrKind :: Ascii ,
76
79
PyStrKindData :: Utf8 ( _) => PyStrKind :: Utf8 ,
80
+ PyStrKindData :: U32 => PyStrKind :: U32 ,
77
81
}
78
82
}
79
83
}
@@ -383,13 +387,24 @@ impl PyStr {
383
387
}
384
388
}
385
389
390
+ #[ allow( dead_code) ]
391
+ fn as_u32_slice ( & self ) -> & [ u32 ] {
392
+ assert_eq ! ( self . kind. kind( ) , PyStrKind :: U32 ) ;
393
+ assert_eq ! ( self . bytes. len( ) % 4 , 0 ) ;
394
+ let ( prefix, reslice, suffix) = unsafe { self . bytes . align_to :: < u32 > ( ) } ;
395
+ assert_eq ! ( prefix. len( ) , 0 ) ;
396
+ assert_eq ! ( suffix. len( ) , 0 ) ;
397
+ reslice
398
+ }
399
+
386
400
fn char_all < F > ( & self , test : F ) -> bool
387
401
where
388
402
F : Fn ( char ) -> bool ,
389
403
{
390
404
match self . kind . kind ( ) {
391
405
PyStrKind :: Ascii => self . bytes . iter ( ) . all ( |& x| test ( char:: from ( x) ) ) ,
392
406
PyStrKind :: Utf8 => self . as_str ( ) . chars ( ) . all ( test) ,
407
+ PyStrKind :: U32 => unimplemented ! ( ) ,
393
408
}
394
409
}
395
410
}
@@ -488,6 +503,7 @@ impl PyStr {
488
503
usize:: MAX => self . _compute_char_len ( ) ,
489
504
len => len,
490
505
} ,
506
+ PyStrKindData :: U32 => self . bytes . len ( ) / 4 ,
491
507
}
492
508
}
493
509
#[ cold]
@@ -512,6 +528,7 @@ impl PyStr {
512
528
match self . kind {
513
529
PyStrKindData :: Ascii => true ,
514
530
PyStrKindData :: Utf8 ( _) => false ,
531
+ PyStrKindData :: U32 => false ,
515
532
}
516
533
}
517
534
@@ -558,6 +575,7 @@ impl PyStr {
558
575
match self . kind . kind ( ) {
559
576
PyStrKind :: Ascii => self . as_str ( ) . to_ascii_lowercase ( ) ,
560
577
PyStrKind :: Utf8 => self . as_str ( ) . to_lowercase ( ) ,
578
+ PyStrKind :: U32 => unimplemented ! ( ) ,
561
579
}
562
580
}
563
581
@@ -572,6 +590,7 @@ impl PyStr {
572
590
match self . kind . kind ( ) {
573
591
PyStrKind :: Ascii => self . as_str ( ) . to_ascii_uppercase ( ) ,
574
592
PyStrKind :: Utf8 => self . as_str ( ) . to_uppercase ( ) ,
593
+ PyStrKind :: U32 => unimplemented ! ( ) ,
575
594
}
576
595
}
577
596
@@ -624,6 +643,7 @@ impl PyStr {
624
643
|v, s, n, vm| v. splitn ( n, s) . map ( |s| vm. ctx . new_str ( s) . into ( ) ) . collect ( ) ,
625
644
|v, n, vm| v. py_split_whitespace ( n, |s| vm. ctx . new_str ( s) . into ( ) ) ,
626
645
) ,
646
+ PyStrKind :: U32 => unimplemented ! ( ) ,
627
647
} ?;
628
648
Ok ( elements)
629
649
}
@@ -907,6 +927,7 @@ impl PyStr {
907
927
PyStrKind :: Utf8 => self
908
928
. as_str ( )
909
929
. py_iscase ( char:: is_lowercase, char:: is_uppercase) ,
930
+ PyStrKind :: U32 => unimplemented ! ( ) ,
910
931
}
911
932
}
912
933
@@ -918,6 +939,7 @@ impl PyStr {
918
939
PyStrKind :: Utf8 => self
919
940
. as_str ( )
920
941
. py_iscase ( char:: is_uppercase, char:: is_lowercase) ,
942
+ PyStrKind :: U32 => unimplemented ! ( ) ,
921
943
}
922
944
}
923
945
0 commit comments