@@ -1054,31 +1054,121 @@ const MAX_STACK_ALLOCATION: usize = 16;
1054
1054
impl IntoStrV for Vec < GString > {
1055
1055
#[ inline]
1056
1056
fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1057
- let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( )
1058
- + self . iter ( ) . map ( |s| s. len ( ) + 1 ) . sum :: < usize > ( ) ;
1057
+ self . as_slice ( ) . run_with_strv ( f)
1058
+ }
1059
+ }
1060
+
1061
+ impl < ' a > IntoStrV for Vec < & ' a GString > {
1062
+ #[ inline]
1063
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1064
+ self . as_slice ( ) . run_with_strv ( f)
1065
+ }
1066
+ }
1067
+
1068
+ impl < ' a > IntoStrV for Vec < & ' a GStr > {
1069
+ #[ inline]
1070
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1071
+ self . as_slice ( ) . run_with_strv ( f)
1072
+ }
1073
+ }
1074
+
1075
+ impl < ' a > IntoStrV for Vec < & ' a str > {
1076
+ #[ inline]
1077
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1078
+ self . as_slice ( ) . run_with_strv ( f)
1079
+ }
1080
+ }
1081
+
1082
+ impl IntoStrV for Vec < String > {
1083
+ #[ inline]
1084
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1085
+ self . as_slice ( ) . run_with_strv ( f)
1086
+ }
1087
+ }
1088
+
1089
+ impl < ' a > IntoStrV for Vec < & ' a String > {
1090
+ #[ inline]
1091
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1092
+ self . as_slice ( ) . run_with_strv ( f)
1093
+ }
1094
+ }
1095
+
1096
+ impl IntoStrV for & [ GString ] {
1097
+ #[ inline]
1098
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1099
+ let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( ) ;
1059
1100
1060
1101
if required_len < MAX_STACK_ALLOCATION * mem:: size_of :: < * mut c_char > ( ) {
1061
1102
unsafe {
1062
1103
let mut s = mem:: MaybeUninit :: < [ * mut c_char ; MAX_STACK_ALLOCATION ] > :: uninit ( ) ;
1063
1104
let ptrs = s. as_mut_ptr ( ) as * mut * mut c_char ;
1064
- let mut strs = ptrs. add ( self . len ( ) + 1 ) as * mut c_char ;
1065
1105
1066
1106
for ( i, item) in self . iter ( ) . enumerate ( ) {
1067
- ptr:: copy_nonoverlapping ( item. as_ptr ( ) , strs, item. len ( ) + 1 ) ;
1068
- * ptrs. add ( i) = strs;
1069
- strs = strs. add ( item. len ( ) + 1 ) ;
1107
+ * ptrs. add ( i) = item. as_ptr ( ) as * mut _ ;
1108
+ }
1109
+ * ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1110
+
1111
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1112
+ }
1113
+ } else {
1114
+ let mut s = StrV :: with_capacity ( self . len ( ) ) ;
1115
+ s. extend_from_slice ( self ) ;
1116
+ s. run_with_strv ( f)
1117
+ }
1118
+ }
1119
+ }
1120
+
1121
+ impl < ' a > IntoStrV for & [ & ' a GString ] {
1122
+ #[ inline]
1123
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1124
+ let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( ) ;
1125
+
1126
+ if required_len < MAX_STACK_ALLOCATION * mem:: size_of :: < * mut c_char > ( ) {
1127
+ unsafe {
1128
+ let mut s = mem:: MaybeUninit :: < [ * mut c_char ; MAX_STACK_ALLOCATION ] > :: uninit ( ) ;
1129
+ let ptrs = s. as_mut_ptr ( ) as * mut * mut c_char ;
1130
+
1131
+ for ( i, item) in self . iter ( ) . enumerate ( ) {
1132
+ * ptrs. add ( i) = item. as_ptr ( ) as * mut _ ;
1070
1133
}
1071
1134
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1072
1135
1073
1136
f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1074
1137
}
1075
1138
} else {
1076
- StrV :: from ( self ) . run_with_strv ( f)
1139
+ let mut s = StrV :: with_capacity ( self . len ( ) ) ;
1140
+ s. extend_from_slice ( self ) ;
1141
+ s. run_with_strv ( f)
1077
1142
}
1078
1143
}
1079
1144
}
1080
1145
1081
- impl < ' a > IntoStrV for & ' a [ String ] {
1146
+ impl < ' a > IntoStrV for & [ & ' a GStr ] {
1147
+ #[ inline]
1148
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1149
+ let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( ) ;
1150
+
1151
+ if required_len < MAX_STACK_ALLOCATION * mem:: size_of :: < * mut c_char > ( ) {
1152
+ unsafe {
1153
+ let mut s = mem:: MaybeUninit :: < [ * mut c_char ; MAX_STACK_ALLOCATION ] > :: uninit ( ) ;
1154
+ let ptrs = s. as_mut_ptr ( ) as * mut * mut c_char ;
1155
+
1156
+ for ( i, item) in self . iter ( ) . enumerate ( ) {
1157
+ * ptrs. add ( i) = item. as_ptr ( ) as * mut _ ;
1158
+ }
1159
+ * ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1160
+
1161
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1162
+ }
1163
+ } else {
1164
+ let mut s = StrV :: with_capacity ( self . len ( ) ) ;
1165
+ s. extend_from_slice ( self ) ;
1166
+ s. run_with_strv ( f)
1167
+ }
1168
+ }
1169
+ }
1170
+
1171
+ impl < ' a > IntoStrV for & [ & ' a str ] {
1082
1172
#[ inline]
1083
1173
fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1084
1174
let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( )
@@ -1108,7 +1198,7 @@ impl<'a> IntoStrV for &'a [String] {
1108
1198
}
1109
1199
}
1110
1200
1111
- impl < ' a > IntoStrV for & ' a [ & ' a str ] {
1201
+ impl IntoStrV for & [ String ] {
1112
1202
#[ inline]
1113
1203
fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1114
1204
let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( )
@@ -1138,7 +1228,7 @@ impl<'a> IntoStrV for &'a [&'a str] {
1138
1228
}
1139
1229
}
1140
1230
1141
- impl < const N : usize > IntoStrV for [ GString ; N ] {
1231
+ impl < ' a > IntoStrV for & [ & ' a String ] {
1142
1232
#[ inline]
1143
1233
fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1144
1234
let required_len = ( self . len ( ) + 1 ) * mem:: size_of :: < * mut c_char > ( )
@@ -1151,7 +1241,8 @@ impl<const N: usize> IntoStrV for [GString; N] {
1151
1241
let mut strs = ptrs. add ( self . len ( ) + 1 ) as * mut c_char ;
1152
1242
1153
1243
for ( i, item) in self . iter ( ) . enumerate ( ) {
1154
- ptr:: copy_nonoverlapping ( item. as_ptr ( ) , strs, item. len ( ) + 1 ) ;
1244
+ ptr:: copy_nonoverlapping ( item. as_ptr ( ) as * const _ , strs, item. len ( ) ) ;
1245
+ * strs. add ( item. len ( ) ) = 0 ;
1155
1246
* ptrs. add ( i) = strs;
1156
1247
strs = strs. add ( item. len ( ) + 1 ) ;
1157
1248
}
@@ -1160,11 +1251,55 @@ impl<const N: usize> IntoStrV for [GString; N] {
1160
1251
f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1161
1252
}
1162
1253
} else {
1163
- StrV :: from ( self ) . run_with_strv ( f)
1254
+ let mut s = StrV :: with_capacity ( self . len ( ) ) ;
1255
+ s. extend_from_slice ( self ) ;
1256
+ s. run_with_strv ( f)
1164
1257
}
1165
1258
}
1166
1259
}
1167
1260
1261
+ impl < const N : usize > IntoStrV for [ GString ; N ] {
1262
+ #[ inline]
1263
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1264
+ self . as_slice ( ) . run_with_strv ( f)
1265
+ }
1266
+ }
1267
+
1268
+ impl < ' a , const N : usize > IntoStrV for [ & ' a GString ; N ] {
1269
+ #[ inline]
1270
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1271
+ self . as_slice ( ) . run_with_strv ( f)
1272
+ }
1273
+ }
1274
+
1275
+ impl < ' a , const N : usize > IntoStrV for [ & ' a GStr ; N ] {
1276
+ #[ inline]
1277
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1278
+ self . as_slice ( ) . run_with_strv ( f)
1279
+ }
1280
+ }
1281
+
1282
+ impl < ' a , const N : usize > IntoStrV for [ & ' a str ; N ] {
1283
+ #[ inline]
1284
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1285
+ self . as_slice ( ) . run_with_strv ( f)
1286
+ }
1287
+ }
1288
+
1289
+ impl < const N : usize > IntoStrV for [ String ; N ] {
1290
+ #[ inline]
1291
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1292
+ self . as_slice ( ) . run_with_strv ( f)
1293
+ }
1294
+ }
1295
+
1296
+ impl < ' a , const N : usize > IntoStrV for [ & ' a String ; N ] {
1297
+ #[ inline]
1298
+ fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1299
+ self . as_slice ( ) . run_with_strv ( f)
1300
+ }
1301
+ }
1302
+
1168
1303
#[ cfg( test) ]
1169
1304
mod test {
1170
1305
use super :: * ;
0 commit comments