@@ -40,6 +40,7 @@ use unicode_casing::CharExt;
40
40
pub ( crate ) enum PyStrKind {
41
41
Ascii ,
42
42
Utf8 ,
43
+ U32 ,
43
44
}
44
45
45
46
impl std:: ops:: BitOr for PyStrKind {
@@ -57,6 +58,7 @@ impl PyStrKind {
57
58
match self {
58
59
PyStrKind :: Ascii => PyStrKindData :: Ascii ,
59
60
PyStrKind :: Utf8 => PyStrKindData :: Utf8 ( Radium :: new ( usize:: MAX ) ) ,
61
+ PyStrKind :: U32 => PyStrKindData :: U32 ,
60
62
}
61
63
}
62
64
}
@@ -66,13 +68,15 @@ enum PyStrKindData {
66
68
Ascii ,
67
69
// uses usize::MAX as a sentinel for "uncomputed"
68
70
Utf8 ( PyAtomic < usize > ) ,
71
+ U32 ,
69
72
}
70
73
71
74
impl PyStrKindData {
72
75
fn kind ( & self ) -> PyStrKind {
73
76
match self {
74
77
PyStrKindData :: Ascii => PyStrKind :: Ascii ,
75
78
PyStrKindData :: Utf8 ( _) => PyStrKind :: Utf8 ,
79
+ PyStrKindData :: U32 => PyStrKind :: U32 ,
76
80
}
77
81
}
78
82
}
@@ -361,13 +365,24 @@ impl PyStr {
361
365
}
362
366
}
363
367
368
+ #[ allow( dead_code) ]
369
+ fn as_u32_slice ( & self ) -> & [ u32 ] {
370
+ assert_eq ! ( self . kind. kind( ) , PyStrKind :: U32 ) ;
371
+ assert_eq ! ( self . bytes. len( ) % 4 , 0 ) ;
372
+ let ( prefix, reslice, suffix) = unsafe { self . bytes . as_slice ( ) . align_to :: < u32 > ( ) } ;
373
+ assert_eq ! ( prefix. len( ) , 0 ) ;
374
+ assert_eq ! ( suffix. len( ) , 0 ) ;
375
+ reslice
376
+ }
377
+
364
378
fn char_all < F > ( & self , test : F ) -> bool
365
379
where
366
380
F : Fn ( char ) -> bool ,
367
381
{
368
382
match self . kind . kind ( ) {
369
383
PyStrKind :: Ascii => self . bytes . iter ( ) . all ( |& x| test ( char:: from ( x) ) ) ,
370
384
PyStrKind :: Utf8 => self . as_str ( ) . chars ( ) . all ( test) ,
385
+ PyStrKind :: U32 => unimplemented ! ( ) ,
371
386
}
372
387
}
373
388
}
@@ -466,6 +481,7 @@ impl PyStr {
466
481
usize:: MAX => self . _compute_char_len ( ) ,
467
482
len => len,
468
483
} ,
484
+ PyStrKindData :: U32 => self . bytes . len ( ) / 4 ,
469
485
}
470
486
}
471
487
#[ cold]
@@ -490,6 +506,7 @@ impl PyStr {
490
506
match self . kind {
491
507
PyStrKindData :: Ascii => true ,
492
508
PyStrKindData :: Utf8 ( _) => false ,
509
+ PyStrKindData :: U32 => false ,
493
510
}
494
511
}
495
512
@@ -531,6 +548,7 @@ impl PyStr {
531
548
match self . kind . kind ( ) {
532
549
PyStrKind :: Ascii => self . as_str ( ) . to_ascii_lowercase ( ) ,
533
550
PyStrKind :: Utf8 => self . as_str ( ) . to_lowercase ( ) ,
551
+ PyStrKind :: U32 => unimplemented ! ( ) ,
534
552
}
535
553
}
536
554
@@ -545,6 +563,7 @@ impl PyStr {
545
563
match self . kind . kind ( ) {
546
564
PyStrKind :: Ascii => self . as_str ( ) . to_ascii_uppercase ( ) ,
547
565
PyStrKind :: Utf8 => self . as_str ( ) . to_uppercase ( ) ,
566
+ PyStrKind :: U32 => unimplemented ! ( ) ,
548
567
}
549
568
}
550
569
@@ -597,6 +616,7 @@ impl PyStr {
597
616
|v, s, n, vm| v. splitn ( n, s) . map ( |s| vm. ctx . new_str ( s) . into ( ) ) . collect ( ) ,
598
617
|v, n, vm| v. py_split_whitespace ( n, |s| vm. ctx . new_str ( s) . into ( ) ) ,
599
618
) ,
619
+ PyStrKind :: U32 => unimplemented ! ( ) ,
600
620
} ?;
601
621
Ok ( elements)
602
622
}
@@ -880,6 +900,7 @@ impl PyStr {
880
900
PyStrKind :: Utf8 => self
881
901
. as_str ( )
882
902
. py_iscase ( char:: is_lowercase, char:: is_uppercase) ,
903
+ PyStrKind :: U32 => unimplemented ! ( ) ,
883
904
}
884
905
}
885
906
@@ -891,6 +912,7 @@ impl PyStr {
891
912
PyStrKind :: Utf8 => self
892
913
. as_str ( )
893
914
. py_iscase ( char:: is_uppercase, char:: is_lowercase) ,
915
+ PyStrKind :: U32 => unimplemented ! ( ) ,
894
916
}
895
917
}
896
918
0 commit comments