@@ -96,19 +96,22 @@ fn try_raw_entries<const N: usize>(
96
96
let mut paths: [ Option < CString > ; N ] = unsafe {
97
97
std:: mem:: MaybeUninit :: uninit ( ) . assume_init ( )
98
98
} ;
99
- for ( idx , entry) in entries . iter ( ) . enumerate ( ) {
100
- paths [ idx ] = if let Some ( entry) = entry {
99
+ for ( path , entry) in paths . iter_mut ( ) . zip ( entries . iter ( ) ) {
100
+ let c_path = if let Some ( entry) = entry {
101
101
Some ( CString :: new ( & entry. path [ ..] ) ?)
102
102
} else {
103
103
None
104
- }
104
+ } ;
105
+
106
+ let path_ptr: * mut Option < CString > = path;
107
+ unsafe { path_ptr. write ( c_path) ; }
105
108
}
106
109
107
110
let mut raw_entries: [ Option < raw:: git_index_entry > ; N ] = unsafe {
108
111
std:: mem:: MaybeUninit :: uninit ( ) . assume_init ( )
109
112
} ;
110
- for ( idx , ( entry, path) ) in entries. iter ( ) . zip ( & paths) . enumerate ( ) {
111
- raw_entries [ idx ] = if let Some ( entry) = entry {
113
+ for ( raw_entry , ( entry, path) ) in raw_entries . iter_mut ( ) . zip ( entries. iter ( ) . zip ( & paths) ) {
114
+ let c_raw_entry = if let Some ( entry) = entry {
112
115
// libgit2 encodes the length of the path in the lower bits of the
113
116
// `flags` entry, so mask those out and recalculate here to ensure we
114
117
// don't corrupt anything.
@@ -120,38 +123,42 @@ fn try_raw_entries<const N: usize>(
120
123
flags |= raw:: GIT_INDEX_ENTRY_NAMEMASK ;
121
124
}
122
125
123
- unsafe {
124
- Some ( raw:: git_index_entry {
125
- dev : entry. dev ,
126
- ino : entry. ino ,
127
- mode : entry. mode ,
128
- uid : entry. uid ,
129
- gid : entry. gid ,
130
- file_size : entry. file_size ,
131
- id : * entry. id . raw ( ) ,
132
- flags,
133
- flags_extended : entry. flags_extended ,
134
- path : path. as_ref ( ) . unwrap ( ) . as_ptr ( ) ,
135
- mtime : raw:: git_index_time {
136
- seconds : entry. mtime . seconds ( ) ,
137
- nanoseconds : entry. mtime . nanoseconds ( ) ,
138
- } ,
139
- ctime : raw:: git_index_time {
140
- seconds : entry. ctime . seconds ( ) ,
141
- nanoseconds : entry. ctime . nanoseconds ( ) ,
142
- } ,
143
- } )
144
- }
126
+ Some ( raw:: git_index_entry {
127
+ dev : entry. dev ,
128
+ ino : entry. ino ,
129
+ mode : entry. mode ,
130
+ uid : entry. uid ,
131
+ gid : entry. gid ,
132
+ file_size : entry. file_size ,
133
+ id : unsafe { * entry. id . raw ( ) } ,
134
+ flags,
135
+ flags_extended : entry. flags_extended ,
136
+ path : path. as_ref ( ) . unwrap ( ) . as_ptr ( ) ,
137
+ mtime : raw:: git_index_time {
138
+ seconds : entry. mtime . seconds ( ) ,
139
+ nanoseconds : entry. mtime . nanoseconds ( ) ,
140
+ } ,
141
+ ctime : raw:: git_index_time {
142
+ seconds : entry. ctime . seconds ( ) ,
143
+ nanoseconds : entry. ctime . nanoseconds ( ) ,
144
+ } ,
145
+ } )
145
146
} else {
146
147
None
147
- }
148
+ } ;
149
+
150
+ let raw_entry_ptr: * mut Option < raw:: git_index_entry > = raw_entry;
151
+ unsafe { raw_entry_ptr. write ( c_raw_entry) ; }
148
152
}
149
153
150
154
let mut raw_entry_ptrs: [ * const raw:: git_index_entry ; N ] = unsafe {
151
155
std:: mem:: MaybeUninit :: uninit ( ) . assume_init ( )
152
156
} ;
153
- for ( idx, entry) in raw_entries. iter ( ) . enumerate ( ) {
154
- raw_entry_ptrs[ idx] = entry. as_ref ( ) . map_or_else ( std:: ptr:: null, |ptr| ptr) ;
157
+ for ( raw_entry_ptr, raw_entry) in raw_entry_ptrs. iter_mut ( ) . zip ( raw_entries. iter ( ) ) {
158
+ let c_raw_entry_ptr = raw_entry. as_ref ( ) . map_or_else ( std:: ptr:: null, |ptr| ptr) ;
159
+
160
+ let raw_entry_ptr_ptr: * mut * const raw:: git_index_entry = raw_entry_ptr;
161
+ unsafe { raw_entry_ptr_ptr. write ( c_raw_entry_ptr) ; }
155
162
}
156
163
157
164
cb ( & raw_entry_ptrs)
0 commit comments