@@ -1067,7 +1067,7 @@ impl IntoStrV for StrV {
1067
1067
impl < ' a > IntoStrV for & ' a StrV {
1068
1068
#[ inline]
1069
1069
fn run_with_strv < R , F : FnOnce ( & [ * mut c_char ] ) -> R > ( self , f : F ) -> R {
1070
- f ( unsafe { std:: slice:: from_raw_parts ( self . as_ptr ( ) , self . len ( ) + 1 ) } )
1070
+ f ( unsafe { std:: slice:: from_raw_parts ( self . as_ptr ( ) , self . len ( ) ) } )
1071
1071
}
1072
1072
}
1073
1073
@@ -1134,7 +1134,7 @@ impl IntoStrV for &[GString] {
1134
1134
}
1135
1135
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1136
1136
1137
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1137
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1138
1138
}
1139
1139
} else {
1140
1140
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1159,7 +1159,7 @@ impl<'a> IntoStrV for &[&'a GString] {
1159
1159
}
1160
1160
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1161
1161
1162
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1162
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1163
1163
}
1164
1164
} else {
1165
1165
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1184,7 +1184,7 @@ impl<'a> IntoStrV for &[&'a GStr] {
1184
1184
}
1185
1185
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1186
1186
1187
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1187
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1188
1188
}
1189
1189
} else {
1190
1190
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1214,7 +1214,7 @@ impl<'a> IntoStrV for &[&'a str] {
1214
1214
}
1215
1215
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1216
1216
1217
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1217
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1218
1218
}
1219
1219
} else {
1220
1220
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1244,7 +1244,7 @@ impl IntoStrV for &[String] {
1244
1244
}
1245
1245
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1246
1246
1247
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1247
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1248
1248
}
1249
1249
} else {
1250
1250
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1274,7 +1274,7 @@ impl<'a> IntoStrV for &[&'a String] {
1274
1274
}
1275
1275
* ptrs. add ( self . len ( ) ) = ptr:: null_mut ( ) ;
1276
1276
1277
- f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) + 1 ) )
1277
+ f ( std:: slice:: from_raw_parts ( ptrs, self . len ( ) ) )
1278
1278
}
1279
1279
} else {
1280
1280
let mut s = StrV :: with_capacity ( self . len ( ) ) ;
@@ -1451,38 +1451,38 @@ mod test {
1451
1451
let items = [ "str1" , "str2" , "str3" , "str4" ] ;
1452
1452
1453
1453
items[ ..] . run_with_strv ( |s| unsafe {
1454
- assert ! ( s[ 4 ] . is_null( ) ) ;
1455
- assert_eq ! ( s. len( ) , items. len( ) + 1 ) ;
1454
+ assert ! ( s. get_unchecked ( 4 ) . is_null( ) ) ;
1455
+ assert_eq ! ( s. len( ) , items. len( ) ) ;
1456
1456
let s = StrV :: from_glib_borrow ( s. as_ptr ( ) as * const * const c_char ) ;
1457
1457
assert_eq ! ( s, items) ;
1458
1458
} ) ;
1459
1459
1460
1460
Vec :: from ( & items[ ..] ) . run_with_strv ( |s| unsafe {
1461
- assert ! ( s[ 4 ] . is_null( ) ) ;
1462
- assert_eq ! ( s. len( ) , items. len( ) + 1 ) ;
1461
+ assert ! ( s. get_unchecked ( 4 ) . is_null( ) ) ;
1462
+ assert_eq ! ( s. len( ) , items. len( ) ) ;
1463
1463
let s = StrV :: from_glib_borrow ( s. as_ptr ( ) as * const * const c_char ) ;
1464
1464
assert_eq ! ( s, items) ;
1465
1465
} ) ;
1466
1466
1467
1467
StrV :: from ( & items[ ..] ) . run_with_strv ( |s| unsafe {
1468
- assert ! ( s[ 4 ] . is_null( ) ) ;
1469
- assert_eq ! ( s. len( ) , items. len( ) + 1 ) ;
1468
+ assert ! ( s. get_unchecked ( 4 ) . is_null( ) ) ;
1469
+ assert_eq ! ( s. len( ) , items. len( ) ) ;
1470
1470
let s = StrV :: from_glib_borrow ( s. as_ptr ( ) as * const * const c_char ) ;
1471
1471
assert_eq ! ( s, items) ;
1472
1472
} ) ;
1473
1473
1474
1474
let v = items. iter ( ) . copied ( ) . map ( String :: from) . collect :: < Vec < _ > > ( ) ;
1475
1475
items. run_with_strv ( |s| unsafe {
1476
- assert ! ( s[ 4 ] . is_null( ) ) ;
1477
- assert_eq ! ( s. len( ) , v. len( ) + 1 ) ;
1476
+ assert ! ( s. get_unchecked ( 4 ) . is_null( ) ) ;
1477
+ assert_eq ! ( s. len( ) , v. len( ) ) ;
1478
1478
let s = StrV :: from_glib_borrow ( s. as_ptr ( ) as * const * const c_char ) ;
1479
1479
assert_eq ! ( s, items) ;
1480
1480
} ) ;
1481
1481
1482
1482
let v = items. iter ( ) . copied ( ) . map ( GString :: from) . collect :: < Vec < _ > > ( ) ;
1483
1483
items. run_with_strv ( |s| unsafe {
1484
- assert ! ( s[ 4 ] . is_null( ) ) ;
1485
- assert_eq ! ( s. len( ) , v. len( ) + 1 ) ;
1484
+ assert ! ( s. get_unchecked ( 4 ) . is_null( ) ) ;
1485
+ assert_eq ! ( s. len( ) , v. len( ) ) ;
1486
1486
let s = StrV :: from_glib_borrow ( s. as_ptr ( ) as * const * const c_char ) ;
1487
1487
assert_eq ! ( s, items) ;
1488
1488
} ) ;
0 commit comments