Skip to content

Commit f65029b

Browse files
committed
glib: Don't create a temporary copy of &GStr for ToGlibPtr::to_glib_none()
That completely defeats the purpose of `GStr` as it is already NUL-terminated. `to_glib_none()` can be for free for `GStr`.
1 parent d373a78 commit f65029b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

glib/src/gstring.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,11 @@ impl crate::value::ToValueOptional for GStr {
341341

342342
#[doc(hidden)]
343343
impl<'a> ToGlibPtr<'a, *const c_char> for GStr {
344-
type Storage = GString;
344+
type Storage = PhantomData<&'a Self>;
345345

346346
#[inline]
347347
fn to_glib_none(&'a self) -> Stash<'a, *const c_char, Self> {
348-
let tmp = self.to_owned();
349-
Stash(self.as_ptr(), tmp)
348+
Stash(self.as_ptr(), PhantomData)
350349
}
351350

352351
#[inline]
@@ -357,12 +356,11 @@ impl<'a> ToGlibPtr<'a, *const c_char> for GStr {
357356

358357
#[doc(hidden)]
359358
impl<'a> ToGlibPtr<'a, *mut c_char> for GStr {
360-
type Storage = GString;
359+
type Storage = PhantomData<&'a Self>;
361360

362361
#[inline]
363362
fn to_glib_none(&'a self) -> Stash<'a, *mut c_char, Self> {
364-
let tmp = self.to_owned();
365-
Stash(tmp.as_ptr() as *mut c_char, tmp)
363+
Stash(self.as_ptr() as *mut c_char, PhantomData)
366364
}
367365

368366
#[inline]

0 commit comments

Comments
 (0)