File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 33//! Todo: verify this module!
44
55use core:: slice;
6+ use core:: str;
67
78/// Convert a buffer or a pointer into ones with uncached address.
89///
@@ -59,6 +60,32 @@ impl<T> Uncache for &mut [T] {
5960 }
6061}
6162
63+ impl Uncache for & str {
64+ #[ inline]
65+ fn uncache ( self ) -> Self {
66+ let addr = self . as_ptr ( ) as usize ;
67+ assert_addr_cached ( addr) ;
68+ let new_ptr = ( addr - 0x4000_0000 ) as * const u8 ;
69+ // note(unsafe): source address is safe; passing ownership
70+ let slice = unsafe { slice:: from_raw_parts ( new_ptr, self . len ( ) ) } ;
71+ // note(unsafe): source slice is guaranteed valid in UTF-8
72+ unsafe { str:: from_utf8_unchecked ( slice) }
73+ }
74+ }
75+
76+ impl Uncache for & mut str {
77+ #[ inline]
78+ fn uncache ( self ) -> Self {
79+ let addr = self . as_ptr ( ) as usize ;
80+ assert_addr_cached ( addr) ;
81+ let new_ptr = ( addr - 0x4000_0000 ) as * mut u8 ;
82+ // note(unsafe): source address is safe; passing ownership
83+ let slice = unsafe { slice:: from_raw_parts_mut ( new_ptr, self . len ( ) ) } ;
84+ // note(unsafe): source slice is guaranteed valid in UTF-8
85+ unsafe { str:: from_utf8_unchecked_mut ( slice) }
86+ }
87+ }
88+
6289impl < T > Uncache for * const T {
6390 #[ inline]
6491 fn uncache ( self ) -> Self {
You can’t perform that action at this time.
0 commit comments