Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glib: Optimize IntoGStr impl for String by simply appending a NUL-byte #1016

Merged
merged 1 commit into from Feb 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions glib/src/gstring.rs
Expand Up @@ -2317,12 +2317,10 @@ impl IntoGStr for &str {

impl IntoGStr for String {
#[inline]
fn run_with_gstr<T, F: FnOnce(&GStr) -> T>(self, f: F) -> T {
if self.len() < MAX_STACK_ALLOCATION {
self.as_str().run_with_gstr(f)
} else {
f(GString::from(self).as_gstr())
}
fn run_with_gstr<T, F: FnOnce(&GStr) -> T>(mut self, f: F) -> T {
self.push('\0');
let gs = unsafe { GStr::from_utf8_with_nul_unchecked(self.as_bytes()) };
f(gs)
}
}

Expand Down