@@ -14,26 +14,26 @@ pub struct HStringHeader {
14
14
}
15
15
16
16
impl HStringHeader {
17
- pub fn alloc ( len : u32 ) -> Result < * mut HStringHeader > {
17
+ pub fn alloc ( len : u32 ) -> Result < * mut Self > {
18
18
if len == 0 {
19
19
return Ok ( core:: ptr:: null_mut ( ) ) ;
20
20
}
21
21
22
22
// Allocate enough space for header and two bytes per character.
23
23
// The space for the terminating null character is already accounted for inside of `HStringHeader`.
24
- let bytes = core:: mem:: size_of :: < HStringHeader > ( ) + 2 * len as usize ;
24
+ let bytes = core:: mem:: size_of :: < Self > ( ) + 2 * len as usize ;
25
25
26
26
#[ cfg( windows) ]
27
- let header = unsafe { bindings :: HeapAlloc ( bindings :: GetProcessHeap ( ) , 0 , bytes ) }
28
- as * mut HStringHeader ;
27
+ let header =
28
+ unsafe { bindings :: HeapAlloc ( bindings :: GetProcessHeap ( ) , 0 , bytes ) } as * mut Self ;
29
29
30
30
#[ cfg( not( windows) ) ]
31
31
let header = unsafe {
32
32
extern "C" {
33
33
fn malloc ( bytes : usize ) -> * mut core:: ffi:: c_void ;
34
34
}
35
35
36
- malloc ( bytes) as * mut HStringHeader
36
+ malloc ( bytes) as * mut Self
37
37
} ;
38
38
39
39
if header. is_null ( ) {
@@ -42,7 +42,7 @@ impl HStringHeader {
42
42
43
43
unsafe {
44
44
// Use `ptr::write` (since `header` is unintialized). `HStringHeader` is safe to be all zeros.
45
- header. write ( core:: mem:: MaybeUninit :: < HStringHeader > :: zeroed ( ) . assume_init ( ) ) ;
45
+ header. write ( core:: mem:: MaybeUninit :: < Self > :: zeroed ( ) . assume_init ( ) ) ;
46
46
( * header) . len = len;
47
47
( * header) . count = RefCount :: new ( 1 ) ;
48
48
( * header) . data = & mut ( * header) . buffer_start ;
@@ -51,36 +51,32 @@ impl HStringHeader {
51
51
Ok ( header)
52
52
}
53
53
54
- pub unsafe fn free ( header : * mut HStringHeader ) {
54
+ pub unsafe fn free ( header : * mut Self ) {
55
55
if header. is_null ( ) {
56
56
return ;
57
57
}
58
58
59
- let header = header as * mut _ ;
60
-
61
59
#[ cfg( windows) ]
62
- {
63
- bindings:: HeapFree ( bindings:: GetProcessHeap ( ) , 0 , header) ;
64
- }
60
+ bindings:: HeapFree ( bindings:: GetProcessHeap ( ) , 0 , header as * mut _ ) ;
65
61
66
62
#[ cfg( not( windows) ) ]
67
63
{
68
64
extern "C" {
69
65
fn free ( ptr : * mut core:: ffi:: c_void ) ;
70
66
}
71
67
72
- free ( header) ;
68
+ free ( header as * mut _ ) ;
73
69
}
74
70
}
75
71
76
- pub fn duplicate ( & self ) -> Result < * mut HStringHeader > {
72
+ pub fn duplicate ( & self ) -> Result < * mut Self > {
77
73
if self . flags & HSTRING_REFERENCE_FLAG == 0 {
78
74
// If this is not a "fast pass" string then simply increment the reference count.
79
75
self . count . add_ref ( ) ;
80
- Ok ( self as * const HStringHeader as * mut HStringHeader )
76
+ Ok ( self as * const Self as * mut Self )
81
77
} else {
82
78
// Otherwise, allocate a new string and copy the value into the new string.
83
- let copy = HStringHeader :: alloc ( self . len ) ?;
79
+ let copy = Self :: alloc ( self . len ) ?;
84
80
// SAFETY: since we are duplicating the string it is safe to copy all data from self to the initialized `copy`.
85
81
// We copy `len + 1` characters since `len` does not account for the terminating null character.
86
82
unsafe {
0 commit comments